Skip to content

Commit

Permalink
Graceful handling of exception thrown by genai-perf if metrics url is…
Browse files Browse the repository at this point in the history
… unreachable (#47)

* Fix exception thrown by genai-perf if metrics url is unreachable

* Fix comments

* Fix comments

* Fix comments

* Add space in error message
  • Loading branch information
lkomali committed Aug 27, 2024
1 parent fddf58f commit d135c19
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions genai-perf/tests/test_telemetry_data_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TestTelemetryDataCollector:

TEST_SERVER_URL = "http://testserver:8080/metrics"

TRITON_METRICS_RESPONSE = """\
TRITON_METRICS_RESPONSE = """\
nv_gpu_power_usage{gpu="0",uuid="GPU-1234"} 123.45
nv_gpu_power_usage{gpu="1",uuid="GPU-5678"} 234.56
Expand Down Expand Up @@ -99,13 +100,15 @@ def test_fetch_metrics_success(
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.text = self.TRITON_METRICS_RESPONSE
mock_response.text = self.TRITON_METRICS_RESPONSE
mock_requests_get.return_value = mock_response

result = collector._fetch_metrics()

mock_requests_get.assert_called_once_with(self.TEST_SERVER_URL)

assert result == self.TRITON_METRICS_RESPONSE
assert result == self.TRITON_METRICS_RESPONSE

@patch("requests.get")
def test_fetch_metrics_failure(
Expand All @@ -126,19 +129,23 @@ def test_collect_metrics(
) -> None:

mock_fetch_metrics.return_value = self.TRITON_METRICS_RESPONSE
mock_fetch_metrics.return_value = self.TRITON_METRICS_RESPONSE

with patch.object(
collector, "_process_and_update_metrics", new_callable=MagicMock
) as mock_process_and_update_metrics:


collector._stop_event = MagicMock()
collector._stop_event.is_set = MagicMock(side_effect=[False, True])
collector._stop_event.is_set = MagicMock(side_effect=[False, True])

collector._collect_metrics()

mock_fetch_metrics.assert_called_once()
mock_process_and_update_metrics.assert_called_once_with(
self.TRITON_METRICS_RESPONSE
self.TRITON_METRICS_RESPONSE
)
mock_sleep.assert_called_once()

Expand Down

0 comments on commit d135c19

Please sign in to comment.