Skip to content

feat: add metrics_aggregator service for real-time metric computation#188

Merged
nv-alicheng merged 12 commits intomainfrom
feat/alicheng-metrics-aggregator
Mar 24, 2026
Merged

feat: add metrics_aggregator service for real-time metric computation#188
nv-alicheng merged 12 commits intomainfrom
feat/alicheng-metrics-aggregator

Conversation

@nv-alicheng
Copy link
Copy Markdown
Collaborator

  • MetricsAggregator: subscribes to ZMQ events, computes QPS/latency/TTFT/TPOT
  • MetricsTable: columnar storage for efficient percentile calculations
  • TokenMetrics: ISL/OSL token-level metrics from PromptData
  • MetricsEmitter: periodic metric publishing
  • Service entry point with CLI interface
  • Comprehensive unit and e2e tests

What does this PR do?

Type of change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor/cleanup

Related issues

Testing

  • Tests added/updated
  • All tests pass locally
  • Manual testing completed

Checklist

  • Code follows project style
  • Pre-commit hooks pass
  • Documentation updated (if needed)

@nv-alicheng nv-alicheng requested a review from a team as a code owner March 18, 2026 00:56
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 18, 2026

MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅

@github-actions github-actions bot requested review from arekay-nv and nvzhihanj March 18, 2026 00:56
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 introduces a new metrics_aggregator service designed to provide real-time performance insights for inference requests. By subscribing to event streams, the service calculates critical metrics such as time-to-first-token, end-to-end latency, request duration, and token-level performance (input/output token counts and time-per-output-token). This enhancement allows for detailed monitoring and analysis of the inference endpoint's performance characteristics.

Highlights

  • Metrics Aggregation Service: Introduced MetricsAggregatorService to subscribe to ZMQ events and compute real-time metrics like QPS, latency, TTFT, and TPOT.
  • Data Storage and Calculation: Implemented MetricsTable for efficient in-memory storage and percentile calculations of per-sample metric data.
  • Token-Level Metrics: Added TokenizePool to handle token-level metrics (ISL/OSL/TPOT) using HuggingFace tokenizers in a thread-safe manner.
  • Metric Emission: Developed JsonlMetricEmitter for periodic publishing of computed metrics to a JSONL file.
  • Command-Line Interface: Provided a command-line interface (CLI) entry point for the new metrics aggregator service.
  • Testing: Included comprehensive unit and end-to-end tests to ensure the correctness and reliability of the new service.

🧠 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.

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

@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 new metrics_aggregator service for real-time metric computation from ZMQ events. The implementation is well-structured, with clear separation of concerns for event processing, metric emission, and tokenization. The accompanying unit and end-to-end tests are comprehensive and cover many edge cases, ensuring the reliability of the new service.

My review includes a few suggestions to improve maintainability and performance. These include simplifying resource management using context managers, improving typing for better static analysis, and a design suggestion to potentially increase event processing throughput by offloading tokenization to a background task.

@nv-alicheng nv-alicheng force-pushed the feat/alicheng-event-logger branch from a1d6ba4 to b51f11b Compare March 18, 2026 03:43
@nv-alicheng nv-alicheng force-pushed the feat/alicheng-metrics-aggregator branch from f2ec2f8 to 14fdfdc Compare March 18, 2026 03:43
@nv-alicheng nv-alicheng changed the base branch from feat/alicheng-event-logger to main March 18, 2026 23:24
Copy link
Copy Markdown
Collaborator

@nvzhihanj nvzhihanj left a comment

Choose a reason for hiding this comment

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

Review Council — Multi-AI Code Review

Found 3 issues across 3 files.

@nvzhihanj
Copy link
Copy Markdown
Collaborator

Review Council — Multi-AI Code Review Council

Reviewed by: Claude
(Codex identified a potential batch-shutdown bug but couldn't produce structured output due to exec-mode sandbox limitations)

Found 3 issues across 3 files:

  • 2 high
  • 1 medium

Each issue is posted as an inline comment on the relevant file and line.

# File Line Severity Reviewer(s) Summary
1 src/.../metrics_aggregator/emitter.py 73 high Claude + Codex* emit() missing None guard — will crash if ISL task fires after close() sets _file = None
2 src/.../metrics_aggregator/aggregator.py 222 medium Claude + Codex* _schedule_isl fire-and-forget tasks not awaited during _finalize(), racing against emitter close()
3 pyproject.toml 55 high Claude sqlalchemy added as core dependency but only used by optional SQL logger — should be in optional-dependencies

*Codex independently identified "a likely batch-shutdown bug in the aggregator" before sandbox restrictions prevented it from producing structured output.

🤖 Generated with Claude Code

Copy link
Copy Markdown
Collaborator

@nvzhihanj nvzhihanj left a comment

Choose a reason for hiding this comment

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

Review Council — Multi-AI Code Review

Found 10 issues (2 high, 6 medium, 2 low).

Copy link
Copy Markdown
Collaborator

@nvzhihanj nvzhihanj left a comment

Choose a reason for hiding this comment

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

Review Council — Multi-AI Code Review

Found 10 issues (2 high, 6 medium, 2 low).

nvzhihanj

This comment was marked as spam.

@nvzhihanj
Copy link
Copy Markdown
Collaborator

Review Council — Multi-AI Code Review Council

Reviewed by: Claude (Codex timed out) | Depth: thorough

Found 10 issues across 8 files.

🔴 Must Fix (high)

Issues that will cause incorrect behavior or crashes in production.

# File Line Category Summary
1 emitter.py 73 bug JsonlMetricEmitter.emit() missing None guard — crashes after close()
2 aggregator.py 155 concurrency Fire-and-forget ISL tasks crash on closed emitter; orphaned tasks never cancelled

🟡 Should Fix (medium)

Real issues under specific conditions or design flaws that will compound.

# File Line Category Summary
3 types.py 84 data-integrity TextModelOutput.__str__ leaks reasoning into OSL/TPOT metrics
4 test_aggregator.py 30 testing Missing mode="strict" on all async test markers (project convention)
5 pyproject.toml 55 design SQLAlchemy added as core dependency but only used by optional SQL writer
6 token_metrics.py 33 concurrency Thread-local tokenizer cache not keyed by name — wrong tokenizer if reused
7 context.py 82 api-contract Singleton ignores socket_dir on second init — silent misconfiguration
8 __main__.py 103 bug call_soon_threadsafe used from same thread — should be call_soon

🔵 Consider (low)

Valid improvements that could be follow-ups.

# File Line Category Summary
9 metrics_table.py 40 performance output_chunks list grows unboundedly per in-flight sample
10 types.py 84 bug Empty string reasoning silently dropped due to truthiness check

Each issue is posted as an inline comment on the relevant file and line.

🤖 Generated with Claude Code

@nv-alicheng nv-alicheng force-pushed the feat/alicheng-metrics-aggregator branch from 14fdfdc to 43a3769 Compare March 20, 2026 00:34
- MetricsAggregator: subscribes to ZMQ events, computes QPS/latency/TTFT/TPOT
- MetricsTable: columnar storage for efficient percentile calculations
- TokenMetrics: ISL/OSL token-level metrics from PromptData
- MetricsEmitter: periodic metric publishing
- Service entry point with CLI interface
- Comprehensive unit and e2e tests
@nv-alicheng nv-alicheng force-pushed the feat/alicheng-metrics-aggregator branch from 43a3769 to 1ce35f4 Compare March 24, 2026 01:20
@nv-alicheng nv-alicheng merged commit 08476d7 into main Mar 24, 2026
4 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants