Skip to content

Commit

Permalink
Fix pre-commit errors and test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lkomali committed Aug 13, 2024
1 parent c325234 commit cfc252a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 42 deletions.
40 changes: 2 additions & 38 deletions genai-perf/genai_perf/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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'.",
)


Expand Down Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
5 changes: 3 additions & 2 deletions genai-perf/genai_perf/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -162,4 +164,3 @@ def run(
finally:
if telemetry_data_collector is not None:
telemetry_data_collector.stop()

1 change: 0 additions & 1 deletion genai-perf/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def test_help_version_arguments_output_and_exit(
"embeddings",
"--service-kind",
"openai",
],
{"batch_size": 5},
),
Expand Down
1 change: 1 addition & 0 deletions genai-perf/tests/test_json_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit cfc252a

Please sign in to comment.