Skip to content

[k2] use metrics descriptor API - #1702

Open
Shamzik wants to merge 7 commits into
masterfrom
kshamazov/k2-metrics-descriptor-api
Open

Shamzik wants to merge 7 commits into
masterfrom
kshamazov/k2-metrics-descriptor-api

Conversation

@Shamzik

@Shamzik Shamzik commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@Shamzik Shamzik added runtime Feature related to runtime k2 Affects compiler or runtime in K2 mode labels Oct 7, 2026
@Shamzik Shamzik self-assigned this Oct 7, 2026
@Shamzik Shamzik added this to the next milestone Oct 7, 2026
The metric families and their bound series move from InstanceState to
ComponentState: the metrics are component-scoped, every instance writes
the same pre-bound series. Instances keep only the counters they flush
into those series, and registration no longer repeats on every instance
start. k2-header.h is synced with the component-scoped contract.
The metrics API is available from k2_create_component onwards; calls
from image-level entry points fail with EINVAL.
K2StringView/K2LabelPair become MetricLabelName/MetricLabelValue/
MetricLabel: a dedicated struct per role instead of one generic byte
string, and "name" instead of "key" to match the monitoring system
terminology. The k2-api wrappers and the diagnostics helpers follow;
the contract doc block is updated to the new names and stays in sync
with the k2-node header.
@Shamzik
Shamzik requested review from PetrShumilov, apolyakov and denisichh and removed request for denisichh October 13, 2026 14:14
Comment thread runtime-light/k2-platform/k2-header.h Outdated
* cases where the set of series is not known in advance.
*
* Contract (shared by all kinds):
* - the metrics API is available from `k2_create_component` onwards;

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.

The documentation is a bit misleading when it describes metrics lifecycle:

  • a component registers each metric once (at initialization) and the metrics API is available from k2_create_component onwards. It looks like we allow metrics to be registered during instance init, for example

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.

Fixed

Comment thread runtime-light/k2-platform/k2-header.h Outdated
* `k2_create_image`/`k2_init_image`) fail with `EINVAL`;
* - buckets are explicit upper boundaries; `buckets_size == 0`
* registers a histogram with a default bucket layout;
* - descriptors are valid until the component exits; there is no

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.

What do you mean by saying until the component exits?

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.

until ending of component's lifetime. Fixed description

Comment thread runtime-light/k2-platform/k2-header.h Outdated
* - a kind mismatch (e.g. `k2_metrics_gauge_set` on a counter series)
* is rejected with `EINVAL`, as is an unknown descriptor.
*
* @param `md`/`sd` Out-pointers receiving the descriptor (0 on failure).

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.

They are not pointers only

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.

Added details

Sync with the vkrs descriptor-api review fixes: registration is
possible anywhere from k2_create_component onwards (not only at
component initialization); descriptors are valid for the component's
whole lifetime; md/sd are out-pointers only in the registration and
bind functions, input values elsewhere.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Comment thread runtime-light/stdlib/diagnostics/metrics.h
Comment thread runtime-light/stdlib/diagnostics/metrics.h Outdated

This branch has not been deployed

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

Labels

k2 Affects compiler or runtime in K2 mode runtime Feature related to runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants