Skip to content

runtime: key counter rename rules by the parsed family name - #1703

Open
aeron-gh wants to merge 2 commits into
volcano-sh:mainfrom
aeron-gh:runtime/counter-rename-family
Open

runtime: key counter rename rules by the parsed family name#1703
aeron-gh wants to merge 2 commits into
volcano-sh:mainfrom
aeron-gh:runtime/counter-rename-family

Conversation

@aeron-gh

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

The runtime documents a standardized kthena:generation_tokens_total series, but it is never emitted for either engine. The rename rules are keyed by the raw counter name (vllm:generation_tokens_total, sglang:generation_tokens_total) while the lookup uses the PARSED family name, and the pinned parser (prometheus-client 0.19.0) munges counter families into their OpenMetrics form, stripping _total from the family name. The counter family therefore arrives named vllm:generation_tokens and the rule never matches. Gauge and histogram family names are untouched, which is why every other rename works and exactly this counter is missing.

The fix keys the two counter rules by the munged family name and renames to a kthena:generation_tokens family. RenameMetric already does per sample suffix arithmetic, so the exposed samples come out as kthena:generation_tokens_total exactly as documented (a _created sample would map the same way).

Which issue(s) this PR fixes:

Fixes #1652

Bug evidence (required for bug-related PRs):

The parser level and end to end reproduction are in #1652. The new tests are a flip proof on this branch:

with the tests added but the fix reverted:

FAILED tests/test_metrics.py::test_vllm_counter_rename_survives_parser_family_munging
FAILED tests/test_metrics.py::test_sglang_counter_rename_survives_parser_family_munging
FAILED tests/test_metrics.py::test_process_metrics_exposes_documented_counter_series
3 failed, 6 passed

The last failure shows the sidecar output containing only the original vllm:generation_tokens_total and no kthena: twin. With the fix, 9 passed, and the end to end test asserts the documented series in the actual process_metrics output:

kthena:generation_tokens_total{model_name="m"} 42.0

Production path: the rules are registered by family name at standard.py#L37-L64, the lookup is metric_operators_dict.get(origin_metric.name) at standard.py#L121, the parser is pinned at requirements.txt#L5, and the suffix arithmetic that restores _total on samples is metric.py#L77.

ruff check passes on both touched files. The full python suite passes apart from the six modules that import fcntl and cannot run on a Windows dev box; they are untouched by this change.

Special notes for your reviewer:

The exposed TYPE line becomes # TYPE kthena:generation_tokens counter with the kthena:generation_tokens_total sample, which is standard counter exposition and what any Prometheus client scrapes as kthena:generation_tokens_total. The docs page (runtime.md#L126) therefore stays accurate as written.

Does this PR introduce a user-facing change?:

Fixed the runtime sidecar so the documented kthena:generation_tokens_total standardized counter is actually emitted for vLLM and SGLang backends.

Signed-off-by: aeron-gh <agab0323@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread python/kthena/runtime/standard.py Outdated
Comment on lines +29 to +34
# The runtime's parser munges counter families into their OpenMetrics
# form: the FAMILY name loses the _total suffix while samples keep it.
# Rules are matched by family name, so the counter rule is keyed by the
# munged family and RenameMetric's suffix arithmetic restores _total on
# the exposed samples, yielding the documented
# kthena:generation_tokens_total series.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think it's necessary to write such complicated comments

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 remove these

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done!

@FAUST-BENCHOU FAUST-BENCHOU left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

others lg

Comment thread python/kthena/runtime/standard.py Outdated
Comment on lines +29 to +34
# The runtime's parser munges counter families into their OpenMetrics
# form: the FAMILY name loses the _total suffix while samples keep it.
# Rules are matched by family name, so the counter rule is keyed by the
# munged family and RenameMetric's suffix arithmetic restores _total on
# the exposed samples, yielding the documented
# kthena:generation_tokens_total series.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 remove these

Signed-off-by: aeron-gh <agab0323@gmail.com>
Copilot AI review requested due to automatic review settings August 27, 2026 06:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@aeron-gh

Copy link
Copy Markdown
Contributor Author

@FAUST-BENCHOU @kube-gopher
removed, thanks! i was worried the family name key would look like a typo to the next reader without some context, so i over explained a bit. the tests cover the why anywayy

@kube-gopher kube-gopher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm
/approve

@volcano-sh-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kube-gopher
Once this PR has been reviewed and has the lgtm label, please assign hzxuzhonghu for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Accepted

Development

Successfully merging this pull request may close these issues.

runtime: documented kthena:generation_tokens_total is never emitted, the counter rename rules cannot match

5 participants