Skip to content

Commit

Permalink
update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
pokgak committed Nov 8, 2024
1 parent 01085c4 commit 964ef73
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
8 changes: 0 additions & 8 deletions exporter/prometheusremotewriteexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/translator/prometheusremotewrite/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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/common v0.112.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.18.0
go.opentelemetry.io/collector/pdata v1.18.0
go.opentelemetry.io/collector/semconv v0.112.0
go.uber.org/goleak v1.3.0
Expand All @@ -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.18.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
Expand Down
10 changes: 9 additions & 1 deletion pkg/translator/prometheusremotewrite/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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())
}
Expand Down
18 changes: 13 additions & 5 deletions pkg/translator/prometheusremotewrite/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 964ef73

Please sign in to comment.