Skip to content

feat: Added drift tests using DB storage#400

Merged
sheltoncyril merged 2 commits intoopendatahub-io:mainfrom
kpunwatk:drift_DB
Jul 1, 2025
Merged

feat: Added drift tests using DB storage#400
sheltoncyril merged 2 commits intoopendatahub-io:mainfrom
kpunwatk:drift_DB

Conversation

@kpunwatk
Copy link
Copy Markdown
Contributor

@kpunwatk kpunwatk commented Jul 1, 2025

  1. This PR introduces tests for drift metrics including MeanShift, KSTest, ApproxKSTest, and FourierMMD using DB storage for the TrustyAIService.

  2. The test class description in the Fairness test case has been updated to include the missing "dir" metric.

Description

How Has This Been Tested?

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

@kpunwatk kpunwatk requested a review from a team as a code owner July 1, 2025 13:16
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 1, 2025

📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Added new tests for drift metrics using database storage, covering the full lifecycle for multiple drift metrics.
    • Enhanced test documentation for fairness metrics to reflect coverage of both "spd" and "dir" metrics.

Summary by CodeRabbit

  • Tests
    • Added new tests to verify drift metric operations with database storage, covering the full lifecycle for multiple drift metrics.
    • Enhanced test documentation to clarify that fairness metric tests now include both "spd" and "dir" metrics.

Walkthrough

A new test class, TestDriftMetricsWithDBStorage, was introduced to test TrustyAI drift metric operations using MariaDB storage. The class mirrors existing drift metric tests but targets database-backed storage. Additionally, a docstring update in the fairness metric tests clarifies coverage of both "spd" and "dir" metrics.

Changes

File(s) Change Summary
tests/model_explainability/trustyai_service/drift/test_drift.py Added TestDriftMetricsWithDBStorage class with multiple test methods for drift metrics using DB storage.
tests/model_explainability/trustyai_service/fairness/test_fairness.py Updated docstrings in TestFairnessMetricsWithPVCStorage and TestFairnessMetricsWithDBStorage to mention both "spd" and "dir" metrics.

Possibly related PRs

Suggested labels

Verified

Suggested reviewers

  • kpunwatk
  • mwaykole
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 1, 2025

The following are automatically added/executed:

  • PR size label.
  • Run pre-commit
  • Run tox
  • Add PR author as the PR assignee
  • Build image based on the PR

Available user actions:

  • To mark a PR as WIP, add /wip in a comment. To remove it from the PR comment /wip cancel to the PR.
  • To block merging of a PR, add /hold in a comment. To un-block merging of PR comment /hold cancel.
  • To mark a PR as approved, add /lgtm in a comment. To remove, add /lgtm cancel.
    lgtm label removed on each new commit push.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
  • To Cherry-pick a merged PR /cherry-pick <target_branch_name> to the PR. If <target_branch_name> is valid,
    and the current PR is merged, a cherry-picked PR would be created and linked to the current PR.
  • To build and push image to quay, add /build-push-pr-image in a comment. This would create an image with tag
    pr-<pr_number> to quay repository. This image tag, however would be deleted on PR merge or close action.
Supported labels

{'/cherry-pick', '/lgtm', '/wip', '/hold', '/verified', '/build-push-pr-image'}

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/model_explainability/trustyai_service/drift/test_drift.py (1)

156-178: LGTM! Well-structured test class for DB storage.

The new test class properly mirrors the existing PVC storage tests with appropriate fixture usage and comprehensive metric coverage.

Minor note: The docstring mentions "Apply name mappings" in step 2, but unlike the fairness tests, there's no explicit name mapping test method in this class.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e86bc4c and c6365eb.

📒 Files selected for processing (2)
  • tests/model_explainability/trustyai_service/drift/test_drift.py (1 hunks)
  • tests/model_explainability/trustyai_service/fairness/test_fairness.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
