Repository navigation
fix: add scrape timestamps to protobuf untyped metrics - #2718
Open
Tanishq-Choudhary wants to merge 1 commit into
Open
Tanishq-Choudhary wants to merge 1 commit into
Tanishq-Choudhary wants to merge 1 commit into
Conversation
The protobuf writer sets `timestamp_ms` from the scrape timestamp for every data point type except unknown. An `UnknownDataPointSnapshot` with a scrape timestamp is written without it, while the Prometheus text and both OpenMetrics text writers include it. Prometheus reads `timestamp_ms` for untyped samples the same way it does for counters and gauges, so untyped series scraped over protobuf lost their explicit timestamps. One path that sets them is the simpleclient bridge, which copies `Sample.timestampMs` onto unknown data points. The writer now calls `setScrapeTimestamp` for unknown data points like it does for all other types. Signed-off-by: Tanishq Choudhary <tanishqchoudhary007@gmail.com>
Tanishq-Choudhary
requested review from
dhoard,
fstab,
jaydeluca and
zeitlinger
as code owners
November 21, 2026 19:03
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The protobuf writer sets
timestamp_msfrom the scrape timestamp for every data point type except unknown.convert(UnknownDataPointSnapshot ...)inPrometheusProtobufWriterImplnever callssetScrapeTimestamp, so an unknown data point with a scrape timestamp loses it. The Prometheus text, OpenMetrics and OpenMetrics 2 writers all write it.Prometheus reads
timestamp_msfor untyped samples the same way as for counters and gauges (ProtobufParser.Series()inmodel/textparse/protobufparse.go). So untyped series scraped over protobuf get the scrape time instead of their own timestamp. One path that hits this is the simpleclient bridge:convertUnknowncopiesSample.timestampMsonto the data point.Repro on main:
Fix: call
setScrapeTimestampin the unknownconvertmethod like the other types do.Test:
testUnknownCompleteinExpositionFormatsTestnow has a protobuf expectation withtimestamp_ms, liketestGaugeComplete. It fails on main and passes with the fix.testUnknownWithDotsalready checks that notimestamp_msis written when there's no scrape timestamp, and still passes.Ran unit tests for config, model, exposition-textformats and exposition-formats, plus google-java-format, checkstyle and the errorprone profile on the changed files.