Skip to content

Commit 75f5b58

Browse files
authored
prometheusreceiver: deprecate start time adjustment (#37879)
#### Description Start time metric adjustment is still enabled by default, but can now be disabled using a feature gate. It is being replaced by the metricstarttime processor: #37186 #### Link to tracking issue Part of #37186 #### Testing I updated the unit test for counters #### Documentation Updated the README
1 parent a95514f commit 75f5b58

File tree

7 files changed

+275
-204
lines changed

7 files changed

+275
-204
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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: deprecation
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: prometheusreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Deprecate metric start time adjustment in the prometheus receiver. It is being replaced by the metricstarttime processor.
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: [37186]
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: Start time adjustment is still enabled by default. To disable it, enable the |
19+
receiver.prometheusreceiver.RemoveStartTimeAdjustment feature gate.
20+
21+
# If your change doesn't affect end users or the exported elements of any package,
22+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
23+
# Optional: The change log or logs in which this entry should be included.
24+
# e.g. '[user]' or '[user, api]'
25+
# Include 'user' if the change is relevant to end users.
26+
# Include 'api' if there is a change to a library API.
27+
# Default: '[user]'
28+
change_logs: []

receiver/prometheusreceiver/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ prometheus --config.file=prom.yaml
9090
"--feature-gates=receiver.prometheusreceiver.RemoveLegacyResourceAttributes"
9191
```
9292

93+
- `receiver.prometheusreceiver.RemoveStartTimeAdjustment`: If enabled, the prometheus receiver no longer sets the start timestamp of metrics if it is not known. Use the `metricstarttime` processor instead if you need this functionality.
94+
95+
```shell
96+
"--feature-gates=receiver.prometheusreceiver.RemoveStartTimeAdjustment"
97+
```
98+
9399
- `report_extra_scrape_metrics`: Extra Prometheus scrape metrics can be reported by setting this parameter to `true`
94100

95101
You can copy and paste that same configuration under:

receiver/prometheusreceiver/internal/metricfamily.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (mg *metricGroup) toDistributionPoint(dest pmetric.HistogramDataPointSlice)
145145
tsNanos := timestampFromMs(mg.ts)
146146
if mg.created != 0 {
147147
point.SetStartTimestamp(timestampFromFloat64(mg.created))
148-
} else {
148+
} else if !removeStartTimeAdjustment.IsEnabled() {
149149
// metrics_adjuster adjusts the startTimestamp to the initial scrape timestamp
150150
point.SetStartTimestamp(tsNanos)
151151
}
@@ -223,7 +223,7 @@ func (mg *metricGroup) toExponentialHistogramDataPoints(dest pmetric.Exponential
223223
tsNanos := timestampFromMs(mg.ts)
224224
if mg.created != 0 {
225225
point.SetStartTimestamp(timestampFromFloat64(mg.created))
226-
} else {
226+
} else if !removeStartTimeAdjustment.IsEnabled() {
227227
// metrics_adjuster adjusts the startTimestamp to the initial scrape timestamp
228228
point.SetStartTimestamp(tsNanos)
229229
}
@@ -317,7 +317,7 @@ func (mg *metricGroup) toSummaryPoint(dest pmetric.SummaryDataPointSlice) {
317317
point.SetTimestamp(tsNanos)
318318
if mg.created != 0 {
319319
point.SetStartTimestamp(timestampFromFloat64(mg.created))
320-
} else {
320+
} else if !removeStartTimeAdjustment.IsEnabled() {
321321
// metrics_adjuster adjusts the startTimestamp to the initial scrape timestamp
322322
point.SetStartTimestamp(tsNanos)
323323
}
@@ -331,7 +331,7 @@ func (mg *metricGroup) toNumberDataPoint(dest pmetric.NumberDataPointSlice) {
331331
if mg.mtype == pmetric.MetricTypeSum {
332332
if mg.created != 0 {
333333
point.SetStartTimestamp(timestampFromFloat64(mg.created))
334-
} else {
334+
} else if !removeStartTimeAdjustment.IsEnabled() {
335335
// metrics_adjuster adjusts the startTimestamp to the initial scrape timestamp
336336
point.SetStartTimestamp(tsNanos)
337337
}

receiver/prometheusreceiver/internal/metrics_adjuster.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ func NewInitialPointAdjuster(logger *zap.Logger, gcInterval time.Duration, useCr
260260
// AdjustMetrics takes a sequence of metrics and adjust their start times based on the initial and
261261
// previous points in the timeseriesMap.
262262
func (a *initialPointAdjuster) AdjustMetrics(metrics pmetric.Metrics) error {
263+
if removeStartTimeAdjustment.IsEnabled() {
264+
return nil
265+
}
263266
for i := 0; i < metrics.ResourceMetrics().Len(); i++ {
264267
rm := metrics.ResourceMetrics().At(i)
265268
_, found := rm.Resource().Attributes().Get(semconv.AttributeServiceName)

receiver/prometheusreceiver/internal/starttimemetricadjuster.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ func NewStartTimeMetricAdjuster(logger *zap.Logger, startTimeMetricRegex *regexp
6060
}
6161

6262
func (stma *startTimeMetricAdjuster) AdjustMetrics(metrics pmetric.Metrics) error {
63+
if removeStartTimeAdjustment.IsEnabled() {
64+
return nil
65+
}
6366
startTime, err := stma.getStartTime(metrics)
6467
if err != nil {
6568
if !useCollectorStartTimeFallbackGate.IsEnabled() {

receiver/prometheusreceiver/internal/transaction.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/prometheus/prometheus/storage"
2020
"go.opentelemetry.io/collector/component"
2121
"go.opentelemetry.io/collector/consumer"
22+
"go.opentelemetry.io/collector/featuregate"
2223
"go.opentelemetry.io/collector/pdata/pcommon"
2324
"go.opentelemetry.io/collector/pdata/pmetric"
2425
"go.opentelemetry.io/collector/receiver"
@@ -29,6 +30,13 @@ import (
2930
mdata "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver/internal/metadata"
3031
)
3132

33+
var removeStartTimeAdjustment = featuregate.GlobalRegistry().MustRegister(
34+
"receiver.prometheusreceiver.RemoveStartTimeAdjustment",
35+
featuregate.StageAlpha,
36+
featuregate.WithRegisterDescription("When enabled, the Prometheus receiver will"+
37+
" leave the start time unset. Use the new metricstarttime processor instead."),
38+
)
39+
3240
type resourceKey struct {
3341
job string
3442
instance string
@@ -465,9 +473,11 @@ func (t *transaction) Commit() error {
465473
return nil
466474
}
467475

468-
if err = t.metricAdjuster.AdjustMetrics(md); err != nil {
469-
t.obsrecv.EndMetricsOp(ctx, dataformat, numPoints, err)
470-
return err
476+
if !removeStartTimeAdjustment.IsEnabled() {
477+
if err = t.metricAdjuster.AdjustMetrics(md); err != nil {
478+
t.obsrecv.EndMetricsOp(ctx, dataformat, numPoints, err)
479+
return err
480+
}
471481
}
472482

473483
err = t.sink.ConsumeMetrics(ctx, md)

0 commit comments

Comments
 (0)