tests/model_explainability/trustyai_service/fairness/test_fairness.py (1)
Learnt from: adolfo-ab
PR: opendatahub-io/opendatahub-tests#334
File: tests/model_explainability/trustyai_service/test_trustyai_service.py:52-65
Timestamp: 2025-06-05T10:05:17.642Z
Learning: For TrustyAI image validation tests: operator image tests require admin_client, related_images_refs, and trustyai_operator_configmap fixtures, while service image tests would require different fixtures like trustyai_service_with_pvc_storage, model_namespace, and current_client_token.
tests/model_explainability/trustyai_service/drift/test_drift.py (1)
Learnt from: adolfo-ab
PR: opendatahub-io/opendatahub-tests#334
File: tests/model_explainability/trustyai_service/test_trustyai_service.py:52-65
Timestamp: 2025-06-05T10:05:17.642Z
Learning: For TrustyAI image validation tests: operator image tests require admin_client, related_images_refs, and trustyai_operator_configmap fixtures, while service image tests would require different fixtures like trustyai_service_with_pvc_storage, model_namespace, and current_client_token.
🪛 Pylint (3.3.7)
tests/model_explainability/trustyai_service/drift/test_drift.py

[refactor] 180-180: Too many arguments (7/5)

(R0913)


[refactor] 180-180: Too many positional arguments (7/5)

(R0917)


[refactor] 214-214: Too many arguments (6/5)

(R0913)


[refactor] 214-214: Too many positional arguments (6/5)

(R0917)


[refactor] 234-234: Too many arguments (6/5)

(R0913)


[refactor] 234-234: Too many positional arguments (6/5)

(R0917)


[refactor] 254-254: Too many arguments (7/5)

(R0913)


[refactor] 254-254: Too many positional arguments (7/5)

(R0917)


[refactor] 271-271: Too many arguments (6/5)

(R0913)


[refactor] 271-271: Too many positional arguments (6/5)

(R0917)

🔇 Additional comments (2)
tests/model_explainability/trustyai_service/fairness/test_fairness.py (1)

168-172: LGTM! Documentation accurately reflects test coverage.

The docstring updates correctly describe that the tests cover both "spd and dir" fairness metrics, which aligns with the FAIRNESS_METRICS list and parametrized test methods.

tests/model_explainability/trustyai_service/drift/test_drift.py (1)

180-284: Comprehensive test coverage with consistent patterns.

All test methods follow established conventions:

  • Proper _with_db_storage naming suffix
  • Correct fixture usage (trustyai_service_with_db_storage)
  • Complete parametrization across all drift metrics
  • Consistent test flow and data handling

The static analysis warnings about "too many arguments" are false positives - pytest test methods commonly use many fixtures.

@kpunwatk kpunwatk changed the title faet: drift test case faet: Added drift tests using DB storage Jul 1, 2025
@kpunwatk
Copy link
Copy Markdown
Contributor Author

kpunwatk commented Jul 1, 2025

/verified

@kpunwatk kpunwatk changed the title faet: Added drift tests using DB storage feat: Added drift tests using DB storage Jul 1, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
tests/model_explainability/trustyai_service/drift/test_drift.py (2)

168-178: Consider the docstring accuracy and missing test coverage.

The docstring mentions "Apply name mappings" as step 2, but there's no dedicated test method for name mapping functionality in this class. Either add the missing test or update the docstring to accurately reflect the actual test coverage.

 """
 Verifies all the basic operations with a drift metric (meanshift, kstest, approxkstest and fouriermmd)
  available in TrustyAI, using MariaDB storage.

 1. Send data to the model and verify that TrustyAI registers the observations.
-2. Apply name mappings
-3. Send metric request (meanshift, kstest, approxkstest and fouriermmd) and verify the response.
-4. Send metric scheduling request and verify the response.
-5. Send metric deletion request and verify that the scheduled metric has been deleted.
+2. Upload training data to TrustyAI service.
+3. Send metric request (meanshift, kstest, approxkstest and fouriermmd) and verify the response.
+4. Send metric scheduling request and verify the response.
+5. Validate Prometheus metrics are exposed correctly.
+6. Send metric deletion request and verify that the scheduled metric has been deleted.
 """

156-285: Consider reducing code duplication with a parameterized approach.

The new TestDriftMetricsWithDBStorage class duplicates the entire test logic from TestDriftMetrics, differing only in the storage fixture used. This creates maintenance overhead as changes need to be applied to both classes.

Consider consolidating both classes into a single parameterized test class:

+@pytest.mark.parametrize("storage_type", ["pvc", "db"])
 @pytest.mark.parametrize(
     "model_namespace, minio_pod, minio_data_connection",
     [
         pytest.param(
             {"name": "test-drift"},
             MinIo.PodConfig.MODEL_MESH_MINIO_CONFIG,
             {"bucket": MinIo.Buckets.MODELMESH_EXAMPLE_MODELS},
         )
     ],
     indirect=True,
 )
 @pytest.mark.usefixtures("minio_pod")
 @pytest.mark.smoke
