Skip to content

Add unified metrics collection framework (v1)#16064

Merged
Kangyan-Zhou merged 12 commits intosgl-project:mainfrom
harvenstar:feat/unified-metrics-framework
Jan 4, 2026
Merged

Add unified metrics collection framework (v1)#16064
Kangyan-Zhou merged 12 commits intosgl-project:mainfrom
harvenstar:feat/unified-metrics-framework

Conversation

@harvenstar
Copy link
Copy Markdown
Collaborator

Implement dump_metric() function for test metrics collection:

  • Outputs to JSONL (${SGLANG_TEST_METRICS_OUTPUT}.${pid}.jsonl)
  • Outputs to stdout ([METRIC] format)
  • Schema: required {filename, test_case, metric_name, value}
  • Optional: {ts, labels}
  • Supports int/float/str, coerces bool to int
  • Auto-captures test context via PYTEST_CURRENT_TEST or inspect
  • Never fails tests, all errors silently caught

Includes comprehensive unit tests covering:

  • JSONL format validation
  • Value type conversions
  • Labels serialization handling
  • Environment variable behavior

Part of #15996 - unified CI metrics collection framework.

cc @Kangyan-Zhou @merrymercy

Implement dump_metric() function for test metrics collection:
- Outputs to JSONL (${SGLANG_TEST_METRICS_OUTPUT}.${pid}.jsonl)
- Outputs to stdout ([METRIC] format)
- Schema: required {filename, test_case, metric_name, value}
- Optional: {ts, labels}
- Supports int/float/str, coerces bool to int
- Auto-captures test context via PYTEST_CURRENT_TEST or inspect
- Never fails tests, all errors silently caught

Includes comprehensive unit tests covering:
- JSONL format validation
- Value type conversions
- Labels serialization handling
- Environment variable behavior

Part of sgl-project#15996 - unified CI metrics collection framework.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @harvenstar, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request establishes a foundational, unified framework for collecting test metrics within the sglang project. It introduces a dump_metric function designed to standardize how performance and other test-related data are recorded, outputting them to both structured JSONL files for programmatic consumption and human-readable stdout logs. The system is built for robustness, automatically capturing test context and handling various data types without interrupting test execution, thereby facilitating consistent and reliable CI metrics collection.

Highlights

  • Unified Metric Collection: Introduced a new dump_metric function to standardize the collection of test metrics across the project.
  • Flexible Output Formats: Metrics are outputted to both a structured JSONL file (specified by SGLANG_TEST_METRICS_OUTPUT environment variable) and to stdout in a human-readable [METRIC] format.
  • Standardized Metric Schema: Each metric record adheres to a defined schema, including required fields like filename, test_case, metric_name, value, and optional fields such as ts (timestamp) and labels.
  • Robust Value and Context Handling: The function supports int, float, and str values, coercing booleans to integers (True=1, False=0), and attempts best-effort conversion for other types. It automatically captures test context (filename and test case) using PYTEST_CURRENT_TEST or Python's inspect module.
  • Error Resilience: All errors during metric collection are silently caught, ensuring that the metric dumping process never causes tests to fail.
  • Comprehensive Unit Tests: A new test file python/sglang/test/test_dump_metric.py has been added, providing extensive coverage for JSONL format validation, value type conversions, label serialization, and environment variable behavior.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a valuable framework for unified metrics collection in tests, which will be very useful for CI performance tracking. The implementation is robust, featuring silent error handling to prevent test failures and a comprehensive set of unit tests. I have a few suggestions to enhance it further:

  • In test_dump_metric.py, I recommend refactoring to avoid code duplication in setUp and tearDown for better maintainability.
  • In dump_metric, I suggest adding logging for caught exceptions. This will significantly aid debugging when metrics are not being reported, without violating the "never fail" contract.
  • To improve the consistency and parsability of stdout logs, I propose using JSON serialization for the labels dictionary.

Comment thread python/sglang/test/test_dump_metric.py
Comment thread python/sglang/test/test_utils.py Outdated
Comment thread python/sglang/test/test_utils.py Outdated
Comment thread python/sglang/test/test_utils.py Outdated
harvenstar and others added 6 commits December 29, 2025 18:25
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Per reviewer feedback, integrate the unified metrics collection framework
into run_eval() function to automatically report eval metrics in both
single-run and repeat-run scenarios.

This enables all evaluations using run_eval() to automatically output
metrics to the standardized JSONL format for CI performance tracking.

Metrics reported:
- {eval_name}_score: evaluation score (single-run mode)
- {eval_name}_latency: evaluation latency (single-run mode)
- {eval_name}_mean_score: mean score across runs (repeat mode)

All metrics include labels with model name, eval name, and repeat count
(when applicable) for better tracking and analysis.
@Kangyan-Zhou
Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci label Jan 2, 2026
@Kangyan-Zhou
Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@Kangyan-Zhou Kangyan-Zhou merged commit f4ab2ec into sgl-project:main Jan 4, 2026
103 of 108 checks passed
harvenstar added a commit to harvenstar/sglang that referenced this pull request Jan 6, 2026
- Add scripts/ci/merge_metrics.py to merge per-process JSONL files
- Configure SGLANG_TEST_METRICS_OUTPUT in stage-b jobs
- Upload metrics artifacts with if: always() for flaky test diagnosis
- Include both merged and raw per-worker files for debugging

Related to sgl-project#15996, follows up on sgl-project#16064
harvenstar added a commit to harvenstar/sglang that referenced this pull request Jan 8, 2026
- Add scripts/ci/merge_metrics.py to merge per-process JSONL files
- Configure SGLANG_TEST_METRICS_OUTPUT in stage-b jobs
- Upload metrics artifacts with if: always() for flaky test diagnosis
- Include both merged and raw per-worker files for debugging

Related to sgl-project#15996, follows up on sgl-project#16064
YChange01 pushed a commit to YChange01/sglang that referenced this pull request Jan 13, 2026
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants