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
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 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.
# 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 ]
11 changes: 9 additions & 2 deletions receiver/prometheusreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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:
Expand Down Expand Up @@ -182,6 +181,14 @@ 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. This replaces the deprecated
`report_extra_scrape_metrics` configuration flag:

```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:
Expand Down
2 changes: 2 additions & 0 deletions receiver/prometheusreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ 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 @@ -13,6 +13,7 @@ import (
"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"
)

Expand Down Expand Up @@ -48,17 +49,18 @@ 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()

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 Down