Skip to content

Commit 4c6231f

Browse files
committed
prometheusreceiver: disable start time adjustment by default
1 parent 3614764 commit 4c6231f

12 files changed

+776
-702
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog)
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: The prometheus receiver no longer adjusts the start time of metrics by default.
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: [43656]
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: Disable the receiver.prometheusreceiver.RemoveStartTimeAdjustment |
19+
feature gate to temporarily re-enable this functionality. Users that need |
20+
this functionality should to migrate to the metricstarttime processor, |
21+
and use the true_reset strategy for equivalent behavior.
22+
23+
# If your change doesn't affect end users or the exported elements of any package,
24+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
25+
# Optional: The change log or logs in which this entry should be included.
26+
# e.g. '[user]' or '[user, api]'
27+
# Include 'user' if the change is relevant to end users.
28+
# Include 'api' if there is a change to a library API.
29+
# Default: '[user]'
30+
change_logs: []

receiver/prometheusreceiver/internal/metricfamily_test.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func TestMetricGroupData_toDistributionUnitTest(t *testing.T) {
120120
intervalStartTimeMs int64
121121
}{
122122
{
123-
name: "histogram with startTimestamp",
123+
name: "histogram with no startTimestamp",
124124
metricName: "histogram",
125125
intervalStartTimeMs: 11,
126126
labels: labels.FromMap(map[string]string{"a": "A", "b": "B"}),
@@ -138,7 +138,6 @@ func TestMetricGroupData_toDistributionUnitTest(t *testing.T) {
138138
point.SetTimestamp(pcommon.Timestamp(11 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
139139
point.ExplicitBounds().FromRaw([]float64{0.75, 2.75})
140140
point.BucketCounts().FromRaw([]uint64{33, 22, 11})
141-
point.SetStartTimestamp(pcommon.Timestamp(11 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
142141
attributes := point.Attributes()
143142
attributes.PutStr("a", "A")
144143
attributes.PutStr("b", "B")
@@ -207,7 +206,6 @@ func TestMetricGroupData_toDistributionUnitTest(t *testing.T) {
207206
point.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(true))
208207
point.ExplicitBounds().FromRaw([]float64{0.75, 2.75})
209208
point.BucketCounts().FromRaw([]uint64{0, 0, 0})
210-
point.SetStartTimestamp(pcommon.Timestamp(11 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
211209
attributes := point.Attributes()
212210
attributes.PutStr("a", "A")
213211
attributes.PutStr("b", "B")
@@ -239,8 +237,7 @@ func TestMetricGroupData_toDistributionUnitTest(t *testing.T) {
239237
point := pmetric.NewHistogramDataPoint()
240238
point.SetCount(66)
241239
point.SetSum(1004.78)
242-
point.SetTimestamp(pcommon.Timestamp(11 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
243-
point.SetStartTimestamp(pcommon.Timestamp(11 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
240+
point.SetTimestamp(pcommon.Timestamp(11 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
244241
point.BucketCounts().FromRaw([]uint64{66})
245242
attributes := point.Attributes()
246243
attributes.PutStr("a", "A")
@@ -323,7 +320,6 @@ func TestMetricGroupData_toNHCBDistributionUnitTest(t *testing.T) {
323320
point.SetCount(180)
324321
point.SetSum(100.5)
325322
point.SetTimestamp(pcommon.Timestamp(11 * time.Millisecond))
326-
point.SetStartTimestamp(pcommon.Timestamp(11 * time.Millisecond))
327323
point.ExplicitBounds().FromRaw([]float64{1.0, 2.0, 5.0, 10.0})
328324
point.BucketCounts().FromRaw([]uint64{10, 25, 45, 50, 50})
329325
attributes := point.Attributes()
@@ -347,7 +343,6 @@ func TestMetricGroupData_toNHCBDistributionUnitTest(t *testing.T) {
347343
point := pmetric.NewHistogramDataPoint()
348344
point.SetTimestamp(pcommon.Timestamp(11 * time.Millisecond))
349345
point.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(true))
350-
point.SetStartTimestamp(pcommon.Timestamp(11 * time.Millisecond))
351346
point.ExplicitBounds().FromRaw([]float64{1.0, 2.0, 5.0, 10.0})
352347
point.BucketCounts().FromRaw([]uint64{0, 0, 0, 0, 0})
353348
attributes := point.Attributes()
@@ -374,7 +369,6 @@ func TestMetricGroupData_toNHCBDistributionUnitTest(t *testing.T) {
374369
point.SetCount(50)
375370
point.SetSum(125.25)
376371
point.SetTimestamp(pcommon.Timestamp(12 * time.Millisecond))
377-
point.SetStartTimestamp(pcommon.Timestamp(12 * time.Millisecond))
378372
point.ExplicitBounds().FromRaw([]float64{0.5, 2.0})
379373
point.BucketCounts().FromRaw([]uint64{15, 20, 15})
380374
attributes := point.Attributes()
@@ -400,7 +394,6 @@ func TestMetricGroupData_toNHCBDistributionUnitTest(t *testing.T) {
400394
point.SetCount(16)
401395
point.SetSum(10.0)
402396
point.SetTimestamp(pcommon.Timestamp(30 * time.Millisecond))
403-
point.SetStartTimestamp(pcommon.Timestamp(30 * time.Millisecond))
404397
point.ExplicitBounds().FromRaw([]float64{-5.0, 0.0, 5.0})
405398
point.BucketCounts().FromRaw([]uint64{5, 10, 15, 16})
406399
point.Attributes().PutStr("a", "A")
@@ -455,7 +448,7 @@ func TestMetricGroupData_toExponentialDistributionUnitTest(t *testing.T) {
455448
intervalStartTimeMs int64
456449
}{
457450
{
458-
name: "integer histogram with startTimestamp",
451+
name: "integer histogram without startTimestamp",
459452
metricName: "request_duration_seconds",
460453
intervalStartTimeMs: 11,
461454
labels: labels.FromMap(map[string]string{"a": "A", "b": "B"}),
@@ -481,8 +474,7 @@ func TestMetricGroupData_toExponentialDistributionUnitTest(t *testing.T) {
481474
point := pmetric.NewExponentialHistogramDataPoint()
482475
point.SetCount(66)
483476
point.SetSum(1004.78)
484-
point.SetTimestamp(pcommon.Timestamp(11 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
485-
point.SetStartTimestamp(pcommon.Timestamp(11 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
477+
point.SetTimestamp(pcommon.Timestamp(11 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
486478
point.SetScale(1)
487479
point.SetZeroThreshold(0.42)
488480
point.SetZeroCount(1)
@@ -560,7 +552,6 @@ func TestMetricGroupData_toExponentialDistributionUnitTest(t *testing.T) {
560552
point := pmetric.NewExponentialHistogramDataPoint()
561553
point.SetTimestamp(pcommon.Timestamp(11 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
562554
point.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(true))
563-
point.SetStartTimestamp(pcommon.Timestamp(11 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
564555
attributes := point.Attributes()
565556
attributes.PutStr("a", "A")
566557
attributes.PutStr("b", "B")
@@ -704,8 +695,7 @@ func TestMetricGroupData_toSummaryUnitTest(t *testing.T) {
704695
qn99 := qtL.AppendEmpty()
705696
qn99.SetQuantile(.99)
706697
qn99.SetValue(82)
707-
point.SetTimestamp(pcommon.Timestamp(14 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
708-
point.SetStartTimestamp(pcommon.Timestamp(14 * time.Millisecond)) // the time in milliseconds -> nanoseconds
698+
point.SetTimestamp(pcommon.Timestamp(14 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
709699
attributes := point.Attributes()
710700
attributes.PutStr("a", "A")
711701
attributes.PutStr("b", "B")
@@ -848,8 +838,7 @@ func TestMetricGroupData_toSummaryUnitTest(t *testing.T) {
848838
qn99 := qtL.AppendEmpty()
849839
qn99.SetQuantile(.99)
850840
qn99.SetValue(0)
851-
point.SetTimestamp(pcommon.Timestamp(14 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
852-
point.SetStartTimestamp(pcommon.Timestamp(14 * time.Millisecond)) // the time in milliseconds -> nanoseconds
841+
point.SetTimestamp(pcommon.Timestamp(14 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
853842
attributes := point.Attributes()
854843
attributes.PutStr("a", "A")
855844
attributes.PutStr("b", "B")
@@ -942,7 +931,6 @@ func TestMetricGroupData_toNumberDataUnitTest(t *testing.T) {
942931

943932
// the time in milliseconds -> nanoseconds.
944933
point.SetTimestamp(pcommon.Timestamp(13 * time.Millisecond))
945-
point.SetStartTimestamp(pcommon.Timestamp(13 * time.Millisecond))
946934

947935
attributes := point.Attributes()
948936
attributes.PutStr("a", "A")
@@ -984,8 +972,7 @@ func TestMetricGroupData_toNumberDataUnitTest(t *testing.T) {
984972
want: func() pmetric.NumberDataPoint {
985973
point := pmetric.NewNumberDataPoint()
986974
point.SetDoubleValue(33.7)
987-
point.SetTimestamp(pcommon.Timestamp(13 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
988-
point.SetStartTimestamp(pcommon.Timestamp(13 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
975+
point.SetTimestamp(pcommon.Timestamp(13 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
989976
attributes := point.Attributes()
990977
attributes.PutStr("a", "A")
991978
attributes.PutStr("b", "B")
@@ -1003,8 +990,7 @@ func TestMetricGroupData_toNumberDataUnitTest(t *testing.T) {
1003990
want: func() pmetric.NumberDataPoint {
1004991
point := pmetric.NewNumberDataPoint()
1005992
point.SetDoubleValue(99.9)
1006-
point.SetTimestamp(pcommon.Timestamp(28 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
1007-
point.SetStartTimestamp(pcommon.Timestamp(28 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
993+
point.SetTimestamp(pcommon.Timestamp(28 * time.Millisecond)) // the time in milliseconds -> nanoseconds.
1008994
attributes := point.Attributes()
1009995
attributes.PutStr("a", "A")
1010996
attributes.PutStr("b", "B")

receiver/prometheusreceiver/internal/metrics_adjuster_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"time"
99

1010
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
12+
"go.opentelemetry.io/collector/featuregate"
1113
"go.opentelemetry.io/collector/pdata/pcommon"
1214
"go.opentelemetry.io/collector/pdata/pmetric"
1315
semconv "go.opentelemetry.io/otel/semconv/v1.27.0"
@@ -740,6 +742,11 @@ type metricsAdjusterTest struct {
740742
func runScript(t *testing.T, ma MetricsAdjuster, job, instance string, tests []*metricsAdjusterTest) {
741743
for _, test := range tests {
742744
t.Run(test.description, func(t *testing.T) {
745+
err := featuregate.GlobalRegistry().Set("receiver.prometheusreceiver.RemoveStartTimeAdjustment", false)
746+
require.NoError(t, err)
747+
defer func() {
748+
_ = featuregate.GlobalRegistry().Set("receiver.prometheusreceiver.RemoveStartTimeAdjustment", true)
749+
}()
743750
adjusted := pmetric.NewMetrics()
744751
test.metrics.CopyTo(adjusted)
745752
// Add the instance/job to the input metrics if they aren't already present.

receiver/prometheusreceiver/internal/starttimemetricadjuster_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ func TestStartTimeMetricMatch(t *testing.T) {
167167
}
168168

169169
func TestStartTimeMetricFallback(t *testing.T) {
170+
defer testutil.SetFeatureGateForTest(t, removeStartTimeAdjustment, false)()
170171
const startTime = pcommon.Timestamp(123 * 1e9)
171172
const currentTime = pcommon.Timestamp(126 * 1e9)
172173
mockStartTime := time.Now().Add(-10 * time.Hour)

receiver/prometheusreceiver/internal/transaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232

3333
var removeStartTimeAdjustment = featuregate.GlobalRegistry().MustRegister(
3434
"receiver.prometheusreceiver.RemoveStartTimeAdjustment",
35-
featuregate.StageAlpha,
35+
featuregate.StageBeta,
3636
featuregate.WithRegisterDescription("When enabled, the Prometheus receiver will"+
3737
" leave the start time unset. Use the new metricstarttime processor instead."),
3838
)

0 commit comments

Comments
 (0)