diff --git a/tests/model_serving/model_server/metrics/conftest.py b/tests/model_serving/model_server/metrics/conftest.py index c987dcc..bed2258 100644 --- a/tests/model_serving/model_server/metrics/conftest.py +++ b/tests/model_serving/model_server/metrics/conftest.py @@ -1,5 +1,6 @@ import pytest import requests +from _pytest.fixtures import FixtureRequest from kubernetes.dynamic import DynamicClient from ocp_utilities.monitoring import Prometheus from simple_logger.logger import get_logger @@ -20,12 +21,14 @@ def prometheus(admin_client: DynamicClient) -> Prometheus: ) -@pytest.fixture(scope="class") -def deleted_metrics(prometheus: Prometheus) -> None: - for metric in ("tgi_request_success", "tgi_request_count"): - LOGGER.info(f"deleting {metric} metric") - requests.post( - f"{prometheus.api_url}/api/v1/admin/tsdb/delete_series?match[]={metric}", - headers=prometheus.headers, - verify=prometheus.verify_ssl, - ) +@pytest.fixture() +def deleted_metric(request: FixtureRequest, prometheus: Prometheus) -> None: + metric = request.param["metric-name"] + + LOGGER.info(f"deleting {metric} metric") + + requests.post( + f"{prometheus.api_url}/api/v1/admin/tsdb/delete_series?match[]={metric}", + headers=prometheus.headers, + verify=prometheus.verify_ssl, + ) diff --git a/tests/model_serving/model_server/metrics/test_model_metrics.py b/tests/model_serving/model_server/metrics/test_model_metrics.py index 924dd51..034548b 100644 --- a/tests/model_serving/model_server/metrics/test_model_metrics.py +++ b/tests/model_serving/model_server/metrics/test_model_metrics.py @@ -25,13 +25,12 @@ ], indirect=True, ) -@pytest.mark.usefixtures("deleted_metrics") class TestModelMetrics: @pytest.mark.smoke @pytest.mark.polarion("ODS-2555") - @pytest.mark.dependency(name="test_model_metrics_num_success_requests") + @pytest.mark.parametrize("deleted_metric", [["tgi_request_success"]], indirect=True) def test_model_metrics_num_success_requests( - self, http_s3_caikit_serverless_inference_service_auth_disabled, prometheus + self, http_s3_caikit_serverless_inference_service_auth_disabled, deleted_metric, prometheus ): """Verify number of successful model requests in OpenShift monitoring system (UserWorkloadMonitoring)metrics""" verify_inference_response( @@ -50,9 +49,9 @@ def test_model_metrics_num_success_requests( @pytest.mark.smoke @pytest.mark.polarion("ODS-2555") - @pytest.mark.dependency(depends=["test_model_metrics_num_success_requests"]) + @pytest.mark.parametrize("deleted_metric", [["tgi_request_count"]], indirect=True) def test_model_metrics_num_total_requests( - self, http_s3_caikit_serverless_inference_service_auth_disabled, prometheus + self, http_s3_caikit_serverless_inference_service_auth_disabled, deleted_metric, prometheus ): """Verify number of total model requests in OpenShift monitoring system (UserWorkloadMonitoring)metrics""" total_runs = 5 @@ -69,5 +68,5 @@ def test_model_metrics_num_total_requests( validate_metrics_value( prometheus=prometheus, metric_name="tgi_request_count", - expected_value=str(total_runs + 1), + expected_value=str(total_runs), )