-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI argument for server-metrics-url (#39)
* Add CLI argument for server-metrics-url * Remove print statement * Fix pre-commit error * Graceful handling of exception thrown by genai-perf if metrics url is unreachable (#47) * Fix exception thrown by genai-perf if metrics url is unreachable * Fix comments * Fix comments * Fix comments * Add space in error message * Add CLI argument for server-metrics-url * Fix pre-commit error and remove duplicates * Remove unnecessary print * Fix comments * Fix pytest error * Fix comments * Refactor test function names * Fix comments * Fix comment in test_profile_handler * Cleanup test_profile_handler.py test * Move MockArgs outside TestProfileHandler * Move test triton metrics url to a variable
- Loading branch information
Showing
5 changed files
with
192 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of NVIDIA CORPORATION nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
from unittest.mock import patch | ||
|
||
import pytest | ||
from genai_perf.constants import DEFAULT_TRITON_METRICS_URL | ||
from genai_perf.parser import profile_handler | ||
from genai_perf.telemetry_data.triton_telemetry_data_collector import ( | ||
TritonTelemetryDataCollector, | ||
) | ||
|
||
|
||
class MockArgs: | ||
def __init__(self, service_kind, server_metrics_url): | ||
self.service_kind = service_kind | ||
self.server_metrics_url = server_metrics_url | ||
|
||
|
||
class TestProfileHandler: | ||
test_triton_metrics_url = "http://tritonmetrics.com:8080/metrics" | ||
|
||
@pytest.mark.parametrize( | ||
"server_metrics_url, expected_url", | ||
[ | ||
(test_triton_metrics_url, test_triton_metrics_url), | ||
(None, DEFAULT_TRITON_METRICS_URL), | ||
], | ||
) | ||
@patch("genai_perf.wrapper.Profiler.run") | ||
def test_profile_handler_creates_telemetry_collector( | ||
self, mock_profiler_run, server_metrics_url, expected_url | ||
): | ||
mock_args = MockArgs( | ||
service_kind="triton", server_metrics_url=server_metrics_url | ||
) | ||
profile_handler(mock_args, extra_args={}) | ||
mock_profiler_run.assert_called_once() | ||
|
||
args, kwargs = mock_profiler_run.call_args | ||
|
||
assert "telemetry_data_collector" in kwargs | ||
|
||
telemetry_data_collector = kwargs["telemetry_data_collector"] | ||
assert isinstance(telemetry_data_collector, TritonTelemetryDataCollector) | ||
assert telemetry_data_collector.metrics_url == expected_url |