Skip to content

Return the mutated entry from LabelMap.set and LabelMap.setDelta#748

Closed
krajorama wants to merge 1 commit into
prometheus:masterfrom
krajorama:labelmap-return-entry
Closed

Return the mutated entry from LabelMap.set and LabelMap.setDelta#748
krajorama wants to merge 1 commit into
prometheus:masterfrom
krajorama:labelmap-return-entry

Conversation

@krajorama

Copy link
Copy Markdown
Member

I'd like to contribute start timestamp (formerly known as created timestamp) support . For this I need to store the start time in the metric entry, but don't want to look the entry up again after adding to the LabelMap. Would be simpler to have set / setDelta return the entry so I can set the start timestamp. Would be used for counters and histograms. Eventually the start timestamp could be exposed on OpenMetrics 1.0 / 2.0.

Summary

  • LabelMap.set and LabelMap.setDelta now return the entry they created or updated, instead of this (the LabelMap).
  • Within this repo, no caller relied on the old this return (the only chained usages were in test/utilTest.js, now de-chained).
  • Added one return-value assertion per method.

API-surface note

LabelMap is an internal helper: it's not exported from index.js, not documented in the README, and entry()'s JSDoc explicitly says "Used internally by some Metrics. You should probably not call this directly." That said, lib/util.js ships in the published package, so a deep-import consumer could in principle have relied on the chaining return. I judge that risk low and reversible, but flagging it explicitly so you can decide.

Both methods previously returned `this` for chaining, but no production
caller relied on that — only a handful of tests did. Returning the
entry lets callers (Counter, Summary) attach per-entry metadata without
a second `entry(labels)` lookup, which doubles the keyFrom+Map.get
cost on every increment. Sets up follow-up work for per-series
created-timestamps.

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
@krajorama krajorama closed this by deleting the head repository Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant