From 620b4b81169af8a9d0c5a957456ab5572dc3f290 Mon Sep 17 00:00:00 2001 From: Zymantas Maumevicius Date: Tue, 25 Nov 2025 23:07:35 +0200 Subject: [PATCH 1/6] [reveicer/prometheusreceiver] Add feature gate for extra scrape metrics in Prometheus receiver --- ...ceiver-featuregate-extrascrapemetrics.yaml | 27 +++++++++++++++++++ receiver/prometheusreceiver/config.go | 1 + receiver/prometheusreceiver/factory.go | 7 +++++ .../prometheusreceiver/metrics_receiver.go | 2 +- ...ceiver_report_extra_scrape_metrics_test.go | 13 ++++++--- 5 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 .chloggen/feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml diff --git a/.chloggen/feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml b/.chloggen/feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml new file mode 100644 index 0000000000000..aaa085e655b84 --- /dev/null +++ b/.chloggen/feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: deprecation + +# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog) +component: reveicer/prometheusreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add feature gate for extra scrape metrics in Prometheus receiver + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [ 44181 ] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: deprecation of extra scrape metrics in Prometheus receiver will be removed in the next major release. + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [ user ] diff --git a/receiver/prometheusreceiver/config.go b/receiver/prometheusreceiver/config.go index efc6aee51cf3b..ceee68658a52f 100644 --- a/receiver/prometheusreceiver/config.go +++ b/receiver/prometheusreceiver/config.go @@ -39,6 +39,7 @@ type Config struct { StartTimeMetricRegex string `mapstructure:"start_time_metric_regex"` // ReportExtraScrapeMetrics - enables reporting of additional metrics for Prometheus client like scrape_body_size_bytes + // Deprecated: use the feature gate "receiver.prometheusreceiver.EnableReportExtraScrapeMetrics" instead. ReportExtraScrapeMetrics bool `mapstructure:"report_extra_scrape_metrics"` TargetAllocator configoptional.Optional[targetallocator.Config] `mapstructure:"target_allocator"` diff --git a/receiver/prometheusreceiver/factory.go b/receiver/prometheusreceiver/factory.go index 20c8064f92f1e..4af7b29e1bae1 100644 --- a/receiver/prometheusreceiver/factory.go +++ b/receiver/prometheusreceiver/factory.go @@ -40,6 +40,13 @@ var enableCreatedTimestampZeroIngestionGate = featuregate.GlobalRegistry().MustR " Created timestamps are injected as 0 valued samples when appropriate."), ) +var enableReportExtraScrapeMetricsGate = featuregate.GlobalRegistry().MustRegister( + "receiver.prometheusreceiver.EnableReportExtraScrapeMetrics", + featuregate.StageAlpha, + featuregate.WithRegisterDescription("Enables reporting of extra scrape metrics."+ + " Extra scrape metrics are metrics that are not scraped by Prometheus but are reported by the Prometheus server."), +) + // NewFactory creates a new Prometheus receiver factory. func NewFactory() receiver.Factory { return receiver.NewFactory( diff --git a/receiver/prometheusreceiver/metrics_receiver.go b/receiver/prometheusreceiver/metrics_receiver.go index 5ba159363a89c..8d8bd532bd957 100644 --- a/receiver/prometheusreceiver/metrics_receiver.go +++ b/receiver/prometheusreceiver/metrics_receiver.go @@ -227,7 +227,7 @@ func (r *pReceiver) initPrometheusComponents(ctx context.Context, logger *slog.L func (r *pReceiver) initScrapeOptions() *scrape.Options { opts := &scrape.Options{ PassMetadataInContext: true, - ExtraMetrics: r.cfg.ReportExtraScrapeMetrics, + ExtraMetrics: enableReportExtraScrapeMetricsGate.IsEnabled() || r.cfg.ReportExtraScrapeMetrics, HTTPClientOptions: []commonconfig.HTTPClientOption{ commonconfig.WithUserAgent(r.settings.BuildInfo.Command + "/" + r.settings.BuildInfo.Version), }, diff --git a/receiver/prometheusreceiver/metrics_receiver_report_extra_scrape_metrics_test.go b/receiver/prometheusreceiver/metrics_receiver_report_extra_scrape_metrics_test.go index fa3c77944fbd6..c398f3839cc6d 100644 --- a/receiver/prometheusreceiver/metrics_receiver_report_extra_scrape_metrics_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_report_extra_scrape_metrics_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/consumer/consumertest" + "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/receiver/receivertest" @@ -53,12 +54,14 @@ func testScraperMetrics(t *testing.T, targets []*testData, reportExtraScrapeMetr require.NoErrorf(t, err, "Failed to create Prometheus config: %v", err) defer mp.Close() + err = featuregate.GlobalRegistry().Set("receiver.prometheusreceiver.EnableReportExtraScrapeMetrics", reportExtraScrapeMetrics) + require.NoError(t, err) + cms := new(consumertest.MetricsSink) receiver, err := newPrometheusReceiver(receivertest.NewNopSettings(metadata.Type), &Config{ - PrometheusConfig: cfg, - UseStartTimeMetric: false, - StartTimeMetricRegex: "", - ReportExtraScrapeMetrics: reportExtraScrapeMetrics, + PrometheusConfig: cfg, + UseStartTimeMetric: false, + StartTimeMetricRegex: "", }, cms) require.NoError(t, err, "Failed to create Prometheus receiver: %v", err) @@ -69,6 +72,8 @@ func testScraperMetrics(t *testing.T, targets []*testData, reportExtraScrapeMetr assert.Lenf(t, flattenTargets(receiver.scrapeManager.TargetsAll()), len(targets), "expected %v targets to be running", len(targets)) require.NoError(t, receiver.Shutdown(t.Context())) assert.Empty(t, flattenTargets(receiver.scrapeManager.TargetsAll()), "expected scrape manager to have no targets") + err := featuregate.GlobalRegistry().Set("receiver.prometheusreceiver.EnableReportExtraScrapeMetrics", false) + require.NoError(t, err) }) // waitgroup Wait() is strictly from a server POV indicating the sufficient number and type of requests have been seen From ae32beda40f4e38529c165e253b342d24d501fda Mon Sep 17 00:00:00 2001 From: Zymantas Maumevicius Date: Wed, 26 Nov 2025 13:12:20 +0200 Subject: [PATCH 2/6] Update feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml --- .../feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml b/.chloggen/feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml index aaa085e655b84..e209b26f4eea9 100644 --- a/.chloggen/feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml +++ b/.chloggen/feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml @@ -4,7 +4,7 @@ change_type: deprecation # The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog) -component: reveicer/prometheusreceiver +component: reveicer/prometheus # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). note: Add feature gate for extra scrape metrics in Prometheus receiver From 7b661af7133fa9e09d3f51ee975f0a918ed59849 Mon Sep 17 00:00:00 2001 From: Zymantas Maumevicius Date: Wed, 26 Nov 2025 15:41:18 +0200 Subject: [PATCH 3/6] Update feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml --- .../feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml b/.chloggen/feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml index e209b26f4eea9..126dbd5f095cc 100644 --- a/.chloggen/feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml +++ b/.chloggen/feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml @@ -4,7 +4,7 @@ change_type: deprecation # The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog) -component: reveicer/prometheus +component: receiver/prometheus # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). note: Add feature gate for extra scrape metrics in Prometheus receiver From cda30b5ef7293023e375ebd52fac3b34863c497c Mon Sep 17 00:00:00 2001 From: Zymantas Maumevicius Date: Wed, 26 Nov 2025 16:09:25 +0200 Subject: [PATCH 4/6] Update receiver/prometheusreceiver/config.go Co-authored-by: Arthur Silva Sens --- receiver/prometheusreceiver/config.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/receiver/prometheusreceiver/config.go b/receiver/prometheusreceiver/config.go index ceee68658a52f..8f1decdb663dc 100644 --- a/receiver/prometheusreceiver/config.go +++ b/receiver/prometheusreceiver/config.go @@ -38,7 +38,8 @@ type Config struct { UseStartTimeMetric bool `mapstructure:"use_start_time_metric"` StartTimeMetricRegex string `mapstructure:"start_time_metric_regex"` - // ReportExtraScrapeMetrics - enables reporting of additional metrics for Prometheus client like scrape_body_size_bytes +// ReportExtraScrapeMetrics - enables reporting of additional metrics for Prometheus client like scrape_body_size_bytes + // // Deprecated: use the feature gate "receiver.prometheusreceiver.EnableReportExtraScrapeMetrics" instead. ReportExtraScrapeMetrics bool `mapstructure:"report_extra_scrape_metrics"` From 2ad3100ebe50ec1f6e0f53f35a692c762175dd2f Mon Sep 17 00:00:00 2001 From: Zymantas Maumevicius Date: Wed, 26 Nov 2025 22:22:40 +0200 Subject: [PATCH 5/6] [receiver/prometheusreceiver] Add support for `EnableReportExtraScrapeMetrics` feature gate in Prometheus receiver --- ...rometheusreceiver-featuregate-extrascrapemetrics.yaml | 2 +- receiver/prometheusreceiver/README.md | 7 +++++++ receiver/prometheusreceiver/config.go | 4 ++-- .../metrics_receiver_report_extra_scrape_metrics_test.go | 9 +++------ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.chloggen/feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml b/.chloggen/feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml index 126dbd5f095cc..3bb91b66e3b2a 100644 --- a/.chloggen/feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml +++ b/.chloggen/feat_prometheusreceiver-featuregate-extrascrapemetrics.yaml @@ -15,7 +15,7 @@ issues: [ 44181 ] # (Optional) One or more lines of additional information to render under the primary note. # These lines will be padded with 2 spaces and then inserted directly into the document. # Use pipe (|) for multiline entries. -subtext: deprecation of extra scrape metrics in Prometheus receiver will be removed in the next major release. +subtext: deprecation of extra scrape metrics in Prometheus receiver will be removed eventually. # If your change doesn't affect end users or the exported elements of any package, # you should instead start your pull request title with [chore] or use the "Skip Changelog" label. diff --git a/receiver/prometheusreceiver/README.md b/receiver/prometheusreceiver/README.md index c6f8385d99f34..0e820a6cb6d53 100644 --- a/receiver/prometheusreceiver/README.md +++ b/receiver/prometheusreceiver/README.md @@ -182,6 +182,13 @@ More info about querying `/api/v1/` and the data format that is returned can be ## Feature gates +- `receiver.prometheusreceiver.EnableReportExtraScrapeMetrics`: Extra Prometheus scrape metrics + can be reported by setting this feature gate option: + +```shell +"--feature-gates=receiver.prometheusreceiver.EnableReportExtraScrapeMetrics" +``` + - `receiver.prometheusreceiver.UseCreatedMetric`: Start time for Summary, Histogram and Sum metrics can be retrieved from `_created` metrics. Currently, this behaviour is disabled by default. To enable it, use the following feature gate option: diff --git a/receiver/prometheusreceiver/config.go b/receiver/prometheusreceiver/config.go index 8f1decdb663dc..84305a9969ed1 100644 --- a/receiver/prometheusreceiver/config.go +++ b/receiver/prometheusreceiver/config.go @@ -38,8 +38,8 @@ type Config struct { UseStartTimeMetric bool `mapstructure:"use_start_time_metric"` StartTimeMetricRegex string `mapstructure:"start_time_metric_regex"` -// ReportExtraScrapeMetrics - enables reporting of additional metrics for Prometheus client like scrape_body_size_bytes - // + // ReportExtraScrapeMetrics - enables reporting of additional metrics for Prometheus client like scrape_body_size_bytes + // // Deprecated: use the feature gate "receiver.prometheusreceiver.EnableReportExtraScrapeMetrics" instead. ReportExtraScrapeMetrics bool `mapstructure:"report_extra_scrape_metrics"` diff --git a/receiver/prometheusreceiver/metrics_receiver_report_extra_scrape_metrics_test.go b/receiver/prometheusreceiver/metrics_receiver_report_extra_scrape_metrics_test.go index c398f3839cc6d..5da14dc2f60b9 100644 --- a/receiver/prometheusreceiver/metrics_receiver_report_extra_scrape_metrics_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_report_extra_scrape_metrics_test.go @@ -10,10 +10,10 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/consumer/consumertest" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/receiver/receivertest" + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver/internal/metadata" ) @@ -49,14 +49,13 @@ func TestReportExtraScrapeMetrics(t *testing.T) { // starts prometheus receiver with custom config, retrieves metrics from MetricsSink func testScraperMetrics(t *testing.T, targets []*testData, reportExtraScrapeMetrics bool) { + defer testutil.SetFeatureGateForTest(t, enableReportExtraScrapeMetricsGate, reportExtraScrapeMetrics)() + ctx := t.Context() mp, cfg, err := setupMockPrometheus(targets...) require.NoErrorf(t, err, "Failed to create Prometheus config: %v", err) defer mp.Close() - err = featuregate.GlobalRegistry().Set("receiver.prometheusreceiver.EnableReportExtraScrapeMetrics", reportExtraScrapeMetrics) - require.NoError(t, err) - cms := new(consumertest.MetricsSink) receiver, err := newPrometheusReceiver(receivertest.NewNopSettings(metadata.Type), &Config{ PrometheusConfig: cfg, @@ -72,8 +71,6 @@ func testScraperMetrics(t *testing.T, targets []*testData, reportExtraScrapeMetr assert.Lenf(t, flattenTargets(receiver.scrapeManager.TargetsAll()), len(targets), "expected %v targets to be running", len(targets)) require.NoError(t, receiver.Shutdown(t.Context())) assert.Empty(t, flattenTargets(receiver.scrapeManager.TargetsAll()), "expected scrape manager to have no targets") - err := featuregate.GlobalRegistry().Set("receiver.prometheusreceiver.EnableReportExtraScrapeMetrics", false) - require.NoError(t, err) }) // waitgroup Wait() is strictly from a server POV indicating the sufficient number and type of requests have been seen From 722be8a0373c940164b8c723a34968a18466e657 Mon Sep 17 00:00:00 2001 From: Zymantas Maumevicius Date: Thu, 27 Nov 2025 22:54:33 +0200 Subject: [PATCH 6/6] [receiver/prometheusreceiver] Deprecate `report_extra_scrape_metrics` in favor of `EnableReportExtraScrapeMetrics` feature gate --- receiver/prometheusreceiver/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/receiver/prometheusreceiver/README.md b/receiver/prometheusreceiver/README.md index 0e820a6cb6d53..f8238507ab247 100644 --- a/receiver/prometheusreceiver/README.md +++ b/receiver/prometheusreceiver/README.md @@ -88,7 +88,7 @@ The prometheus receiver also supports additional top-level options: - **trim_metric_suffixes**: [**Experimental**] When set to true, this enables trimming unit and some counter type suffixes from metric names. For example, it would cause `singing_duration_seconds_total` to be trimmed to `singing_duration`. This can be useful when trying to restore the original metric names used in OpenTelemetry instrumentation. Defaults to false. - **use_start_time_metric**: When set to true, this enables retrieving the start time of all counter metrics from the process_start_time_seconds metric. This is only correct if all counters on that endpoint started after the process start time, and the process is the only actor exporting the metric after the process started. It should not be used in "exporters" which export counters that may have started before the process itself. Use only if you know what you are doing, as this may result in incorrect rate calculations. Defaults to false. - **start_time_metric_regex**: The regular expression for the start time metric, and is only applied when use_start_time_metric is enabled. Defaults to process_start_time_seconds. -- **report_extra_scrape_metrics**: Extra Prometheus scrape metrics can be reported by setting this parameter to `true` +- **report_extra_scrape_metrics**: Extra Prometheus scrape metrics can be reported by setting this parameter to `true`. Deprecated; use the feature gate `receiver.prometheusreceiver.EnableReportExtraScrapeMetrics` instead. Example configuration: @@ -97,7 +97,6 @@ receivers: prometheus: trim_metric_suffixes: true use_start_time_metric: true - report_extra_scrape_metrics: true start_time_metric_regex: foo_bar_.* config: scrape_configs: @@ -183,7 +182,8 @@ More info about querying `/api/v1/` and the data format that is returned can be ## Feature gates - `receiver.prometheusreceiver.EnableReportExtraScrapeMetrics`: Extra Prometheus scrape metrics - can be reported by setting this feature gate option: + can be reported by setting this feature gate option. This replaces the deprecated + `report_extra_scrape_metrics` configuration flag: ```shell "--feature-gates=receiver.prometheusreceiver.EnableReportExtraScrapeMetrics"