-class TestDriftMetrics:
+class TestDriftMetrics:
     """
-    Verifies all the basic operations with a drift metric (meanshift) available in TrustyAI, using PVC storage.
+    Verifies all the basic operations with drift metrics available in TrustyAI, using PVC or DB storage.
     """
     
+    @pytest.fixture
+    def trustyai_service(self, storage_type, trustyai_service_with_pvc_storage, trustyai_service_with_db_storage):
+        return trustyai_service_with_pvc_storage if storage_type == "pvc" else trustyai_service_with_db_storage
+    
     def test_drift_send_inference_and_verify_trustyai_service(
         self,
         admin_client,
         current_client_token,
         model_namespace,
-        trustyai_service_with_pvc_storage,
+        trustyai_service,
         gaussian_credit_model,
         isvc_getter_token,
     ) -> None:

This approach would eliminate duplication while maintaining the same test coverage.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c6365eb and 5c9e9e1.

📒 Files selected for processing (2)
  • tests/model_explainability/trustyai_service/drift/test_drift.py (1 hunks)
  • tests/model_explainability/trustyai_service/fairness/test_fairness.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/model_explainability/trustyai_service/fairness/test_fairness.py
🧰 Additional context used
🧠 Learnings (1)
tests/model_explainability/trustyai_service/drift/test_drift.py (1)
Learnt from: adolfo-ab
PR: opendatahub-io/opendatahub-tests#334
File: tests/model_explainability/trustyai_service/test_trustyai_service.py:52-65
Timestamp: 2025-06-05T10:05:17.642Z
Learning: For TrustyAI image validation tests: operator image tests require admin_client, related_images_refs, and trustyai_operator_configmap fixtures, while service image tests would require different fixtures like trustyai_service_with_pvc_storage, model_namespace, and current_client_token.
🪛 Pylint (3.3.7)
tests/model_explainability/trustyai_service/drift/test_drift.py

[refactor] 180-180: Too many arguments (7/5)

(R0913)


[refactor] 180-180: Too many positional arguments (7/5)

(R0917)


[refactor] 214-214: Too many arguments (6/5)

(R0913)


[refactor] 214-214: Too many positional arguments (6/5)

(R0917)


[refactor] 234-234: Too many arguments (6/5)

(R0913)


[refactor] 234-234: Too many positional arguments (6/5)

(R0917)


[refactor] 254-254: Too many arguments (7/5)

(R0913)


[refactor] 254-254: Too many positional arguments (7/5)

(R0917)


[refactor] 271-271: Too many arguments (6/5)

(R0913)


[refactor] 271-271: Too many positional arguments (6/5)

(R0917)

🔇 Additional comments (1)
tests/model_explainability/trustyai_service/drift/test_drift.py (1)

180-188: Test method structure follows established patterns.

The test method correctly uses the database storage fixture and maintains the same parameter structure as the PVC storage equivalent. The implementation properly delegates to the shared utility function.

Copy link
Copy Markdown
Contributor

@sheltoncyril sheltoncyril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

kpunwatk and others added 2 commits July 1, 2025 16:40
	modified:   tests/model_explainability/trustyai_service/drift/test_drift.py
	modified:   tests/model_explainability/trustyai_service/fairness/test_fairness.py

	modified:   tests/model_explainability/trustyai_service/drift/test_drift.py
	modified:   tests/model_explainability/trustyai_service/fairness/test_fairness.py
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
tests/model_explainability/trustyai_service/drift/test_drift.py (2)

168-168: Add smoke test marker for consistency.

The original TestDriftMetrics class includes @pytest.mark.smoke but this new DB storage test class doesn't. Consider adding it for consistency in test categorization.

 @pytest.mark.usefixtures("minio_pod")
+@pytest.mark.smoke
 class TestDriftMetricsWithDBStorage:

169-178: Update docstring to accurately reflect test coverage.

