Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
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: deprecation

# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog)
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

# 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 ]
1 change: 1 addition & 0 deletions receiver/prometheusreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
7 changes: 7 additions & 0 deletions receiver/prometheusreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion receiver/prometheusreceiver/metrics_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down