Skip to content

fix: add created timestamps to protobuf histograms and summaries - #2709

Open
Tanishq-Choudhary wants to merge 1 commit into
prometheus:mainfrom
Tanishq-Choudhary:protobuf-histogram-summary-created
Open

Tanishq-Choudhary wants to merge 1 commit into
prometheus:mainfrom
Tanishq-Choudhary:protobuf-histogram-summary-created

Conversation

@Tanishq-Choudhary

Copy link
Copy Markdown
Contributor

The protobuf writer only sets created_timestamp on counters (#1532). Histogram and Summary record a created timestamp too, and the Histogram and Summary messages in metrics.proto both have a created_timestamp field, but PrometheusProtobufWriterImpl drops it. The OpenMetrics writer already exposes _created for both types.

Prometheus reads this field (called start_timestamp there now) for counters, summaries, histograms and gauge histograms (ProtobufParser.StartTimestamp() in model/textparse/protobufparse.go). So with created timestamp zero ingestion on, histogram and summary series from client_java never get the synthetic zero sample, while counters do. #1498 asked for the created timestamp in protobuf in general, and the answer there was that it can always be included for protobuf.

Repro on main:

Histogram h = Histogram.builder().name("test").build();
h.observe(0.5);
new PrometheusProtobufWriterImpl().convert(h.collect(), EscapingScheme.ALLOW_UTF8);
// histogram { sample_count: 1 sample_sum: 0.5 bucket ... } with no created_timestamp

Fix: set the field in the histogram and summary convert methods, the same way the counter one does. Gauge histograms get it too, which matches what the OpenMetrics writer does with _created.

Tests:

  • ExpositionFormatsTest: the protobuf expectations in testSummaryComplete, testClassicHistogramComplete, testClassicGaugeHistogramComplete and testNativeHistogramComplete now include created_timestamp. These four fail on main and pass with the fix.
  • HistogramTest: the client_golang test cases and testDefaults check that the created timestamp is there, then clear it before comparing, so the copied golden strings stay as they are.

Ran unit tests for config, model, exposition-textformats, exposition-formats, core, exporter-common, exporter-httpserver and simpleclient-bridge, plus google-java-format, checkstyle and the errorprone profile on the changed files. I didn't run the Docker integration tests; debug-protobuf.txt only has a counter, info and gauge, so it isn't affected.

The protobuf writer sets `created_timestamp` on counters only.
`Histogram` and `Summary` both record a created timestamp, and the
`io.prometheus.client.Histogram` and `Summary` messages both have a
`created_timestamp` field, but the writer drops it. The OpenMetrics
text writer already exposes `_created` for both types.

Prometheus reads this field for counters, summaries and histograms
(including gauge histograms) when created timestamp zero ingestion is
on, so histogram and summary series from client_java never got a
synthetic zero sample.

The writer now sets the field for histogram and summary data points
the same way it does for counters.

Signed-off-by: Tanishq Choudhary <tanishqchoudhary007@gmail.com>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant