Skip to content

Unify metrics tests to use shared fixture + .filter() pattern #881

@silvi-t

Description

@silvi-t

Description

Currently, metrics tests across the testsuite are inconsistent in how they query and filter Prometheus metrics — some use has_label(), others use raw lambdas, and some make individual prometheus.get_metrics() calls per test without a shared fixture.

The CoreDNS tests (testsuite/tests/multicluster/coredns/two_clusters/metrics/test_metrics.py) demonstrate the preferred pattern:

  1. Fetch all relevant metrics once in a module-scoped fixture
  2. Use .filter(has_label(...)) in individual tests to filter from the already-collected metrics

This approach reduces the number of Prometheus API calls and provides a consistent interface.

Files to review and refactor

  • testsuite/tests/singlecluster/limitador/metrics/test_metrics.py
  • testsuite/tests/singlecluster/limitador/metrics/trlp_metrics/test_trlp_metrics.py
  • testsuite/tests/singlecluster/limitador/metrics/trlp_metrics/test_trlp_metrics_stream.py
  • testsuite/tests/singlecluster/authorino/metrics/test_deep_metrics.py
    Note: This list may not be exhaustive. Search the testsuite for other metrics test files that could benefit from the same refactoring.

Acceptance criteria

  • All metrics tests use a shared module-scoped fixture for fetching metrics
  • Filtering is done via .filter(has_label(...)) instead of passing labels to get_metrics() in each test
  • No change in test coverage or behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomersrefactorRefactor with same functionality

    Type

    No type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions