Skip to content

feat: add TrustyAIService Prometheus integration tests#301

Merged
adolfo-ab merged 2 commits intoopendatahub-io:mainfrom
adolfo-ab:trusty-prometheus
May 12, 2025
Merged

feat: add TrustyAIService Prometheus integration tests#301
adolfo-ab merged 2 commits intoopendatahub-io:mainfrom
adolfo-ab:trusty-prometheus

Conversation

@adolfo-ab
Copy link
Copy Markdown
Contributor

@adolfo-ab adolfo-ab commented May 9, 2025

Add tests to check the integration between TrustyAIService and Prometheus, for both drift and fairness metrics.

How Has This Been Tested?

Running the tests against a working cluster.

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

Summary by CodeRabbit

  • Tests
    • Added new tests to validate Prometheus metrics for drift and fairness in model explainability services.
    • Updated metric validation in model serving tests to use a more flexible validation approach.
    • Removed a redundant Prometheus fixture from model server tests.
    • Introduced a new Prometheus fixture for monitoring in test configurations.
  • Refactor
    • Improved metric validation utilities by splitting functionality into modular functions for greater flexibility and clearer logging.

@adolfo-ab adolfo-ab requested a review from a team as a code owner May 9, 2025 14:13
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 9, 2025

Walkthrough

The changes introduce new Prometheus metric validation tests for drift and fairness metrics, refactor metric validation utilities for greater flexibility, and consolidate Prometheus fixture usage. The metric validation logic now allows checking both metric values and labels. Related imports and fixtures are updated or removed to match the refactored utilities and test structure.

Changes

File(s) Change Summary
tests/conftest.py Added a session-scoped prometheus pytest fixture that initializes and returns a Prometheus instance with SSL verification.
tests/model_explainability/trustyai_service/drift/test_drift.py Added test_drift_metric_prometheus to validate a Prometheus metric label for drift meanshift metrics.
tests/model_explainability/trustyai_service/fairness/test_fairness.py Added test_fairness_metric_prometheus to validate a Prometheus metric label for fairness SPD metrics.
tests/model_serving/model_server/conftest.py Removed the prometheus fixture and related imports.
tests/model_serving/model_server/metrics/test_model_metrics.py
tests/model_serving/model_server/metrics/test_non_admin_users.py
Updated imports and replaced validate_metrics_value calls with validate_metrics_field in metric validation tests.
utilities/monitoring.py Refactored metric validation: removed validate_metrics_value, added get_metrics_value, get_metric_label, and validate_metrics_field.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Method
    participant Prom as Prometheus Instance
    participant Utils as Monitoring Utilities

    Test->>Prom: Query metric with metric_query
    Prom-->>Test: Metric results
    Test->>Utils: Extract field/label (get_metrics_value/get_metric_label)
    Utils-->>Test: Field/label value
    Test->>Utils: Validate value with validate_metrics_field (with timeout)
    Utils-->>Test: Assertion success or TimeoutExpiredError
Loading

Poem

In the warren of code, new tests do appear,
Prometheus metrics checked with cheer!
Labels and values, now easy to see,
Thanks to refactored utilities—
The fixtures are trimmed, the functions are neat,
With every hop, our coverage is sweet! 🐇✨

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b617c6 and d291201.

📒 Files selected for processing (7)
  • tests/conftest.py (3 hunks)
  • tests/model_explainability/trustyai_service/drift/test_drift.py (3 hunks)
  • tests/model_explainability/trustyai_service/fairness/test_fairness.py (3 hunks)
  • tests/model_serving/model_server/conftest.py (0 hunks)
  • tests/model_serving/model_server/metrics/test_model_metrics.py (3 hunks)
  • tests/model_serving/model_server/metrics/test_non_admin_users.py (2 hunks)
  • utilities/monitoring.py (2 hunks)
💤 Files with no reviewable changes (1)
  • tests/model_serving/model_server/conftest.py
