From 6594bccfcc82037efafc4a8f6a88162f5918335a Mon Sep 17 00:00:00 2001 From: Arthur Silva Sens Date: Tue, 18 Feb 2025 11:09:26 -0300 Subject: [PATCH 1/3] Add fallback_scrape_protocol before config validation Signed-off-by: Arthur Silva Sens (cherry picked from commit 8cac6a9e13904b6dafb93eeb1c1d103c43dcf878) --- receiver/prometheusreceiver/config.go | 9 +++++++++ receiver/prometheusreceiver/factory.go | 9 --------- receiver/prometheusreceiver/factory_test.go | 19 ------------------- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/receiver/prometheusreceiver/config.go b/receiver/prometheusreceiver/config.go index 556dd42445187..11e5639419177 100644 --- a/receiver/prometheusreceiver/config.go +++ b/receiver/prometheusreceiver/config.go @@ -103,6 +103,15 @@ func (cfg *PromConfig) Validate() error { if err != nil { return err } + // Since Prometheus 3.0, the scrape manager started to fail scrapes that don't have proper + // Content-Type headers, but they provided an extra configuration option to fallback to the + // previous behavior. We need to make sure that this option is set for all scrape configs + // to avoid introducing a breaking change. + for _, sc := range scrapeConfigs { + if sc.ScrapeFallbackProtocol == "" { + sc.ScrapeFallbackProtocol = promconfig.PrometheusText0_0_4 + } + } for _, sc := range scrapeConfigs { if err := validateHTTPClientConfig(&sc.HTTPClientConfig); err != nil { diff --git a/receiver/prometheusreceiver/factory.go b/receiver/prometheusreceiver/factory.go index bbb82a9442e9e..247ffb428cddb 100644 --- a/receiver/prometheusreceiver/factory.go +++ b/receiver/prometheusreceiver/factory.go @@ -63,7 +63,6 @@ func createMetricsReceiver( nextConsumer consumer.Metrics, ) (receiver.Metrics, error) { configWarnings(set.Logger, cfg.(*Config)) - addDefaultFallbackScrapeProtocol(cfg.(*Config)) return newPrometheusReceiver(set, cfg.(*Config), nextConsumer), nil } @@ -76,11 +75,3 @@ func configWarnings(logger *zap.Logger, cfg *Config) { } } } - -func addDefaultFallbackScrapeProtocol(cfg *Config) { - for _, sc := range cfg.PrometheusConfig.ScrapeConfigs { - if sc.ScrapeFallbackProtocol == "" { - sc.ScrapeFallbackProtocol = promconfig.PrometheusText1_0_0 - } - } -} diff --git a/receiver/prometheusreceiver/factory_test.go b/receiver/prometheusreceiver/factory_test.go index 3a21e03375914..2fe0592f7d2d8 100644 --- a/receiver/prometheusreceiver/factory_test.go +++ b/receiver/prometheusreceiver/factory_test.go @@ -8,7 +8,6 @@ import ( "path/filepath" "testing" - promconfig "github.com/prometheus/prometheus/config" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" @@ -63,21 +62,3 @@ func TestMultipleCreate(t *testing.T) { require.NoError(t, secondRcvr.Start(context.Background(), host)) require.NoError(t, secondRcvr.Shutdown(context.Background())) } - -func TestDefaultFallbackScrapeProtocol(t *testing.T) { - cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config_fallback_scrape_protocol.yaml")) - require.NoError(t, err) - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - - sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) - require.NoError(t, err) - assert.NoError(t, sub.Unmarshal(cfg)) - - _, err = factory.CreateMetrics(context.Background(), receivertest.NewNopSettings(), cfg, consumertest.NewNop()) - require.NoError(t, err) - - // During receiver creation, scrapeconfig without fallback scrape protocol set, should be set to 'PrometheusText1.0.0'. - assert.Equal(t, promconfig.PrometheusText1_0_0, cfg.(*Config).PrometheusConfig.ScrapeConfigs[0].ScrapeFallbackProtocol) - assert.Equal(t, promconfig.OpenMetricsText1_0_0, cfg.(*Config).PrometheusConfig.ScrapeConfigs[1].ScrapeFallbackProtocol) -} From 332da6b95b087a52364999d99e08e0d01e0bbfce Mon Sep 17 00:00:00 2001 From: Arthur Silva Sens Date: Tue, 18 Feb 2025 11:17:55 -0300 Subject: [PATCH 2/3] Relax usage of fallback scrape protocol in tests Signed-off-by: Arthur Silva Sens (cherry picked from commit c404a8877d7ecf489c6db23723bdf4dd55b6d87e) --- exporter/datadogexporter/examples/collector-metrics.yaml | 1 - exporter/datadogexporter/examples/ootb-ec2.yaml | 1 - .../integration_test_internal_metrics_config.yaml | 1 - .../integrationtest/integration_test_logs_config.yaml | 1 - .../prometheusreceiver/internal/staleness_end_to_end_test.go | 1 - receiver/prometheusreceiver/metrics_receiver_labels_test.go | 2 -- .../prometheusreceiver/testdata/config_target_allocator.yaml | 2 -- .../testdata/invalid-config-prometheus-file-sd-config-json.yaml | 1 - .../testdata/invalid-config-prometheus-file-sd-config-yaml.yaml | 1 - .../invalid-config-prometheus-nonexistent-scrape-config.yaml | 1 - .../invalid-config-prometheus-unsupported-features.yaml | 1 - .../testdata/nonexistent-prometheus-sd-file-config.yaml | 1 - 12 files changed, 14 deletions(-) diff --git a/exporter/datadogexporter/examples/collector-metrics.yaml b/exporter/datadogexporter/examples/collector-metrics.yaml index c6ba8797ba171..4a68e51caa193 100644 --- a/exporter/datadogexporter/examples/collector-metrics.yaml +++ b/exporter/datadogexporter/examples/collector-metrics.yaml @@ -4,7 +4,6 @@ receivers: scrape_configs: - job_name: 'otelcol' scrape_interval: 10s - fallback_scrape_protocol: "PrometheusText1.0.0" static_configs: - targets: ['0.0.0.0:8888'] diff --git a/exporter/datadogexporter/examples/ootb-ec2.yaml b/exporter/datadogexporter/examples/ootb-ec2.yaml index ecac3621fd076..731060d5e4b6e 100644 --- a/exporter/datadogexporter/examples/ootb-ec2.yaml +++ b/exporter/datadogexporter/examples/ootb-ec2.yaml @@ -39,7 +39,6 @@ receivers: scrape_configs: - job_name: 'otelcol' scrape_interval: 10s - fallback_scrape_protocol: "PrometheusText1.0.0" static_configs: - targets: ['0.0.0.0:8888'] diff --git a/exporter/datadogexporter/integrationtest/integration_test_internal_metrics_config.yaml b/exporter/datadogexporter/integrationtest/integration_test_internal_metrics_config.yaml index 6a3bb12477972..1d1e6762b998b 100644 --- a/exporter/datadogexporter/integrationtest/integration_test_internal_metrics_config.yaml +++ b/exporter/datadogexporter/integrationtest/integration_test_internal_metrics_config.yaml @@ -11,7 +11,6 @@ receivers: scrape_configs: - job_name: 'otelcol' scrape_interval: 1s - fallback_scrape_protocol: "PrometheusText1.0.0" static_configs: - targets: [ '${env:PROM_SERVER}' ] diff --git a/exporter/datadogexporter/integrationtest/integration_test_logs_config.yaml b/exporter/datadogexporter/integrationtest/integration_test_logs_config.yaml index 008258e9acea7..ae2af23589678 100644 --- a/exporter/datadogexporter/integrationtest/integration_test_logs_config.yaml +++ b/exporter/datadogexporter/integrationtest/integration_test_logs_config.yaml @@ -11,7 +11,6 @@ receivers: scrape_configs: - job_name: 'otelcol' scrape_interval: 1s - fallback_scrape_protocol: "PrometheusText1.0.0" static_configs: - targets: [ '${env:PROM_SERVER}' ] metric_relabel_configs: diff --git a/receiver/prometheusreceiver/internal/staleness_end_to_end_test.go b/receiver/prometheusreceiver/internal/staleness_end_to_end_test.go index b630ce8ac8cec..4cb899295c356 100644 --- a/receiver/prometheusreceiver/internal/staleness_end_to_end_test.go +++ b/receiver/prometheusreceiver/internal/staleness_end_to_end_test.go @@ -109,7 +109,6 @@ receivers: scrape_configs: - job_name: 'test' scrape_interval: 100ms - fallback_scrape_protocol: "PrometheusText1.0.0" static_configs: - targets: [%q] diff --git a/receiver/prometheusreceiver/metrics_receiver_labels_test.go b/receiver/prometheusreceiver/metrics_receiver_labels_test.go index e20846802646a..0afff6a7417de 100644 --- a/receiver/prometheusreceiver/metrics_receiver_labels_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_labels_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/prometheus/common/model" - promconfig "github.com/prometheus/prometheus/config" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/relabel" "github.com/stretchr/testify/require" @@ -258,7 +257,6 @@ func TestLabelNameLimitConfig(t *testing.T) { testComponent(t, targets, nil, func(cfg *PromConfig) { // set label limit in scrape_config for _, scrapeCfg := range cfg.ScrapeConfigs { - scrapeCfg.ScrapeFallbackProtocol = promconfig.PrometheusText1_0_0 scrapeCfg.LabelNameLengthLimit = 20 } }) diff --git a/receiver/prometheusreceiver/testdata/config_target_allocator.yaml b/receiver/prometheusreceiver/testdata/config_target_allocator.yaml index e59b4c16f9b9b..9c708ed58de5b 100644 --- a/receiver/prometheusreceiver/testdata/config_target_allocator.yaml +++ b/receiver/prometheusreceiver/testdata/config_target_allocator.yaml @@ -15,10 +15,8 @@ prometheus/withScrape: scrape_configs: - job_name: 'demo' scrape_interval: 5s - fallback_scrape_protocol: "PrometheusText1.0.0" prometheus/withOnlyScrape: config: scrape_configs: - job_name: 'demo' scrape_interval: 5s - fallback_scrape_protocol: "PrometheusText1.0.0" diff --git a/receiver/prometheusreceiver/testdata/invalid-config-prometheus-file-sd-config-json.yaml b/receiver/prometheusreceiver/testdata/invalid-config-prometheus-file-sd-config-json.yaml index 32fe068b9a983..d33312ab453a8 100644 --- a/receiver/prometheusreceiver/testdata/invalid-config-prometheus-file-sd-config-json.yaml +++ b/receiver/prometheusreceiver/testdata/invalid-config-prometheus-file-sd-config-json.yaml @@ -3,6 +3,5 @@ prometheus: scrape_configs: - job_name: 'demo' scrape_interval: 5s - fallback_scrape_protocol: "PrometheusText1.0.0" file_sd_configs: - files: ["./testdata/sd-config-with-null-target-group.json"] diff --git a/receiver/prometheusreceiver/testdata/invalid-config-prometheus-file-sd-config-yaml.yaml b/receiver/prometheusreceiver/testdata/invalid-config-prometheus-file-sd-config-yaml.yaml index 6f2af0f951d65..f101bdb6265fc 100644 --- a/receiver/prometheusreceiver/testdata/invalid-config-prometheus-file-sd-config-yaml.yaml +++ b/receiver/prometheusreceiver/testdata/invalid-config-prometheus-file-sd-config-yaml.yaml @@ -3,6 +3,5 @@ prometheus: scrape_configs: - job_name: 'demo' scrape_interval: 5s - fallback_scrape_protocol: "PrometheusText1.0.0" file_sd_configs: - files: ["./testdata/sd-config-with-null-target-group.yaml"] diff --git a/receiver/prometheusreceiver/testdata/invalid-config-prometheus-nonexistent-scrape-config.yaml b/receiver/prometheusreceiver/testdata/invalid-config-prometheus-nonexistent-scrape-config.yaml index 4a57b8452add7..a3a09838b45ce 100644 --- a/receiver/prometheusreceiver/testdata/invalid-config-prometheus-nonexistent-scrape-config.yaml +++ b/receiver/prometheusreceiver/testdata/invalid-config-prometheus-nonexistent-scrape-config.yaml @@ -17,4 +17,3 @@ prometheus/withOnlyScrape: scrape_configs: - job_name: 'demo' scrape_interval: 5s - fallback_scrape_protocol: "PrometheusText1.0.0" diff --git a/receiver/prometheusreceiver/testdata/invalid-config-prometheus-unsupported-features.yaml b/receiver/prometheusreceiver/testdata/invalid-config-prometheus-unsupported-features.yaml index 4761aaf8d1305..4ed0892f10b2c 100644 --- a/receiver/prometheusreceiver/testdata/invalid-config-prometheus-unsupported-features.yaml +++ b/receiver/prometheusreceiver/testdata/invalid-config-prometheus-unsupported-features.yaml @@ -5,7 +5,6 @@ prometheus: scrape_configs: - job_name: 'demo' scrape_interval: 5s - fallback_scrape_protocol: "PrometheusText1.0.0" remote_write: - url: "https://example.org/write" diff --git a/receiver/prometheusreceiver/testdata/nonexistent-prometheus-sd-file-config.yaml b/receiver/prometheusreceiver/testdata/nonexistent-prometheus-sd-file-config.yaml index 1088c876b6283..816a1d6113b30 100644 --- a/receiver/prometheusreceiver/testdata/nonexistent-prometheus-sd-file-config.yaml +++ b/receiver/prometheusreceiver/testdata/nonexistent-prometheus-sd-file-config.yaml @@ -3,6 +3,5 @@ prometheus: scrape_configs: - job_name: 'test' scrape_interval: 5s - fallback_scrape_protocol: "PrometheusText1.0.0" file_sd_configs: - files: ["./testdata/nonexistent-sd-file.json"] From a1997036c8ea7343cd6f2e6f62e8f999d9629622 Mon Sep 17 00:00:00 2001 From: Arthur Silva Sens Date: Tue, 18 Feb 2025 12:55:50 -0300 Subject: [PATCH 3/3] Changelog Signed-off-by: Arthur Silva Sens (cherry picked from commit 6f00b3878fa0e11e4d87b85974943655f2635748) --- .chloggen/prom-scrape-config-protocol.yaml | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .chloggen/prom-scrape-config-protocol.yaml diff --git a/.chloggen/prom-scrape-config-protocol.yaml b/.chloggen/prom-scrape-config-protocol.yaml new file mode 100644 index 0000000000000..951be0e0e5473 --- /dev/null +++ b/.chloggen/prom-scrape-config-protocol.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: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: receiver/prometheus + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix Collector failing to start up if Prometheus receiver is present in config without 'fallback_scrape_protocol'. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [38018] + +# (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: + +# 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]