Skip to content

Commit 72b834b

Browse files
committed
[receiver/prometheus] Add fallback_scrape_protocol during config validation (open-telemetry#38018)
During the release process, we noticed a breaking change in the Prometheus receiver caused by open-telemetry#36873. In that PR, I tried adding a fallback scrape protocol by default everytime the PrometheusReceiver was built, but it turned out that config validation happened even before the component was created. And the collector fails startup with invalid configuration This PR moves the addition of scrape protocol to the validation step. <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> Fixes open-telemetry#37902 <!--Describe what testing was performed and which tests were added.--> <!--Describe the documentation added.--> <!--Please delete paragraphs that you did not use before submitting.-->
1 parent 406aeab commit 72b834b

16 files changed

+36
-42
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: receiver/prometheus
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fix Collector failing to start up if Prometheus receiver is present in config without 'fallback_scrape_protocol'.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [38018]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

exporter/datadogexporter/examples/collector-metrics.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ receivers:
44
scrape_configs:
55
- job_name: 'otelcol'
66
scrape_interval: 10s
7-
fallback_scrape_protocol: "PrometheusText1.0.0"
87
static_configs:
98
- targets: ['0.0.0.0:8888']
109

exporter/datadogexporter/examples/ootb-ec2.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ receivers:
3939
scrape_configs:
4040
- job_name: 'otelcol'
4141
scrape_interval: 10s
42-
fallback_scrape_protocol: "PrometheusText1.0.0"
4342
static_configs:
4443
- targets: ['0.0.0.0:8888']
4544

exporter/datadogexporter/integrationtest/integration_test_internal_metrics_config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ receivers:
1111
scrape_configs:
1212
- job_name: 'otelcol'
1313
scrape_interval: 1s
14-
fallback_scrape_protocol: "PrometheusText1.0.0"
1514
static_configs:
1615
- targets: [ '${env:PROM_SERVER}' ]
1716

exporter/datadogexporter/integrationtest/integration_test_logs_config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ receivers:
1111
scrape_configs:
1212
- job_name: 'otelcol'
1313
scrape_interval: 1s
14-
fallback_scrape_protocol: "PrometheusText1.0.0"
1514
static_configs:
1615
- targets: [ '${env:PROM_SERVER}' ]
1716
metric_relabel_configs:

receiver/prometheusreceiver/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ func (cfg *PromConfig) Validate() error {
103103
if err != nil {
104104
return err
105105
}
106+
// Since Prometheus 3.0, the scrape manager started to fail scrapes that don't have proper
107+
// Content-Type headers, but they provided an extra configuration option to fallback to the
108+
// previous behavior. We need to make sure that this option is set for all scrape configs
109+
// to avoid introducing a breaking change.
110+
for _, sc := range scrapeConfigs {
111+
if sc.ScrapeFallbackProtocol == "" {
112+
sc.ScrapeFallbackProtocol = promconfig.PrometheusText0_0_4
113+
}
114+
}
106115

107116
for _, sc := range scrapeConfigs {
108117
if err := validateHTTPClientConfig(&sc.HTTPClientConfig); err != nil {

receiver/prometheusreceiver/factory.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ func createMetricsReceiver(
6363
nextConsumer consumer.Metrics,
6464
) (receiver.Metrics, error) {
6565
configWarnings(set.Logger, cfg.(*Config))
66-
addDefaultFallbackScrapeProtocol(cfg.(*Config))
6766
return newPrometheusReceiver(set, cfg.(*Config), nextConsumer), nil
6867
}
6968

@@ -76,11 +75,3 @@ func configWarnings(logger *zap.Logger, cfg *Config) {
7675
}
7776
}
7877
}
79-
80-
func addDefaultFallbackScrapeProtocol(cfg *Config) {
81-
for _, sc := range cfg.PrometheusConfig.ScrapeConfigs {
82-
if sc.ScrapeFallbackProtocol == "" {
83-
sc.ScrapeFallbackProtocol = promconfig.PrometheusText1_0_0
84-
}
85-
}
86-
}

receiver/prometheusreceiver/factory_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"path/filepath"
99
"testing"
1010

11-
promconfig "github.com/prometheus/prometheus/config"
1211
"github.com/stretchr/testify/assert"
1312
"github.com/stretchr/testify/require"
1413
"go.opentelemetry.io/collector/component"
@@ -63,21 +62,3 @@ func TestMultipleCreate(t *testing.T) {
6362
require.NoError(t, secondRcvr.Start(context.Background(), host))
6463
require.NoError(t, secondRcvr.Shutdown(context.Background()))
6564
}
66-
67-
func TestDefaultFallbackScrapeProtocol(t *testing.T) {
68-
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config_fallback_scrape_protocol.yaml"))
69-
require.NoError(t, err)
70-
factory := NewFactory()
71-
cfg := factory.CreateDefaultConfig()
72-
73-
sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String())
74-
require.NoError(t, err)
75-
assert.NoError(t, sub.Unmarshal(cfg))
76-
77-
_, err = factory.CreateMetrics(context.Background(), receivertest.NewNopSettingsWithType(metadata.Type), cfg, consumertest.NewNop())
78-
require.NoError(t, err)
79-
80-
// During receiver creation, scrapeconfig without fallback scrape protocol set, should be set to 'PrometheusText1.0.0'.
81-
assert.Equal(t, promconfig.PrometheusText1_0_0, cfg.(*Config).PrometheusConfig.ScrapeConfigs[0].ScrapeFallbackProtocol)
82-
assert.Equal(t, promconfig.OpenMetricsText1_0_0, cfg.(*Config).PrometheusConfig.ScrapeConfigs[1].ScrapeFallbackProtocol)
83-
}

receiver/prometheusreceiver/internal/staleness_end_to_end_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ receivers:
109109
scrape_configs:
110110
- job_name: 'test'
111111
scrape_interval: 100ms
112-
fallback_scrape_protocol: "PrometheusText1.0.0"
113112
static_configs:
114113
- targets: [%q]
115114

receiver/prometheusreceiver/metrics_receiver_labels_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"testing"
88

99
"github.com/prometheus/common/model"
10-
promconfig "github.com/prometheus/prometheus/config"
1110
"github.com/prometheus/prometheus/model/labels"
1211
"github.com/prometheus/prometheus/model/relabel"
1312
"github.com/stretchr/testify/require"
@@ -258,7 +257,6 @@ func TestLabelNameLimitConfig(t *testing.T) {
258257
testComponent(t, targets, nil, func(cfg *PromConfig) {
259258
// set label limit in scrape_config
260259
for _, scrapeCfg := range cfg.ScrapeConfigs {
261-
scrapeCfg.ScrapeFallbackProtocol = promconfig.PrometheusText1_0_0
262260
scrapeCfg.LabelNameLengthLimit = 20
263261
}
264262
})

receiver/prometheusreceiver/testdata/config_target_allocator.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ prometheus/withScrape:
1515
scrape_configs:
1616
- job_name: 'demo'
1717
scrape_interval: 5s
18-
fallback_scrape_protocol: "PrometheusText1.0.0"
1918
prometheus/withOnlyScrape:
2019
config:
2120
scrape_configs:
2221
- job_name: 'demo'
2322
scrape_interval: 5s
24-
fallback_scrape_protocol: "PrometheusText1.0.0"

receiver/prometheusreceiver/testdata/invalid-config-prometheus-file-sd-config-json.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ prometheus:
33
scrape_configs:
44
- job_name: 'demo'
55
scrape_interval: 5s
6-
fallback_scrape_protocol: "PrometheusText1.0.0"
76
file_sd_configs:
87
- files: ["./testdata/sd-config-with-null-target-group.json"]

receiver/prometheusreceiver/testdata/invalid-config-prometheus-file-sd-config-yaml.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ prometheus:
33
scrape_configs:
44
- job_name: 'demo'
55
scrape_interval: 5s
6-
fallback_scrape_protocol: "PrometheusText1.0.0"
76
file_sd_configs:
87
- files: ["./testdata/sd-config-with-null-target-group.yaml"]

receiver/prometheusreceiver/testdata/invalid-config-prometheus-nonexistent-scrape-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ prometheus/withOnlyScrape:
1717
scrape_configs:
1818
- job_name: 'demo'
1919
scrape_interval: 5s
20-
fallback_scrape_protocol: "PrometheusText1.0.0"

receiver/prometheusreceiver/testdata/invalid-config-prometheus-unsupported-features.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ prometheus:
55
scrape_configs:
66
- job_name: 'demo'
77
scrape_interval: 5s
8-
fallback_scrape_protocol: "PrometheusText1.0.0"
98
remote_write:
109
- url: "https://example.org/write"
1110

receiver/prometheusreceiver/testdata/nonexistent-prometheus-sd-file-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ prometheus:
33
scrape_configs:
44
- job_name: 'test'
55
scrape_interval: 5s
6-
fallback_scrape_protocol: "PrometheusText1.0.0"
76
file_sd_configs:
87
- files: ["./testdata/nonexistent-sd-file.json"]

0 commit comments

Comments
 (0)