🚧 Files skipped from review as they are similar to previous changes (6)
  • tests/model_serving/model_server/metrics/test_non_admin_users.py
  • tests/model_serving/model_server/metrics/test_model_metrics.py
  • tests/model_explainability/trustyai_service/fairness/test_fairness.py
  • tests/model_explainability/trustyai_service/drift/test_drift.py
  • tests/conftest.py
  • utilities/monitoring.py
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@adolfo-ab
Copy link
Copy Markdown
Contributor Author

/verified

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 9, 2025

The following are automatically added/executed:

  • PR size label.
  • Run pre-commit
  • Run tox
  • Add PR author as the PR assignee

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.
Supported labels

{'/verified', '/wip', '/hold', '/lgtm'}

@github-actions github-actions bot added the size/l label May 9, 2025
@rhods-ci-bot rhods-ci-bot added the Verified Verified pr in Jenkins label May 9, 2025
lugi0
lugi0 previously approved these changes May 9, 2025
Copy link
Copy Markdown
Contributor

@lugi0 lugi0 left a comment

Choose a reason for hiding this comment

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

couple questions but looks good overall

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/conftest.py (1)

526-533: Good centralization of the Prometheus fixture.

Creating a session-scoped Prometheus fixture in the global conftest file makes it available to all tests, promoting reuse and consistency across the test suite. The fixture is properly configured with necessary parameters.

However, consider adding a docstring to describe the fixture's purpose and configuration.

 @pytest.fixture(scope="session")
 def prometheus(admin_client: DynamicClient) -> Prometheus:
+    """
+    Returns a configured Prometheus client for querying metrics from the cluster.
+    
+    The client is configured to use the thanos-querier with the current user's token.
+    """
     return Prometheus(
         client=admin_client,
         resource_name="thanos-querier",
         verify_ssl=False,
         bearer_token=get_openshift_token(),
     )
tests/model_explainability/trustyai_service/fairness/test_fairness.py (1)

120-134: Well-implemented Prometheus integration test for fairness metrics.

This test verifies that TrustyAI's fairness metrics are properly exposed in Prometheus with the correct metadata. It makes good use of:

  1. The centralized Prometheus fixture
  2. The flexible validate_metrics_field function
  3. Partial function application to create a specialized label getter

To maintain consistency with other test methods, consider adding a docstring.

     def test_fairness_metric_prometheus(
         self,
         admin_client,
         model_namespace,
         trustyai_service_with_pvc_storage,
         onnx_loan_model,
         prometheus,
     ):
+        """Verify that TrustyAI fairness metrics are correctly exposed in Prometheus with proper labels."""
         validate_metrics_field(
             prometheus=prometheus,
             metrics_query=f'trustyai_{TrustyAIServiceMetrics.Fairness.SPD}{{namespace="{model_namespace.name}"}}',
             expected_value=TrustyAIServiceMetrics.Fairness.SPD.upper(),
             field_getter=partial(get_metric_label, label_name="metricName"),
         )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 212b8d9 and 7b617c6.

📒 Files selected for processing (7)
  • tests/conftest.py (2 hunks)
  • tests/model_explainability/trustyai_service/drift/test_drift.py (3 hunks)
  • tests/model_explainability/trustyai_service/fairness/test_fairness.py (3 hunks)
  • tests/model_serving/model_server/conftest.py (0 hunks)
  • tests/model_serving/model_server/metrics/test_model_metrics.py (3 hunks)
  • tests/model_serving/model_server/metrics/test_non_admin_users.py (2 hunks)
  • utilities/monitoring.py (2 hunks)
💤 Files with no reviewable changes (1)
  • tests/model_serving/model_server/conftest.py
🧰 Additional context used
🧬 Code Graph Analysis (5)
tests/conftest.py (1)
utilities/infra.py (1)
  • get_openshift_token (475-483)
tests/model_serving/model_server/metrics/test_model_metrics.py (1)
utilities/monitoring.py (2)
  • get_metrics_value (10-24)
  • validate_metrics_field (53-88)
tests/model_serving/model_server/metrics/test_non_admin_users.py (1)
utilities/monitoring.py (1)
  • validate_metrics_field (53-88)
