-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CLI argument for server-metrics-url #39
Changes from 8 commits
517c6f0
bb50ce2
fddf58f
d135c19
91bb0dc
96d9dff
37b6af0
8cff8ea
fefe4ab
f461c83
05ff8fb
b922910
4daf377
aee3a92
f3efd80
27d5055
486c949
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -917,3 +917,75 @@ def test_get_extra_inputs_as_dict(self, extra_inputs_list, expected_dict): | |
namespace.extra_inputs = extra_inputs_list | ||
actual_dict = parser.get_extra_inputs_as_dict(namespace) | ||
assert actual_dict == expected_dict | ||
|
||
TEST_TRITON_METRICS_URL = "http://custom-metrics-url:8002/metrics" | ||
INVALID_URL = "invalid_url" | ||
INVALID_URL_ERROR_MESSAGE = ( | ||
"The URL passed for --server-metrics-url is invalid. " | ||
"It must use 'http' or 'https', have a valid domain, " | ||
"and contain '/metrics' in the path. The expected structure is: " | ||
"<scheme>://<netloc>/<path>;<params>?<query>#<fragment>" | ||
) | ||
|
||
@pytest.mark.parametrize( | ||
"args_list, expected_url, expected_error", | ||
[ | ||
# Test with a custom URL | ||
( | ||
[ | ||
"genai-perf", | ||
"profile", | ||
"--model", | ||
"test_model", | ||
"--service-kind", | ||
"triton", | ||
"--server-metrics-url", | ||
TEST_TRITON_METRICS_URL, | ||
], | ||
TEST_TRITON_METRICS_URL, | ||
None, | ||
), | ||
# Test with default URL | ||
( | ||
[ | ||
"genai-perf", | ||
"profile", | ||
"--model", | ||
"test_model", | ||
"--service-kind", | ||
"triton", | ||
], | ||
None, | ||
None, | ||
), | ||
# Test with invalid URL | ||
( | ||
[ | ||
"genai-perf", | ||
"profile", | ||
"--model", | ||
"test_model", | ||
"--service-kind", | ||
"triton", | ||
"--server-metrics-url", | ||
INVALID_URL, | ||
], | ||
None, | ||
INVALID_URL_ERROR_MESSAGE, | ||
), | ||
], | ||
) | ||
def test_server_metrics_url_for_triton( | ||
debermudez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self, args_list, expected_url, expected_error, monkeypatch, capsys | ||
): | ||
monkeypatch.setattr("sys.argv", args_list) | ||
|
||
if expected_error: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you start using branching logic like this, it suggests this should be two tests. Do you want to add the valid test to the test_cli valid arg test and then have a separate one just for the error testing? That assumes there's not a generic error test that you can reuse... which if we don't have, we should refactor sometime soon to add. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have test_conditional_errors, that handles error scenarios. |
||
with pytest.raises(SystemExit) as excinfo: | ||
parser.parse_args() | ||
captured = capsys.readouterr() | ||
assert expected_error in captured.err | ||
assert excinfo.value.code != 0 | ||
else: | ||
args, _ = parser.parse_args() | ||
assert args.server_metrics_url == expected_url |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/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, | ||
) | ||
|
||
TRITON_TEST_METRICS_URL = "http://tritonmetrics.com:8080/metrics" | ||
|
||
|
||
# Parameterized fixture | ||
@pytest.fixture( | ||
params=[ | ||
{"service_kind": "triton", "server_metrics_url": TRITON_TEST_METRICS_URL}, | ||
{"service_kind": "triton", "server_metrics_url": None}, # Default URL case | ||
] | ||
) | ||
def mock_args(request): | ||
params = request.param | ||
|
||
class MockArgs: | ||
def __init__(self, service_kind, server_metrics_url): | ||
self.service_kind = service_kind | ||
self.server_metrics_url = server_metrics_url | ||
|
||
return MockArgs(params["service_kind"], params["server_metrics_url"]) | ||
|
||
|
||
@patch("genai_perf.wrapper.Profiler.run") | ||
def test_profile_handler_creates_telemetry_collector_triton( | ||
mock_profiler_run, mock_args | ||
): | ||
profile_handler(mock_args, extra_args={}) | ||
mock_profiler_run.assert_called_once() | ||
|
||
args, kwargs = mock_profiler_run.call_args | ||
telemetry_collector = kwargs.get("telemetry_data_collector") | ||
|
||
expected_url = ( | ||
TRITON_TEST_METRICS_URL | ||
if mock_args.server_metrics_url == TRITON_TEST_METRICS_URL | ||
else DEFAULT_TRITON_METRICS_URL | ||
) | ||
|
||
assert isinstance(telemetry_collector, TritonTelemetryDataCollector) | ||
assert telemetry_collector.metrics_url == expected_url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for creating these global variables? I feel like this could be confusing. I'd need to scroll down quite a bit to see why they are used. It'd be better to have these as local variables inside the one test.