From cfc252a1ac58c7cdb86bdc0609938366f00d6f13 Mon Sep 17 00:00:00 2001 From: lkomali Date: Tue, 13 Aug 2024 09:58:02 -0700 Subject: [PATCH] Fix pre-commit errors and test errors --- genai-perf/genai_perf/parser.py | 40 +------------------ .../telemetry_data_collector.py | 2 +- genai-perf/genai_perf/wrapper.py | 5 ++- genai-perf/tests/test_cli.py | 1 - genai-perf/tests/test_json_exporter.py | 1 + 5 files changed, 7 insertions(+), 42 deletions(-) diff --git a/genai-perf/genai_perf/parser.py b/genai-perf/genai_perf/parser.py index 8bc0017d..d9803608 100644 --- a/genai-perf/genai_perf/parser.py +++ b/genai-perf/genai_perf/parser.py @@ -245,42 +245,6 @@ def _check_load_manager_args(args: argparse.Namespace) -> argparse.Namespace: args.concurrency = 1 return args -def is_valid_url(url): - """ - Checks if a URL is valid. It must use 'http' or 'https', have a valid - netloc, optional port, and contain '/metrics' in the path. - """ - try: - result = urlparse(url) - - # Check scheme - if result.scheme not in ['http', 'https']: - return False - - # Check netloc - if not result.netloc: - return False - - # Check path contains '/metrics' - if '/metrics' not in result.path: - return False - - return True - except Exception: - return False - - -def _check_server_metrics_url(parser: argparse.ArgumentParser, args: argparse.Namespace) -> argparse.Namespace: - """ - Checks if the server metrics URL is valid based on the backend and service kind. - """ - - # Check if the URL is valid and contains the expected path - if args.service_kind == 'triton' and args.server_metrics_url and not is_valid_url(args.server_metrics_url): - parser.error("The --server-metrics-url option contains an invalid URL format.") - - return args - def is_valid_url(url): """ @@ -688,7 +652,7 @@ def _add_endpoint_args(parser): type=str, default=None, required=False, - help="URL of the server metrics endpoint. Required for 'openai' service kind. Defaults to the default URL if 'service_kind' is 'triton'." + help="URL of the server metrics endpoint. Required for 'openai' service kind. Defaults to the default URL if 'service_kind' is 'triton'.", ) @@ -855,7 +819,7 @@ def profile_handler(args, extra_args): telemetry_data_collector = None if args.service_kind == "triton": - server_metrics_url=args.server_metrics_url or DEFAULT_TRITON_METRICS_URL + server_metrics_url = args.server_metrics_url or DEFAULT_TRITON_METRICS_URL telemetry_data_collector = TritonTelemetryDataCollector( server_metrics_url=server_metrics_url ) diff --git a/genai-perf/genai_perf/telemetry_data/telemetry_data_collector.py b/genai-perf/genai_perf/telemetry_data/telemetry_data_collector.py index 1c66e115..20bd7b6d 100755 --- a/genai-perf/genai_perf/telemetry_data/telemetry_data_collector.py +++ b/genai-perf/genai_perf/telemetry_data/telemetry_data_collector.py @@ -91,7 +91,7 @@ def _collect_metrics(self) -> None: def metrics(self) -> TelemetryMetrics: """Return the collected metrics.""" return self._metrics - + @property def metrics_url(self) -> str: """Return server metrics url""" diff --git a/genai-perf/genai_perf/wrapper.py b/genai-perf/genai_perf/wrapper.py index 9c6f9757..a50f1504 100644 --- a/genai-perf/genai_perf/wrapper.py +++ b/genai-perf/genai_perf/wrapper.py @@ -152,7 +152,9 @@ def run( if telemetry_data_collector.check_url_reachability(): telemetry_data_collector.start() else: - logger.debug(f"The server-metrics-url provided ({telemetry_data_collector.metrics_url}) is unreachable, cannot collect telemetry data") + logger.debug( + f"The server-metrics-url provided ({telemetry_data_collector.metrics_url}) is unreachable, cannot collect telemetry data" + ) cmd = Profiler.build_cmd(args, extra_args) logger.info(f"Running Perf Analyzer : '{' '.join(cmd)}'") if args and args.verbose: @@ -162,4 +164,3 @@ def run( finally: if telemetry_data_collector is not None: telemetry_data_collector.stop() - diff --git a/genai-perf/tests/test_cli.py b/genai-perf/tests/test_cli.py index 6e6964aa..6ec2f2e5 100644 --- a/genai-perf/tests/test_cli.py +++ b/genai-perf/tests/test_cli.py @@ -87,7 +87,6 @@ def test_help_version_arguments_output_and_exit( "embeddings", "--service-kind", "openai", - ], {"batch_size": 5}, ), diff --git a/genai-perf/tests/test_json_exporter.py b/genai-perf/tests/test_json_exporter.py index 8b6e96e3..fa37ca0c 100644 --- a/genai-perf/tests/test_json_exporter.py +++ b/genai-perf/tests/test_json_exporter.py @@ -327,6 +327,7 @@ def test_generate_json_custom_export( "service_kind": "triton", "streaming": true, "u": null, + "server_metrics_url": null, "input_dataset": null, "num_prompts": 100, "output_tokens_mean": -1,