@@ -207,7 +207,13 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO
207
207
if encodingHeader != string (Identity ) {
208
208
rsp .Header ().Set (contentEncodingHeader , encodingHeader )
209
209
}
210
- enc := expfmt .NewEncoder (w , contentType )
210
+
211
+ var enc expfmt.Encoder
212
+ if opts .EnableOpenMetricsTextCreatedSamples {
213
+ enc = expfmt .NewEncoder (w , contentType , expfmt .WithCreatedLines ())
214
+ } else {
215
+ enc = expfmt .NewEncoder (w , contentType )
216
+ }
211
217
212
218
// handleError handles the error according to opts.ErrorHandling
213
219
// and returns true if we have to abort after the handling.
@@ -408,6 +414,21 @@ type HandlerOpts struct {
408
414
// (which changes the identity of the resulting series on the Prometheus
409
415
// server).
410
416
EnableOpenMetrics bool
417
+ // EnableOpenMetricsTextCreatedSamples specifies if this handler should add, extra, synthetic
418
+ // Created Timestamps for counters, histograms and summaries, which for the current
419
+ // version of OpenMetrics are defined as extra series with the same name and "_created"
420
+ // suffix. See also the OpenMetrics specification for more details
421
+ // https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#counter-1
422
+ //
423
+ // Created timestamps are used to improve the accuracy of reset detection,
424
+ // but the way it's designed in OpenMetrics 1.0 it also dramatically increases cardinality
425
+ // if the scraper does not handle those metrics correctly (converting to created timestamp
426
+ // instead of leaving those series as-is). New OpenMetrics versions might improve
427
+ // this situation.
428
+ //
429
+ // Prometheus introduced the feature flag 'created-timestamp-zero-ingestion'
430
+ // in version 2.50.0 to handle this situation.
431
+ EnableOpenMetricsTextCreatedSamples bool
411
432
// ProcessStartTime allows setting process start timevalue that will be exposed
412
433
// with "Process-Start-Time-Unix" response header along with the metrics
413
434
// payload. This allow callers to have efficient transformations to cumulative
0 commit comments