Skip to content
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 #37

Closed
wants to merge 0 commits into from
Closed

Conversation

lkomali
Copy link
Contributor

@lkomali lkomali commented Aug 13, 2024

This PR adds a CLI argument to get server metrics url when the server is running on a machine different from the one genai-perf is running.

  • Added a --server-metrics-url to endpoint arguments
  • Check the server_metrics_url if all conditions are met
  • Test different scenarios - default case, non-default case, invalid url
  • Added a check if url is reachable or not to catch the error gracefully and display it

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add this to the docstring:

<scheme>://<netloc>/<path>;<params>?<query>#<fragment>

so we know what the pattern is for the url?


return True
except Exception:
return False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we just want to return false here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function returns if url is valid or not and the _check_server_metrics_url will display error message based on the return value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will move the exception to this function.

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.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this exception into is_valid_url.
And update this method to check service kind and existence of the metrics url. Then return the result of _is_valid_url.

This way, as we add more checks later, we can make the call to the url validation method and it will bubble up the exception if one is thrown.

@@ -604,6 +647,14 @@ def _add_endpoint_args(parser):
help="URL of the endpoint to target for benchmarking.",
)

endpoint_group.add_argument(
"--server-metrics-url",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets keep these alphabetized based on the option name.

if self._server_metrics_url:
try:
response = requests.get(self._server_metrics_url, timeout=5)
return response.status_code == 200
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return response.status_code == 200
return response.status_code == response.codes.ok

Copy link
Contributor

@dyastremsky dyastremsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Can you add a unit test that tests the functionality you added (not just the parsing)?

"""

# 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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we return the exact error with the URL?

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems redundant and like it'll get out of sync with the code below. It's already out of sync, since it mentions that it must have an optional port, which I don't think means anything and there is no port-related check here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I will update the comment. I had a check for port earlier but removed it after reading about netloc.

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'.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be required. It'd be good to avoid adding required args.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will modify the comment.

Base automatically changed from lkomali-tpa-192 to main August 14, 2024 15:03
benchmark_duration=self.TEST_BENCHMARK_DURATION,
)

assert gc.goodput == None # before computing

Check notice

Code scanning / CodeQL

Testing equality to None

Testing for None should use the 'is' operator.
metric=test_llm_metrics_1,
benchmark_duration=self.TEST_BENCHMARK_DURATION,
)
assert gc_1.goodput == None # before computing

Check notice

Code scanning / CodeQL

Testing equality to None

Testing for None should use the 'is' operator.
metric=test_llm_metrics_2,
benchmark_duration=self.TEST_BENCHMARK_DURATION,
)
assert gc_2.goodput == None # before computing

Check notice

Code scanning / CodeQL

Testing equality to None

Testing for None should use the 'is' operator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants