Kuadrant / Kuadrant/testsuite

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

Open
#881 0 comments 0 reactions 0 assignees View on GitHub
good first issue refactor
Dominant language
Python
Stars
7
Forks
29
Avg merge
1d 9h
Merged PRs (30d)
7

Description

### 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

Contributor guide

Open the contributing guide

Research direction

Start with the preferred pattern in testsuite/tests/multicluster/coredns/two_clusters/metrics/test_metrics.py, then review the four listed Limitador and Authorino metrics test files. Search the testsuite for other metrics tests using per-test get_metrics() calls, and run the affected tests. Done means metrics are fetched through shared module-scoped fixtures, filtering uses .filter(has_label(...)), and coverage and behavior remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
prometheus, python
Domain
observability, testing
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.