From 0e3b184d09e8cb86601336783b5192c07031bfc1 Mon Sep 17 00:00:00 2001 From: Aiman Ismail Date: Tue, 5 Nov 2024 22:49:22 +0800 Subject: [PATCH 1/9] [exporter/prometheusremotewrite] deprecate export_created_metric --- ...35003-deprecate-export_created_metric.yaml | 25 +++++++++++++++++++ .../prometheusremotewriteexporter/README.md | 2 +- .../prometheusremotewriteexporter/config.go | 1 + .../prometheusremotewriteexporter/exporter.go | 4 +++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .chloggen/35003-deprecate-export_created_metric.yaml diff --git a/.chloggen/35003-deprecate-export_created_metric.yaml b/.chloggen/35003-deprecate-export_created_metric.yaml new file mode 100644 index 000000000000..d50afa9a57f2 --- /dev/null +++ b/.chloggen/35003-deprecate-export_created_metric.yaml @@ -0,0 +1,25 @@ +# 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. otlpreceiver) +component: exporter/prometheusremotewrite + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: deprecate export_created metric + +# One or more tracking issues or pull requests related to the change +issues: [35003] + +# (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: + +# 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] diff --git a/exporter/prometheusremotewriteexporter/README.md b/exporter/prometheusremotewriteexporter/README.md index ce8be0ee280b..eedb2b6fa5df 100644 --- a/exporter/prometheusremotewriteexporter/README.md +++ b/exporter/prometheusremotewriteexporter/README.md @@ -59,7 +59,7 @@ The following settings can be optionally configured: - `enabled` (default = false): If `enabled` is `true`, all the resource attributes will be converted to metric labels by default. - `target_info`: customize `target_info` metric - `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). -- `export_created_metric`: +- `export_created_metric` (deprecated): - `enabled` (default = false): If `enabled` is `true`, a `_created` metric is exported for Summary, Histogram, and Monotonic Sum metric points if `StartTimeUnixNano` is set. diff --git a/exporter/prometheusremotewriteexporter/config.go b/exporter/prometheusremotewriteexporter/config.go index 6a6f449a93dd..21eb7397bad8 100644 --- a/exporter/prometheusremotewriteexporter/config.go +++ b/exporter/prometheusremotewriteexporter/config.go @@ -45,6 +45,7 @@ type Config struct { TargetInfo *TargetInfo `mapstructure:"target_info,omitempty"` // CreatedMetric allows customizing creation of _created metrics + // Deprecated: This feature is useless in PRWv1 and and PRWv2 already have the created timestamp in the proto CreatedMetric *CreatedMetric `mapstructure:"export_created_metric,omitempty"` // AddMetricSuffixes controls whether unit and type suffixes are added to metrics on export diff --git a/exporter/prometheusremotewriteexporter/exporter.go b/exporter/prometheusremotewriteexporter/exporter.go index aa4a58082416..806f3fd2a9f8 100644 --- a/exporter/prometheusremotewriteexporter/exporter.go +++ b/exporter/prometheusremotewriteexporter/exporter.go @@ -128,6 +128,10 @@ func newPRWExporter(cfg *Config, set exporter.Settings) (*prwExporter, error) { batchTimeSeriesState: newBatchTimeSericesState(), } + if prwe.exporterSettings.ExportCreatedMetric { + prwe.settings.Logger.Warn("export_created_metric is deprecated and will be removed in a future release") + } + prwe.wal = newWAL(cfg.WAL, prwe.export) return prwe, nil } From 810c2168b880567f46d123b337c442ed4ecda938 Mon Sep 17 00:00:00 2001 From: Aiman Ismail Date: Thu, 7 Nov 2024 12:42:23 +0800 Subject: [PATCH 2/9] Apply suggestions from code review Co-authored-by: Arthur Silva Sens --- .chloggen/35003-deprecate-export_created_metric.yaml | 2 +- exporter/prometheusremotewriteexporter/README.md | 2 +- exporter/prometheusremotewriteexporter/config.go | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.chloggen/35003-deprecate-export_created_metric.yaml b/.chloggen/35003-deprecate-export_created_metric.yaml index d50afa9a57f2..e5cce195bb93 100644 --- a/.chloggen/35003-deprecate-export_created_metric.yaml +++ b/.chloggen/35003-deprecate-export_created_metric.yaml @@ -7,7 +7,7 @@ change_type: deprecation component: exporter/prometheusremotewrite # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: deprecate export_created metric +note: Deprecate configuration option `export_created metric` # One or more tracking issues or pull requests related to the change issues: [35003] diff --git a/exporter/prometheusremotewriteexporter/README.md b/exporter/prometheusremotewriteexporter/README.md index eedb2b6fa5df..09a0f2feda7d 100644 --- a/exporter/prometheusremotewriteexporter/README.md +++ b/exporter/prometheusremotewriteexporter/README.md @@ -59,7 +59,7 @@ The following settings can be optionally configured: - `enabled` (default = false): If `enabled` is `true`, all the resource attributes will be converted to metric labels by default. - `target_info`: customize `target_info` metric - `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). -- `export_created_metric` (deprecated): +- `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. - `enabled` (default = false): If `enabled` is `true`, a `_created` metric is exported for Summary, Histogram, and Monotonic Sum metric points if `StartTimeUnixNano` is set. diff --git a/exporter/prometheusremotewriteexporter/config.go b/exporter/prometheusremotewriteexporter/config.go index 21eb7397bad8..23b8c5f1e4e3 100644 --- a/exporter/prometheusremotewriteexporter/config.go +++ b/exporter/prometheusremotewriteexporter/config.go @@ -45,7 +45,8 @@ type Config struct { TargetInfo *TargetInfo `mapstructure:"target_info,omitempty"` // CreatedMetric allows customizing creation of _created metrics - // Deprecated: This feature is useless in PRWv1 and and PRWv2 already have the created timestamp in the proto + // Deprecated[0.114.0]: The feature doesn't provide the expected behavior. Use Prometheus remote-write v2 to enable sending Created Timestamps. + // This feature is planned to be removed in v0.116.0 CreatedMetric *CreatedMetric `mapstructure:"export_created_metric,omitempty"` // AddMetricSuffixes controls whether unit and type suffixes are added to metrics on export From 69c57e305dbef33f22b0bde92df622f109d0ae41 Mon Sep 17 00:00:00 2001 From: Aiman Ismail Date: Thu, 7 Nov 2024 13:02:04 +0800 Subject: [PATCH 3/9] use feature gate to set default value --- exporter/prometheusremotewriteexporter/config.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/exporter/prometheusremotewriteexporter/config.go b/exporter/prometheusremotewriteexporter/config.go index 23b8c5f1e4e3..bd0d50e97cd7 100644 --- a/exporter/prometheusremotewriteexporter/config.go +++ b/exporter/prometheusremotewriteexporter/config.go @@ -10,6 +10,7 @@ import ( "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/configretry" "go.opentelemetry.io/collector/exporter/exporterhelper" + "go.opentelemetry.io/collector/featuregate" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry" ) @@ -85,6 +86,13 @@ type RemoteWriteQueue struct { var _ component.Config = (*Config)(nil) +var exportCreatedMetricGate = featuregate.GlobalRegistry().MustRegister( + "exporter.prometheusremotewriteexporter.exportCreatedMetric", + featuregate.StageBeta, + featuregate.WithRegisterDescription("Allow enabling the export_created_metric feature."), + featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35003"), +) + // Validate checks if the exporter configuration is valid func (cfg *Config) Validate() error { if cfg.RemoteWriteQueue.QueueSize < 0 { @@ -106,7 +114,7 @@ func (cfg *Config) Validate() error { } if cfg.CreatedMetric == nil { cfg.CreatedMetric = &CreatedMetric{ - Enabled: false, + Enabled: exportCreatedMetricGate.IsEnabled(), } } if cfg.MaxBatchSizeBytes < 0 { From 31f8a029edd63c7f4d2eb761a0797ddc90c2e365 Mon Sep 17 00:00:00 2001 From: Aiman Ismail Date: Thu, 7 Nov 2024 13:05:23 +0800 Subject: [PATCH 4/9] updated feature gate description --- exporter/prometheusremotewriteexporter/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporter/prometheusremotewriteexporter/config.go b/exporter/prometheusremotewriteexporter/config.go index bd0d50e97cd7..b408272fa657 100644 --- a/exporter/prometheusremotewriteexporter/config.go +++ b/exporter/prometheusremotewriteexporter/config.go @@ -89,7 +89,7 @@ var _ component.Config = (*Config)(nil) var exportCreatedMetricGate = featuregate.GlobalRegistry().MustRegister( "exporter.prometheusremotewriteexporter.exportCreatedMetric", featuregate.StageBeta, - featuregate.WithRegisterDescription("Allow enabling the export_created_metric feature."), + featuregate.WithRegisterDescription("Set the default value of the export_created_metric feature."), featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35003"), ) From 222332e77b9e8a414e4f5914ac90fcf208cf4c0b Mon Sep 17 00:00:00 2001 From: Aiman Ismail Date: Fri, 8 Nov 2024 16:55:12 +0800 Subject: [PATCH 5/9] Apply suggestions from code review Co-authored-by: Arthur Silva Sens --- exporter/prometheusremotewriteexporter/config.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exporter/prometheusremotewriteexporter/config.go b/exporter/prometheusremotewriteexporter/config.go index b408272fa657..fd5090b82c85 100644 --- a/exporter/prometheusremotewriteexporter/config.go +++ b/exporter/prometheusremotewriteexporter/config.go @@ -87,9 +87,9 @@ type RemoteWriteQueue struct { var _ component.Config = (*Config)(nil) var exportCreatedMetricGate = featuregate.GlobalRegistry().MustRegister( - "exporter.prometheusremotewriteexporter.exportCreatedMetric", + "exporter.prometheusremotewriteexporter.deprecateCreatedMetric", featuregate.StageBeta, - featuregate.WithRegisterDescription("Set the default value of the export_created_metric feature."), + featuregate.WithRegisterDescription("Feature gate used to control the deprecation of created metrics."), featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35003"), ) @@ -114,7 +114,7 @@ func (cfg *Config) Validate() error { } if cfg.CreatedMetric == nil { cfg.CreatedMetric = &CreatedMetric{ - Enabled: exportCreatedMetricGate.IsEnabled(), + Enabled: false, } } if cfg.MaxBatchSizeBytes < 0 { From 9a5c58737ecfb9b3f66d986af24eedcb0c44e9c9 Mon Sep 17 00:00:00 2001 From: Aiman Ismail Date: Fri, 8 Nov 2024 17:47:29 +0800 Subject: [PATCH 6/9] update test case --- .../prometheusremotewriteexporter/config.go | 8 -------- pkg/translator/prometheusremotewrite/go.mod | 7 ++++--- pkg/translator/prometheusremotewrite/helper.go | 10 +++++++++- .../prometheusremotewrite/helper_test.go | 18 +++++++++++++----- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/exporter/prometheusremotewriteexporter/config.go b/exporter/prometheusremotewriteexporter/config.go index fd5090b82c85..23b8c5f1e4e3 100644 --- a/exporter/prometheusremotewriteexporter/config.go +++ b/exporter/prometheusremotewriteexporter/config.go @@ -10,7 +10,6 @@ import ( "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/configretry" "go.opentelemetry.io/collector/exporter/exporterhelper" - "go.opentelemetry.io/collector/featuregate" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry" ) @@ -86,13 +85,6 @@ type RemoteWriteQueue struct { var _ component.Config = (*Config)(nil) -var exportCreatedMetricGate = featuregate.GlobalRegistry().MustRegister( - "exporter.prometheusremotewriteexporter.deprecateCreatedMetric", - featuregate.StageBeta, - featuregate.WithRegisterDescription("Feature gate used to control the deprecation of created metrics."), - featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35003"), -) - // Validate checks if the exporter configuration is valid func (cfg *Config) Validate() error { if cfg.RemoteWriteQueue.QueueSize < 0 { diff --git a/pkg/translator/prometheusremotewrite/go.mod b/pkg/translator/prometheusremotewrite/go.mod index f8ef0fa0e38f..a76d6762f9eb 100644 --- a/pkg/translator/prometheusremotewrite/go.mod +++ b/pkg/translator/prometheusremotewrite/go.mod @@ -5,11 +5,13 @@ go 1.22.0 require ( github.com/cespare/xxhash/v2 v2.3.0 github.com/google/go-cmp v0.6.0 - github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.113.0 - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.113.0 + github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.113.0 + github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.112.0 + github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.112.0 github.com/prometheus/common v0.60.1 github.com/prometheus/prometheus v0.54.1 github.com/stretchr/testify v1.9.0 + go.opentelemetry.io/collector/featuregate v1.19.0 go.opentelemetry.io/collector/pdata v1.19.0 go.opentelemetry.io/collector/semconv v0.113.0 go.uber.org/goleak v1.3.0 @@ -26,7 +28,6 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_model v0.6.1 // indirect - go.opentelemetry.io/collector/featuregate v1.19.0 // indirect golang.org/x/net v0.29.0 // indirect golang.org/x/sys v0.26.0 // indirect golang.org/x/text v0.19.0 // indirect diff --git a/pkg/translator/prometheusremotewrite/helper.go b/pkg/translator/prometheusremotewrite/helper.go index cb03a7c32959..640f14244b61 100644 --- a/pkg/translator/prometheusremotewrite/helper.go +++ b/pkg/translator/prometheusremotewrite/helper.go @@ -19,6 +19,7 @@ import ( "github.com/prometheus/prometheus/model/timestamp" "github.com/prometheus/prometheus/model/value" "github.com/prometheus/prometheus/prompb" + "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" conventions "go.opentelemetry.io/collector/semconv/v1.25.0" @@ -41,6 +42,13 @@ const ( infoType = "info" ) +var exportCreatedMetricGate = featuregate.GlobalRegistry().MustRegister( + "exporter.prometheusremotewriteexporter.deprecateCreatedMetric", + featuregate.StageBeta, + featuregate.WithRegisterDescription("Feature gate used to control the deprecation of created metrics."), + featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35003"), +) + type bucketBoundsData struct { ts *prompb.TimeSeries bound float64 @@ -429,7 +437,7 @@ func (c *prometheusConverter) addSummaryDataPoints(dataPoints pmetric.SummaryDat } startTimestamp := pt.StartTimestamp() - if settings.ExportCreatedMetric && startTimestamp != 0 { + if settings.ExportCreatedMetric && startTimestamp != 0 && exportCreatedMetricGate.IsEnabled() { createdLabels := createLabels(baseName+createdSuffix, baseLabels) c.addTimeSeriesIfNeeded(createdLabels, startTimestamp, pt.Timestamp()) } diff --git a/pkg/translator/prometheusremotewrite/helper_test.go b/pkg/translator/prometheusremotewrite/helper_test.go index 8894c0f7a27d..c912ade5d784 100644 --- a/pkg/translator/prometheusremotewrite/helper_test.go +++ b/pkg/translator/prometheusremotewrite/helper_test.go @@ -19,6 +19,7 @@ import ( "go.opentelemetry.io/collector/pdata/pmetric" conventions "go.opentelemetry.io/collector/semconv/v1.25.0" + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/testdata" prometheustranslator "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus" ) @@ -785,12 +786,14 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) { func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) { ts := pcommon.Timestamp(time.Now().UnixNano()) tests := []struct { - name string - metric func() pmetric.Metric - want func() map[uint64]*prompb.TimeSeries + name string + isGateEnabled bool + metric func() pmetric.Metric + want func() map[uint64]*prompb.TimeSeries }{ { - name: "histogram with start time", + name: "histogram with start time", + isGateEnabled: true, metric: func() pmetric.Metric { metric := pmetric.NewMetric() metric.SetName("test_hist") @@ -836,7 +839,8 @@ func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) { }, }, { - name: "histogram without start time", + name: "histogram without start time", + isGateEnabled: true, metric: func() pmetric.Metric { metric := pmetric.NewMetric() metric.SetName("test_hist") @@ -877,6 +881,10 @@ func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) { metric := tt.metric() converter := newPrometheusConverter() + oldValue := exportCreatedMetricGate.IsEnabled() + testutil.SetFeatureGateForTest(t, exportCreatedMetricGate, tt.isGateEnabled) + defer testutil.SetFeatureGateForTest(t, exportCreatedMetricGate, oldValue) + converter.addHistogramDataPoints( metric.Histogram().DataPoints(), pcommon.NewResource(), From f11490cb4b5b6bdec5e8f07858f0a3ac1d604058 Mon Sep 17 00:00:00 2001 From: Aiman Ismail Date: Sat, 9 Nov 2024 13:50:27 +0800 Subject: [PATCH 7/9] add test case for exportCreatedGate disabled --- .../prometheusremotewrite/helper.go | 2 +- .../prometheusremotewrite/helper_test.go | 98 +++++++++++++++++-- 2 files changed, 91 insertions(+), 9 deletions(-) diff --git a/pkg/translator/prometheusremotewrite/helper.go b/pkg/translator/prometheusremotewrite/helper.go index 640f14244b61..49b125a96b6a 100644 --- a/pkg/translator/prometheusremotewrite/helper.go +++ b/pkg/translator/prometheusremotewrite/helper.go @@ -282,7 +282,7 @@ func (c *prometheusConverter) addHistogramDataPoints(dataPoints pmetric.Histogra c.addExemplars(pt, bucketBounds) startTimestamp := pt.StartTimestamp() - if settings.ExportCreatedMetric && startTimestamp != 0 { + if settings.ExportCreatedMetric && startTimestamp != 0 && exportCreatedMetricGate.IsEnabled() { labels := createLabels(baseName+createdSuffix, baseLabels) c.addTimeSeriesIfNeeded(labels, startTimestamp, pt.Timestamp()) } diff --git a/pkg/translator/prometheusremotewrite/helper_test.go b/pkg/translator/prometheusremotewrite/helper_test.go index c912ade5d784..b94b2d909371 100644 --- a/pkg/translator/prometheusremotewrite/helper_test.go +++ b/pkg/translator/prometheusremotewrite/helper_test.go @@ -678,12 +678,14 @@ func TestMostRecentTimestampInMetric(t *testing.T) { func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) { ts := pcommon.Timestamp(time.Now().UnixNano()) tests := []struct { - name string - metric func() pmetric.Metric - want func() map[uint64]*prompb.TimeSeries + name string + isGateEnabled bool + metric func() pmetric.Metric + want func() map[uint64]*prompb.TimeSeries }{ { - name: "summary with start time", + name: "summary with start time", + isGateEnabled: true, metric: func() pmetric.Metric { metric := pmetric.NewMetric() metric.SetName("test_summary") @@ -728,7 +730,44 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) { }, }, { - name: "summary without start time", + name: "summary without start time", + isGateEnabled: true, + metric: func() pmetric.Metric { + metric := pmetric.NewMetric() + metric.SetName("test_summary") + metric.SetEmptySummary() + + dp := metric.Summary().DataPoints().AppendEmpty() + dp.SetTimestamp(ts) + + return metric + }, + want: func() map[uint64]*prompb.TimeSeries { + labels := []prompb.Label{ + {Name: model.MetricNameLabel, Value: "test_summary" + countStr}, + } + sumLabels := []prompb.Label{ + {Name: model.MetricNameLabel, Value: "test_summary" + sumStr}, + } + return map[uint64]*prompb.TimeSeries{ + timeSeriesSignature(labels): { + Labels: labels, + Samples: []prompb.Sample{ + {Value: 0, Timestamp: convertTimeStamp(ts)}, + }, + }, + timeSeriesSignature(sumLabels): { + Labels: sumLabels, + Samples: []prompb.Sample{ + {Value: 0, Timestamp: convertTimeStamp(ts)}, + }, + }, + } + }, + }, + { + name: "summary with exportCreatedMetricGate disabled", + isGateEnabled: false, metric: func() pmetric.Metric { metric := pmetric.NewMetric() metric.SetName("test_summary") @@ -736,6 +775,7 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) { dp := metric.Summary().DataPoints().AppendEmpty() dp.SetTimestamp(ts) + dp.SetStartTimestamp(ts) return metric }, @@ -765,6 +805,10 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + oldValue := exportCreatedMetricGate.IsEnabled() + testutil.SetFeatureGateForTest(t, exportCreatedMetricGate, tt.isGateEnabled) + defer testutil.SetFeatureGateForTest(t, exportCreatedMetricGate, oldValue) + metric := tt.metric() converter := newPrometheusConverter() @@ -875,16 +919,54 @@ func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) { } }, }, + { + name: "histogram with exportCreatedMetricGate disabled", + isGateEnabled: false, + metric: func() pmetric.Metric { + metric := pmetric.NewMetric() + metric.SetName("test_hist") + metric.SetEmptyHistogram().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) + + pt := metric.Histogram().DataPoints().AppendEmpty() + pt.SetTimestamp(ts) + pt.SetStartTimestamp(ts) + + return metric + }, + want: func() map[uint64]*prompb.TimeSeries { + labels := []prompb.Label{ + {Name: model.MetricNameLabel, Value: "test_hist" + countStr}, + } + infLabels := []prompb.Label{ + {Name: model.MetricNameLabel, Value: "test_hist_bucket"}, + {Name: model.BucketLabel, Value: "+Inf"}, + } + return map[uint64]*prompb.TimeSeries{ + timeSeriesSignature(infLabels): { + Labels: infLabels, + Samples: []prompb.Sample{ + {Value: 0, Timestamp: convertTimeStamp(ts)}, + }, + }, + timeSeriesSignature(labels): { + Labels: labels, + Samples: []prompb.Sample{ + {Value: 0, Timestamp: convertTimeStamp(ts)}, + }, + }, + } + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - metric := tt.metric() - converter := newPrometheusConverter() - oldValue := exportCreatedMetricGate.IsEnabled() testutil.SetFeatureGateForTest(t, exportCreatedMetricGate, tt.isGateEnabled) defer testutil.SetFeatureGateForTest(t, exportCreatedMetricGate, oldValue) + metric := tt.metric() + converter := newPrometheusConverter() + converter.addHistogramDataPoints( metric.Histogram().DataPoints(), pcommon.NewResource(), From 6ffc194558480b6b7c0532555a5106224c7754dc Mon Sep 17 00:00:00 2001 From: Aiman Ismail Date: Thu, 14 Nov 2024 01:23:17 +0800 Subject: [PATCH 8/9] Update .chloggen/35003-deprecate-export_created_metric.yaml Co-authored-by: David Ashpole --- .chloggen/35003-deprecate-export_created_metric.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/35003-deprecate-export_created_metric.yaml b/.chloggen/35003-deprecate-export_created_metric.yaml index e5cce195bb93..732e78854ae0 100644 --- a/.chloggen/35003-deprecate-export_created_metric.yaml +++ b/.chloggen/35003-deprecate-export_created_metric.yaml @@ -15,7 +15,7 @@ issues: [35003] # (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: +subtext: Disable the exporter.prometheusremotewriteexporter.deprecateCreatedMetric feature gate to temporarily re-enable the created metric. # Optional: The change log or logs in which this entry should be included. # e.g. '[user]' or '[user, api]' From 2806f5a1ab190012d0ddab85c831215f3f11fc3e Mon Sep 17 00:00:00 2001 From: Aiman Ismail Date: Thu, 14 Nov 2024 01:30:06 +0800 Subject: [PATCH 9/9] fix featuregate default to stage alpha --- pkg/translator/prometheusremotewrite/helper.go | 6 +++--- .../prometheusremotewrite/helper_test.go | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/translator/prometheusremotewrite/helper.go b/pkg/translator/prometheusremotewrite/helper.go index 49b125a96b6a..b96308a2ebac 100644 --- a/pkg/translator/prometheusremotewrite/helper.go +++ b/pkg/translator/prometheusremotewrite/helper.go @@ -44,7 +44,7 @@ const ( var exportCreatedMetricGate = featuregate.GlobalRegistry().MustRegister( "exporter.prometheusremotewriteexporter.deprecateCreatedMetric", - featuregate.StageBeta, + featuregate.StageAlpha, featuregate.WithRegisterDescription("Feature gate used to control the deprecation of created metrics."), featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35003"), ) @@ -282,7 +282,7 @@ func (c *prometheusConverter) addHistogramDataPoints(dataPoints pmetric.Histogra c.addExemplars(pt, bucketBounds) startTimestamp := pt.StartTimestamp() - if settings.ExportCreatedMetric && startTimestamp != 0 && exportCreatedMetricGate.IsEnabled() { + if settings.ExportCreatedMetric && startTimestamp != 0 && !exportCreatedMetricGate.IsEnabled() { labels := createLabels(baseName+createdSuffix, baseLabels) c.addTimeSeriesIfNeeded(labels, startTimestamp, pt.Timestamp()) } @@ -437,7 +437,7 @@ func (c *prometheusConverter) addSummaryDataPoints(dataPoints pmetric.SummaryDat } startTimestamp := pt.StartTimestamp() - if settings.ExportCreatedMetric && startTimestamp != 0 && exportCreatedMetricGate.IsEnabled() { + if settings.ExportCreatedMetric && startTimestamp != 0 && !exportCreatedMetricGate.IsEnabled() { createdLabels := createLabels(baseName+createdSuffix, baseLabels) c.addTimeSeriesIfNeeded(createdLabels, startTimestamp, pt.Timestamp()) } diff --git a/pkg/translator/prometheusremotewrite/helper_test.go b/pkg/translator/prometheusremotewrite/helper_test.go index b94b2d909371..12c0dcd978be 100644 --- a/pkg/translator/prometheusremotewrite/helper_test.go +++ b/pkg/translator/prometheusremotewrite/helper_test.go @@ -685,7 +685,7 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) { }{ { name: "summary with start time", - isGateEnabled: true, + isGateEnabled: false, metric: func() pmetric.Metric { metric := pmetric.NewMetric() metric.SetName("test_summary") @@ -731,7 +731,7 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) { }, { name: "summary without start time", - isGateEnabled: true, + isGateEnabled: false, metric: func() pmetric.Metric { metric := pmetric.NewMetric() metric.SetName("test_summary") @@ -766,8 +766,8 @@ func TestPrometheusConverter_AddSummaryDataPoints(t *testing.T) { }, }, { - name: "summary with exportCreatedMetricGate disabled", - isGateEnabled: false, + name: "summary with exportCreatedMetricGate enabled", + isGateEnabled: true, metric: func() pmetric.Metric { metric := pmetric.NewMetric() metric.SetName("test_summary") @@ -837,7 +837,7 @@ func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) { }{ { name: "histogram with start time", - isGateEnabled: true, + isGateEnabled: false, metric: func() pmetric.Metric { metric := pmetric.NewMetric() metric.SetName("test_hist") @@ -884,7 +884,7 @@ func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) { }, { name: "histogram without start time", - isGateEnabled: true, + isGateEnabled: false, metric: func() pmetric.Metric { metric := pmetric.NewMetric() metric.SetName("test_hist") @@ -920,8 +920,8 @@ func TestPrometheusConverter_AddHistogramDataPoints(t *testing.T) { }, }, { - name: "histogram with exportCreatedMetricGate disabled", - isGateEnabled: false, + name: "histogram with exportCreatedMetricGate enabled", + isGateEnabled: true, metric: func() pmetric.Metric { metric := pmetric.NewMetric() metric.SetName("test_hist")