Skip to content

Commit 32f1518

Browse files
pokgakArthurSensdashpole
authored andcommitted
[exporter/prometheusremotewrite] deprecate export_created_metric (open-telemetry#36214)
#### Description Deprecate export_created_metric config option #### Link to tracking issue Fixes open-telemetry#35003 --------- Co-authored-by: Arthur Silva Sens <[email protected]> Co-authored-by: David Ashpole <[email protected]>
1 parent 3de024e commit 32f1518

File tree

7 files changed

+146
-16
lines changed

7 files changed

+146
-16
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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. otlpreceiver)
7+
component: exporter/prometheusremotewrite
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Deprecate configuration option `export_created metric`
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [35003]
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 exporter.prometheusremotewriteexporter.deprecateCreatedMetric feature gate to temporarily re-enable the created metric.
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [user]

exporter/prometheusremotewriteexporter/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ The following settings can be optionally configured:
5959
- `enabled` (default = false): If `enabled` is `true`, all the resource attributes will be converted to metric labels by default.
6060
- `target_info`: customize `target_info` metric
6161
- `enabled` (default = true): If `enabled` is `true`, a `target_info` metric will be generated for each resource metric (see https://github.com/open-telemetry/opentelemetry-specification/pull/2381).
62-
- `export_created_metric`:
62+
- `export_created_metric`: `WARNING` Deprecated and planned for removal in v0.116.0. See [related issue](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35003) for more information.
6363
- `enabled` (default = false): If `enabled` is `true`, a `_created` metric is
6464
exported for Summary, Histogram, and Monotonic Sum metric points if
6565
`StartTimeUnixNano` is set.

exporter/prometheusremotewriteexporter/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ type Config struct {
4545
TargetInfo *TargetInfo `mapstructure:"target_info,omitempty"`
4646

4747
// CreatedMetric allows customizing creation of _created metrics
48+
// Deprecated[0.114.0]: The feature doesn't provide the expected behavior. Use Prometheus remote-write v2 to enable sending Created Timestamps.
49+
// This feature is planned to be removed in v0.116.0
4850
CreatedMetric *CreatedMetric `mapstructure:"export_created_metric,omitempty"`
4951

5052
// AddMetricSuffixes controls whether unit and type suffixes are added to metrics on export

exporter/prometheusremotewriteexporter/exporter.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ func newPRWExporter(cfg *Config, set exporter.Settings) (*prwExporter, error) {
143143
batchTimeSeriesState: newBatchTimeSericesState(),
144144
}
145145

146+
if prwe.exporterSettings.ExportCreatedMetric {
147+
prwe.settings.Logger.Warn("export_created_metric is deprecated and will be removed in a future release")
148+
}
149+
146150
prwe.wal = newWAL(cfg.WAL, prwe.export)
147151
return prwe, nil
148152
}

pkg/translator/prometheusremotewrite/go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ go 1.22.0
55
require (
66
github.com/cespare/xxhash/v2 v2.3.0
77
github.com/google/go-cmp v0.6.0
8-
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.113.0
9-
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.113.0
8+
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.113.0
9+
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.112.0
10+
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.112.0
1011
github.com/prometheus/common v0.60.1
1112
github.com/prometheus/prometheus v0.54.1
1213
github.com/stretchr/testify v1.9.0
14+
go.opentelemetry.io/collector/featuregate v1.19.1-0.20241115165626-8b99b8023ca3
1315
go.opentelemetry.io/collector/pdata v1.19.1-0.20241115165626-8b99b8023ca3
1416
go.opentelemetry.io/collector/semconv v0.113.1-0.20241115165626-8b99b8023ca3
1517
go.uber.org/goleak v1.3.0
@@ -26,7 +28,6 @@ require (
2628
github.com/modern-go/reflect2 v1.0.2 // indirect
2729
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
2830
github.com/prometheus/client_model v0.6.1 // indirect
29-
go.opentelemetry.io/collector/featuregate v1.19.1-0.20241115165626-8b99b8023ca3 // indirect
3031
golang.org/x/net v0.29.0 // indirect
3132
golang.org/x/sys v0.27.0 // indirect
3233
golang.org/x/text v0.19.0 // indirect

pkg/translator/prometheusremotewrite/helper.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/prometheus/prometheus/model/timestamp"
2020
"github.com/prometheus/prometheus/model/value"
2121
"github.com/prometheus/prometheus/prompb"
22+
"go.opentelemetry.io/collector/featuregate"
2223
"go.opentelemetry.io/collector/pdata/pcommon"
2324
"go.opentelemetry.io/collector/pdata/pmetric"
2425
conventions "go.opentelemetry.io/collector/semconv/v1.25.0"
@@ -41,6 +42,13 @@ const (
4142
infoType = "info"
4243
)
4344

45+
var exportCreatedMetricGate = featuregate.GlobalRegistry().MustRegister(
46+
"exporter.prometheusremotewriteexporter.deprecateCreatedMetric",
47+
featuregate.StageAlpha,
48+
featuregate.WithRegisterDescription("Feature gate used to control the deprecation of created metrics."),
49+
featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35003"),
50+
)
51+
4452
type bucketBoundsData struct {
4553
ts *prompb.TimeSeries
4654
bound float64
@@ -275,7 +283,7 @@ func (c *prometheusConverter) addHistogramDataPoints(dataPoints pmetric.Histogra
275283
c.addExemplars(pt, bucketBounds)
276284

277285
startTimestamp := pt.StartTimestamp()
278-
if settings.ExportCreatedMetric && startTimestamp != 0 {
286+
if settings.ExportCreatedMetric && startTimestamp != 0 && !exportCreatedMetricGate.IsEnabled() {
279287
labels := createLabels(baseName+createdSuffix, baseLabels)
280288
c.addTimeSeriesIfNeeded(labels, startTimestamp, pt.Timestamp())
281289
}
@@ -431,7 +439,7 @@ func (c *prometheusConverter) addSummaryDataPoints(dataPoints pmetric.SummaryDat
431439
}
432440

433441
startTimestamp := pt.StartTimestamp()
434-
if settings.ExportCreatedMetric && startTimestamp != 0 {
442+
if settings.ExportCreatedMetric && startTimestamp != 0 && !exportCreatedMetricGate.IsEnabled() {
435443
createdLabels := createLabels(baseName+createdSuffix, baseLabels)
436444
c.addTimeSeriesIfNeeded(createdLabels, startTimestamp, pt.Timestamp())
437445
}

pkg/translator/prometheusremotewrite/helper_test.go

Lines changed: 100 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"go.opentelemetry.io/collector/pdata/pmetric"
2020
conventions "go.opentelemetry.io/collector/semconv/v1.25.0"
2121

22+
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
2223
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/testdata"
2324
prometheustranslator "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus"
2425
)
@@ -677,12 +678,14 @@ func TestMostRecentTimestampInMetric(t *testing.T) {
677678
func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) {
678679
ts := pcommon.Timestamp(time.Now().UnixNano())
679680
tests := []struct {
680-
name string
681-
metric func() pmetric.Metric
682-
want func() map[uint64]*prompb.TimeSeries
681+
name string
682+
isGateEnabled bool
683+
metric func() pmetric.Metric
684+
want func() map[uint64]*prompb.TimeSeries
683685
}{
684686
{
685-
name: "summary with start time",
687+
name: "summary with start time",
688+
isGateEnabled: false,
686689
metric: func() pmetric.Metric {
687690
metric := pmetric.NewMetric()
688691
metric.SetName("test_summary")
@@ -727,14 +730,52 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) {
727730
},
728731
},
729732
{
730-
name: "summary without start time",
733+
name: "summary without start time",
734+
isGateEnabled: false,
735+
metric: func() pmetric.Metric {
736+
metric := pmetric.NewMetric()
737+
metric.SetName("test_summary")
738+
metric.SetEmptySummary()
739+
740+
dp := metric.Summary().DataPoints().AppendEmpty()
741+
dp.SetTimestamp(ts)
742+
743+
return metric
744+
},
745+
want: func() map[uint64]*prompb.TimeSeries {
746+
labels := []prompb.Label{
747+
{Name: model.MetricNameLabel, Value: "test_summary" + countStr},
748+
}
749+
sumLabels := []prompb.Label{
750+
{Name: model.MetricNameLabel, Value: "test_summary" + sumStr},
751+
}
752+
return map[uint64]*prompb.TimeSeries{
753+
timeSeriesSignature(labels): {
754+
Labels: labels,
755+
Samples: []prompb.Sample{
756+
{Value: 0, Timestamp: convertTimeStamp(ts)},
757+
},
758+
},
759+
timeSeriesSignature(sumLabels): {
760+
Labels: sumLabels,
761+
Samples: []prompb.Sample{
762+
{Value: 0, Timestamp: convertTimeStamp(ts)},
763+
},
764+
},
765+
}
766+
},
767+
},
768+
{
769+
name: "summary with exportCreatedMetricGate enabled",
770+
isGateEnabled: true,
731771
metric: func() pmetric.Metric {
732772
metric := pmetric.NewMetric()
733773
metric.SetName("test_summary")
734774
metric.SetEmptySummary()
735775

736776
dp := metric.Summary().DataPoints().AppendEmpty()
737777
dp.SetTimestamp(ts)
778+
dp.SetStartTimestamp(ts)
738779

739780
return metric
740781
},
@@ -764,6 +805,10 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) {
764805
}
765806
for _, tt := range tests {
766807
t.Run(tt.name, func(t *testing.T) {
808+
oldValue := exportCreatedMetricGate.IsEnabled()
809+
testutil.SetFeatureGateForTest(t, exportCreatedMetricGate, tt.isGateEnabled)
810+
defer testutil.SetFeatureGateForTest(t, exportCreatedMetricGate, oldValue)
811+
767812
metric := tt.metric()
768813
converter := newPrometheusConverter()
769814

@@ -785,12 +830,14 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) {
785830
func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) {
786831
ts := pcommon.Timestamp(time.Now().UnixNano())
787832
tests := []struct {
788-
name string
789-
metric func() pmetric.Metric
790-
want func() map[uint64]*prompb.TimeSeries
833+
name string
834+
isGateEnabled bool
835+
metric func() pmetric.Metric
836+
want func() map[uint64]*prompb.TimeSeries
791837
}{
792838
{
793-
name: "histogram with start time",
839+
name: "histogram with start time",
840+
isGateEnabled: false,
794841
metric: func() pmetric.Metric {
795842
metric := pmetric.NewMetric()
796843
metric.SetName("test_hist")
@@ -836,7 +883,8 @@ func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) {
836883
},
837884
},
838885
{
839-
name: "histogram without start time",
886+
name: "histogram without start time",
887+
isGateEnabled: false,
840888
metric: func() pmetric.Metric {
841889
metric := pmetric.NewMetric()
842890
metric.SetName("test_hist")
@@ -871,9 +919,51 @@ func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) {
871919
}
872920
},
873921
},
922+
{
923+
name: "histogram with exportCreatedMetricGate enabled",
924+
isGateEnabled: true,
925+
metric: func() pmetric.Metric {
926+
metric := pmetric.NewMetric()
927+
metric.SetName("test_hist")
928+
metric.SetEmptyHistogram().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative)
929+
930+
pt := metric.Histogram().DataPoints().AppendEmpty()
931+
pt.SetTimestamp(ts)
932+
pt.SetStartTimestamp(ts)
933+
934+
return metric
935+
},
936+
want: func() map[uint64]*prompb.TimeSeries {
937+
labels := []prompb.Label{
938+
{Name: model.MetricNameLabel, Value: "test_hist" + countStr},
939+
}
940+
infLabels := []prompb.Label{
941+
{Name: model.MetricNameLabel, Value: "test_hist_bucket"},
942+
{Name: model.BucketLabel, Value: "+Inf"},
943+
}
944+
return map[uint64]*prompb.TimeSeries{
945+
timeSeriesSignature(infLabels): {
946+
Labels: infLabels,
947+
Samples: []prompb.Sample{
948+
{Value: 0, Timestamp: convertTimeStamp(ts)},
949+
},
950+
},
951+
timeSeriesSignature(labels): {
952+
Labels: labels,
953+
Samples: []prompb.Sample{
954+
{Value: 0, Timestamp: convertTimeStamp(ts)},
955+
},
956+
},
957+
}
958+
},
959+
},
874960
}
875961
for _, tt := range tests {
876962
t.Run(tt.name, func(t *testing.T) {
963+
oldValue := exportCreatedMetricGate.IsEnabled()
964+
testutil.SetFeatureGateForTest(t, exportCreatedMetricGate, tt.isGateEnabled)
965+
defer testutil.SetFeatureGateForTest(t, exportCreatedMetricGate, oldValue)
966+
877967
metric := tt.metric()
878968
converter := newPrometheusConverter()
879969

0 commit comments

Comments
 (0)