-
Notifications
You must be signed in to change notification settings - Fork 588
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
Fix metrics #1963
Merged
Merged
Fix metrics #1963
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0717148
Move environ location and add missing dependency
binarycrayon ce40d67
Add unit test to check metrics with enable_metrics flag
binarycrayon 24acce8
Merge branch 'main' into fix-metrics
binarycrayon fa39658
Fix lint error
binarycrayon 3fa9361
remove unused and redundant stats entry
binarycrayon 588f2c3
Fix buckets for time based historgram metrics
binarycrayon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,84 @@ | ||
import unittest | ||
from types import SimpleNamespace | ||
|
||
import requests | ||
|
||
from sglang.srt.utils import kill_child_process | ||
from sglang.test.run_eval import run_eval | ||
from sglang.test.test_utils import ( | ||
DEFAULT_MODEL_NAME_FOR_TEST, | ||
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH, | ||
DEFAULT_URL_FOR_TEST, | ||
popen_launch_server, | ||
) | ||
|
||
TEST_MODEL = ( | ||
DEFAULT_MODEL_NAME_FOR_TEST # I used "google/gemma-2-2b-it" for testing locally | ||
) | ||
|
||
|
||
class TestEnableMetrics(unittest.TestCase): | ||
def test_metrics_enabled(self): | ||
"""Test that metrics endpoint returns data when enabled""" | ||
# Launch server with metrics enabled | ||
process = popen_launch_server( | ||
model=TEST_MODEL, | ||
base_url=DEFAULT_URL_FOR_TEST, | ||
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH, | ||
enable_metrics=True, | ||
) | ||
|
||
try: | ||
# Make a request to generate some metrics | ||
response = requests.get(f"{DEFAULT_URL_FOR_TEST}/health_generate") | ||
self.assertEqual(response.status_code, 200) | ||
|
||
# Get metrics | ||
metrics_response = requests.get(f"{DEFAULT_URL_FOR_TEST}/metrics") | ||
self.assertEqual(metrics_response.status_code, 200) | ||
metrics_content = metrics_response.text | ||
|
||
# Verify essential metrics are present | ||
essential_metrics = [ | ||
"sglang:prompt_tokens_total", | ||
"sglang:generation_tokens_total", | ||
"sglang:max_total_num_tokens", | ||
"sglang:context_len", | ||
"sglang:time_to_first_token_seconds", | ||
"sglang:time_per_output_token_seconds", | ||
"sglang:e2e_request_latency_seconds", | ||
] | ||
|
||
for metric in essential_metrics: | ||
self.assertIn(metric, metrics_content, f"Missing metric: {metric}") | ||
|
||
# Verify model name label is present and correct | ||
expected_model_name = TEST_MODEL | ||
self.assertIn(f'model_name="{expected_model_name}"', metrics_content) | ||
# Verify metrics have values (not empty) | ||
self.assertIn("_sum{", metrics_content) | ||
self.assertIn("_count{", metrics_content) | ||
self.assertIn("_bucket{", metrics_content) | ||
|
||
finally: | ||
kill_child_process(process.pid, include_self=True) | ||
|
||
def test_metrics_disabled(self): | ||
"""Test that metrics endpoint returns 404 when disabled""" | ||
# Launch server with metrics disabled | ||
process = popen_launch_server( | ||
model=TEST_MODEL, | ||
base_url=DEFAULT_URL_FOR_TEST, | ||
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH, | ||
enable_metrics=False, | ||
) | ||
|
||
try: | ||
response = requests.get(f"{DEFAULT_URL_FOR_TEST}/health_generate") | ||
self.assertEqual(response.status_code, 200) | ||
# Verify metrics endpoint is not available | ||
metrics_response = requests.get(f"{DEFAULT_URL_FOR_TEST}/metrics") | ||
self.assertEqual(metrics_response.status_code, 404) | ||
|
||
finally: | ||
kill_child_process(process.pid, include_self=True) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm happy to take suggestions here