tests/model_explainability/trustyai_service/fairness/test_fairness.py (5)
utilities/monitoring.py (2)
  • validate_metrics_field (53-88)
  • get_metric_label (27-50)
tests/conftest.py (3)
  • admin_client (51-52)
  • model_namespace (98-118)
  • prometheus (527-533)
tests/model_explainability/trustyai_service/conftest.py (1)
  • trustyai_service_with_pvc_storage (66-89)
tests/model_explainability/trustyai_service/fairness/conftest.py (1)
  • onnx_loan_model (40-69)
tests/model_explainability/trustyai_service/trustyai_service_utils.py (2)
  • TrustyAIServiceMetrics (32-37)
  • Fairness (33-34)
utilities/monitoring.py (1)
tests/conftest.py (1)
  • prometheus (527-533)
🔇 Additional comments (11)
tests/model_serving/model_server/metrics/test_non_admin_users.py (2)

10-10: Good refactoring to use the more flexible validation function.

The import change from validate_metrics_value to validate_metrics_field aligns with the broader refactoring in the monitoring utilities, providing more flexibility for metric validation.


70-74: Properly adapted function call to use the new API.

The call to validate_metrics_field maintains the same validation logic while leveraging the improved, more flexible API. This change ensures consistent metric validation behavior with enhanced capabilities.

tests/model_serving/model_server/metrics/test_model_metrics.py (3)

17-17: Appropriate update to import both validation function and the value getter.

The import now includes both validate_metrics_field and get_metrics_value, providing access to both the high-level validation function and the lower-level value getter if needed.


60-64: Successfully migrated to the enhanced metric validation API.

This change properly replaces the deprecated validate_metrics_value with the more flexible validate_metrics_field function, maintaining the same validation logic for successful model requests.


81-85: Consistent update to use the new validation API for total requests.

The migration to validate_metrics_field is done consistently across all metric validations, ensuring a uniform approach to metric testing throughout the test suite.

tests/conftest.py (1)

17-17: Added required import for the Prometheus client.

This import supports the new centralized Prometheus fixture, ensuring the necessary class is available to create the Prometheus client instance.

tests/model_explainability/trustyai_service/fairness/test_fairness.py (2)

1-1: Added partial function import for creating specialized field getters.

Good use of functools.partial to create specialized field getter functions for the metric validation.


17-17: Updated imports for the metric validation utilities.

The import now includes both validate_metrics_field and get_metric_label, providing access to the necessary functions for validating Prometheus metrics.

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

109-123: Well-implemented Prometheus integration test for drift metrics.

This test effectively validates that TrustyAI drift metrics are properly exposed in Prometheus, ensuring that monitoring systems can track model drift. The use of partial with get_metric_label is a clean approach to customize the field extraction.

utilities/monitoring.py (2)

10-51: Good extraction of metric value and label retrieval into separate functions.

These helper functions improve code modularity by clearly separating concerns:

  1. get_metrics_value cleanly extracts numeric values from Prometheus query results
  2. get_metric_label provides focused label extraction with appropriate logging

This separation makes the code more maintainable and facilitates the new label-based validations needed for TrustyAI metrics.


53-88: Well-designed refactoring of the metrics validation function.

The validate_metrics_field function generalizes the validation logic by:

  1. Using a customizable field_getter to support validation of any metric attribute
  2. Defaulting to value checking for backward compatibility
  3. Providing clear error messages and logging
  4. Using TimeoutSampler appropriately to handle eventual consistency

This flexible approach elegantly supports both the new label-based validations and existing value checks.

dbasunag
dbasunag previously approved these changes May 9, 2025
mwaykole
mwaykole previously approved these changes May 10, 2025
@adolfo-ab
Copy link
Copy Markdown
Contributor Author

/verified

@adolfo-ab adolfo-ab merged commit 168ff4c into opendatahub-io:main May 12, 2025
13 checks passed
@github-actions
Copy link
Copy Markdown

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.

6 participants