diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index 763911363b..ad9108a6df 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -269,6 +269,7 @@ func (c *flagConfig) setFeatureListOptions(logger *slog.Logger) error { case "created-timestamp-zero-ingestion": // NOTE(bwplotka): Once AppendableV1 is removed, there will be only the TSDB and agent flags. c.scrape.EnableStartTimestampZeroIngestion = true + c.scrape.ParseST = true c.web.STZeroIngestionEnabled = true c.tsdb.EnableSTAsZeroSample = true c.agent.EnableSTAsZeroSample = true @@ -280,6 +281,7 @@ func (c *flagConfig) setFeatureListOptions(logger *slog.Logger) error { logger.Info("Experimental start timestamp zero ingestion enabled. Changed default scrape_protocols to prefer PrometheusProto format.", "global.scrape_protocols", fmt.Sprintf("%v", config.DefaultGlobalConfig.ScrapeProtocols)) case "st-storage": // TODO(bwplotka): Implement ST Storage as per PROM-60 and document this hidden feature flag. + c.scrape.ParseST = true c.tsdb.EnableSTStorage = true c.agent.EnableSTStorage = true diff --git a/scrape/manager.go b/scrape/manager.go index 24a63b056b..17f7b804a3 100644 --- a/scrape/manager.go +++ b/scrape/manager.go @@ -115,8 +115,19 @@ type Options struct { // Option to enable the ingestion of the created timestamp as a synthetic zero sample. // See: https://github.com/prometheus/proposals/blob/main/proposals/2023-06-13_created-timestamp.md + // + // NOTE: This option has no effect for AppenderV2 and will be removed with the AppenderV1 + // removal. EnableStartTimestampZeroIngestion bool + // ParseST controls if ST should be parsed and appended from the scrape format + // notably from the expensive OpenMetrics 1.0 _created line flow. This adds some + // overhead and can yield wrong ST values on OM1 edge cases. + // + // This only applies to AppenderV2 flow. + // TODO: Move this option to OM1 parser and use only on OM1 flow + ParseST bool + // EnableTypeAndUnitLabels represents type-and-unit-labels feature flag. EnableTypeAndUnitLabels bool diff --git a/scrape/manager_test.go b/scrape/manager_test.go index 395cc98a82..137596151b 100644 --- a/scrape/manager_test.go +++ b/scrape/manager_test.go @@ -767,6 +767,7 @@ func TestManagerSTZeroIngestion(t *testing.T) { app := teststorage.NewAppendable() discoveryManager, scrapeManager := runManagers(t, ctx, &Options{ EnableStartTimestampZeroIngestion: testSTZeroIngest, + ParseST: testSTZeroIngest, skipOffsetting: true, }, app, nil) defer scrapeManager.Stop() @@ -953,6 +954,7 @@ func TestManagerSTZeroIngestionHistogram(t *testing.T) { app := teststorage.NewAppendable() discoveryManager, scrapeManager := runManagers(t, ctx, &Options{ EnableStartTimestampZeroIngestion: tc.enableSTZeroIngestion, + ParseST: tc.enableSTZeroIngestion, skipOffsetting: true, }, app, nil) defer scrapeManager.Stop() @@ -1065,6 +1067,7 @@ func TestNHCBAndSTZeroIngestion(t *testing.T) { app := teststorage.NewAppendable() discoveryManager, scrapeManager := runManagers(t, ctx, &Options{ EnableStartTimestampZeroIngestion: true, + ParseST: true, skipOffsetting: true, }, app, nil) defer scrapeManager.Stop() diff --git a/scrape/scrape.go b/scrape/scrape.go index d5a9ba72b4..cd102a23ba 100644 --- a/scrape/scrape.go +++ b/scrape/scrape.go @@ -870,6 +870,7 @@ type scrapeLoop struct { // Options from scrape.Options. enableSTZeroIngestion bool + parseST bool // Used by AppenderV2 only. enableTypeAndUnitLabels bool reportExtraMetrics bool appendMetadataToWAL bool @@ -1223,7 +1224,12 @@ func newScrapeLoop(opts scrapeLoopOptions) *scrapeLoop { validationScheme: opts.sp.config.MetricNameValidationScheme, // scrape.Options. - enableSTZeroIngestion: opts.sp.options.EnableStartTimestampZeroIngestion, + enableSTZeroIngestion: opts.sp.options.EnableStartTimestampZeroIngestion, + // parseST was added recently. Before EnableStartTimestampZeroIngestion + // was enabling parsing ST. For non-Prometheus users of the scrape + // manager, we ensure appenderV2 parseST is set on EnableStartTimestampZeroIngestion + // This will be removed when EnableStartTimestampZeroIngestion is removed. + parseST: opts.sp.options.ParseST || opts.sp.options.EnableStartTimestampZeroIngestion, enableTypeAndUnitLabels: opts.sp.options.EnableTypeAndUnitLabels, appendMetadataToWAL: opts.sp.options.AppendMetadata, passMetadataInContext: opts.sp.options.PassMetadataInContext, diff --git a/scrape/scrape_append_v2.go b/scrape/scrape_append_v2.go index 64969707e1..825e56f9df 100644 --- a/scrape/scrape_append_v2.go +++ b/scrape/scrape_append_v2.go @@ -102,7 +102,7 @@ func (sl *scrapeLoopAppenderV2) append(b []byte, contentType string, ts time.Tim IgnoreNativeHistograms: !sl.enableNativeHistogramScraping, ConvertClassicHistogramsToNHCB: sl.convertClassicHistToNHCB, KeepClassicOnClassicAndNativeHistograms: sl.alwaysScrapeClassicHist, - OpenMetricsSkipSTSeries: sl.enableSTZeroIngestion, + OpenMetricsSkipSTSeries: sl.parseST, FallbackContentType: sl.fallbackScrapeProtocol, }) if p == nil { @@ -254,7 +254,7 @@ loop: } st := int64(0) - if sl.enableSTZeroIngestion { + if sl.parseST { // p.StartTimestamp() tend to be expensive (e.g. OM1). Do it only if we care. st = p.StartTimestamp() }