Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/prom-scrape-config-protocol.yaml
Original file line number Diff line number Diff line change
@@ -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]
1 change: 0 additions & 1 deletion exporter/datadogexporter/examples/collector-metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
1 change: 0 additions & 1 deletion exporter/datadogexporter/examples/ootb-ec2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}' ]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions receiver/prometheusreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also noticed that my choice of default scrape protocol was wrong 🤦 The previous default is Prometheus 0.0.4

}
}

for _, sc := range scrapeConfigs {
if err := validateHTTPClientConfig(&sc.HTTPClientConfig); err != nil {
Expand Down
9 changes: 0 additions & 9 deletions receiver/prometheusreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
}
}
19 changes: 0 additions & 19 deletions receiver/prometheusreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ receivers:
scrape_configs:
- job_name: 'test'
scrape_interval: 100ms
fallback_scrape_protocol: "PrometheusText1.0.0"
static_configs:
- targets: [%q]

Expand Down
2 changes: 0 additions & 2 deletions receiver/prometheusreceiver/metrics_receiver_labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ prometheus/withOnlyScrape:
scrape_configs:
- job_name: 'demo'
scrape_interval: 5s
fallback_scrape_protocol: "PrometheusText1.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]