The docstring mentions "Apply name mappings" as step 2, but there's no specific test method for name mappings in this class. Consider removing this step or adding the corresponding test method.

     """
     Verifies all the basic operations with a drift metric (meanshift, kstest, approxkstest and fouriermmd)
-     available in TrustyAI, using MariaDB storage.
+    available in TrustyAI, using MariaDB storage.
 
     1. Send data to the model and verify that TrustyAI registers the observations.
-    2. Apply name mappings
-    3. Send metric request (meanshift, kstest, approxkstest and fouriermmd) and verify the response.
-    4. Send metric scheduling request and verify the response.
-    5. Send metric deletion request and verify that the scheduled metric has been deleted.
+    2. Send metric request (meanshift, kstest, approxkstest and fouriermmd) and verify the response.
+    3. Send metric scheduling request and verify the response.
+    4. Send metric deletion request and verify that the scheduled metric has been deleted.
     """
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5c9e9e1 and 89ec574.

📒 Files selected for processing (2)
  • tests/model_explainability/trustyai_service/drift/test_drift.py (1 hunks)
  • tests/model_explainability/trustyai_service/fairness/test_fairness.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/model_explainability/trustyai_service/fairness/test_fairness.py
🧰 Additional context used
🧠 Learnings (1)
tests/model_explainability/trustyai_service/drift/test_drift.py (1)
Learnt from: adolfo-ab
PR: opendatahub-io/opendatahub-tests#334
File: tests/model_explainability/trustyai_service/test_trustyai_service.py:52-65
Timestamp: 2025-06-05T10:05:17.642Z
Learning: For TrustyAI image validation tests: operator image tests require admin_client, related_images_refs, and trustyai_operator_configmap fixtures, while service image tests would require different fixtures like trustyai_service_with_pvc_storage, model_namespace, and current_client_token.
🧬 Code Graph Analysis (1)
tests/model_explainability/trustyai_service/drift/test_drift.py (5)
utilities/constants.py (3)
  • MinIo (242-290)
  • PodConfig (258-286)
  • Buckets (254-256)
tests/conftest.py (5)
  • admin_client (55-56)
  • current_client_token (71-72)
  • model_namespace (87-107)
  • minio_data_connection (478-490)
  • prometheus (523-531)
tests/model_explainability/trustyai_service/conftest.py (3)
  • trustyai_service_with_db_storage (97-111)
  • gaussian_credit_model (286-324)
  • isvc_getter_token (371-372)
tests/model_explainability/trustyai_service/trustyai_service_utils.py (5)
  • send_inferences_and_verify_trustyai_service_registered (272-336)
  • verify_upload_data_to_trustyai_service (519-551)
  • verify_trustyai_service_metric_request (434-462)
  • verify_trustyai_service_metric_scheduling_request (465-516)
  • verify_trustyai_service_metric_delete_request (554-595)
utilities/monitoring.py (2)
  • validate_metrics_field (53-88)
  • get_metric_label (27-50)
🪛 Pylint (3.3.7)
tests/model_explainability/trustyai_service/drift/test_drift.py

[refactor] 180-180: Too many arguments (7/5)

(R0913)


[refactor] 180-180: Too many positional arguments (7/5)

(R0917)


[refactor] 214-214: Too many arguments (6/5)

(R0913)


[refactor] 214-214: Too many positional arguments (6/5)

(R0917)


[refactor] 234-234: Too many arguments (6/5)

(R0913)


[refactor] 234-234: Too many positional arguments (6/5)

(R0917)


[refactor] 254-254: Too many arguments (7/5)

(R0913)


[refactor] 254-254: Too many positional arguments (7/5)

(R0917)


[refactor] 271-271: Too many arguments (6/5)

(R0913)


[refactor] 271-271: Too many positional arguments (6/5)

(R0917)

🔇 Additional comments (1)
tests/model_explainability/trustyai_service/drift/test_drift.py (1)

156-284: Excellent implementation of DB storage drift tests.

The new test class properly mirrors the existing PVC storage tests while using the appropriate trustyai_service_with_db_storage fixture. The comprehensive coverage of all drift metrics (meanshift, kstest, approxkstest, fouriermmd) and their lifecycle operations (request, schedule, prometheus validation, delete) ensures thorough testing of the database storage backend.

The code structure follows established patterns and correctly utilizes the existing utility functions. The method naming with _with_db_storage suffix provides clear differentiation from the PVC storage tests.

Note: The pylint warnings about too many arguments are false positives - this is expected and acceptable for pytest test methods that require multiple fixtures.

@sheltoncyril sheltoncyril merged commit 0856638 into opendatahub-io:main Jul 1, 2025
9 of 10 checks passed
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 1, 2025

Status of building tag latest: success.
Status of pushing tag latest to image registry: success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants