Skip to content

Commit cbde22c

Browse files
author
Hardik Shingala
committed
Revert "[pkg/translator/prometheus] Switch NormalizeName FG back to alpha (open-telemetry#23229)"
This reverts commit 47b208f.
1 parent ab1dbd4 commit cbde22c

12 files changed

+134
-158
lines changed

exporter/prometheusexporter/collector_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,6 @@ func TestCollectMetrics(t *testing.T) {
448448
continue
449449
}
450450

451-
require.Contains(t, m.Desc().String(), "fqName: \"test_space_test_metric\"")
452451
require.Regexp(t, `variableLabels: \[.*label_1.+label_2.+job.+instance.*\]`, m.Desc().String())
453452

454453
pbMetric := io_prometheus_client.Metric{}
@@ -467,11 +466,13 @@ func TestCollectMetrics(t *testing.T) {
467466

468467
switch tt.metricType {
469468
case prometheus.CounterValue:
469+
require.Contains(t, m.Desc().String(), "fqName: \"test_space_test_metric_total\"")
470470
require.Equal(t, tt.value, *pbMetric.Counter.Value)
471471
require.Nil(t, pbMetric.Gauge)
472472
require.Nil(t, pbMetric.Histogram)
473473
require.Nil(t, pbMetric.Summary)
474474
case prometheus.GaugeValue:
475+
require.Contains(t, m.Desc().String(), "fqName: \"test_space_test_metric\"")
475476
require.Equal(t, tt.value, *pbMetric.Gauge.Value)
476477
require.Nil(t, pbMetric.Counter)
477478
require.Nil(t, pbMetric.Histogram)

exporter/prometheusexporter/prometheus_test.go

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ func TestPrometheusExporter_WithTLS(t *testing.T) {
160160
_ = rsp.Body.Close()
161161

162162
want := []string{
163-
`# HELP test_counter_int`,
164-
`# TYPE test_counter_int counter`,
165-
`test_counter_int{code2="one2",foo2="bar2",label_1="label-value-1",resource_attr="resource-attr-val-1"} 123 1581452773000`,
166-
`test_counter_int{code2="one2",foo2="bar2",label_2="label-value-2",resource_attr="resource-attr-val-1"} 456 1581452773000`,
163+
`# HELP test_counter_int_total`,
164+
`# TYPE test_counter_int_total counter`,
165+
`test_counter_int_total{code2="one2",foo2="bar2",label_1="label-value-1",resource_attr="resource-attr-val-1"} 123 1581452773000`,
166+
`test_counter_int_total{code2="one2",foo2="bar2",label_2="label-value-2",resource_attr="resource-attr-val-1"} 456 1581452773000`,
167167
}
168168

169169
for _, w := range want {
@@ -220,18 +220,18 @@ func TestPrometheusExporter_endToEndMultipleTargets(t *testing.T) {
220220
blob, _ := io.ReadAll(res.Body)
221221
_ = res.Body.Close()
222222
want := []string{
223-
`# HELP test_metric_1_this_one_there_where Extra ones`,
224-
`# TYPE test_metric_1_this_one_there_where counter`,
225-
fmt.Sprintf(`test_metric_1_this_one_there_where{arch="x86",code1="one1",foo1="bar1",instance="localhost:8080",job="cpu-exporter",os="windows"} %v`, 99+128),
226-
fmt.Sprintf(`test_metric_1_this_one_there_where{arch="x86",code1="one1",foo1="bar1",instance="localhost:8080",job="cpu-exporter",os="linux"} %v`, 100+128),
227-
fmt.Sprintf(`test_metric_1_this_one_there_where{arch="x86",code1="one1",foo1="bar1",instance="localhost:8081",job="cpu-exporter",os="windows"} %v`, 99+128),
228-
fmt.Sprintf(`test_metric_1_this_one_there_where{arch="x86",code1="one1",foo1="bar1",instance="localhost:8081",job="cpu-exporter",os="linux"} %v`, 100+128),
229-
`# HELP test_metric_2_this_one_there_where Extra ones`,
230-
`# TYPE test_metric_2_this_one_there_where counter`,
231-
fmt.Sprintf(`test_metric_2_this_one_there_where{arch="x86",code1="one1",foo1="bar1",instance="localhost:8080",job="cpu-exporter",os="windows"} %v`, 99+delta),
232-
fmt.Sprintf(`test_metric_2_this_one_there_where{arch="x86",code1="one1",foo1="bar1",instance="localhost:8080",job="cpu-exporter",os="linux"} %v`, 100+delta),
233-
fmt.Sprintf(`test_metric_2_this_one_there_where{arch="x86",code1="one1",foo1="bar1",instance="localhost:8081",job="cpu-exporter",os="windows"} %v`, 99+delta),
234-
fmt.Sprintf(`test_metric_2_this_one_there_where{arch="x86",code1="one1",foo1="bar1",instance="localhost:8081",job="cpu-exporter",os="linux"} %v`, 100+delta),
223+
`# HELP test_metric_1_this_one_there_where_total Extra ones`,
224+
`# TYPE test_metric_1_this_one_there_where_total counter`,
225+
fmt.Sprintf(`test_metric_1_this_one_there_where_total{arch="x86",code1="one1",foo1="bar1",instance="localhost:8080",job="cpu-exporter",os="windows"} %v`, 99+128),
226+
fmt.Sprintf(`test_metric_1_this_one_there_where_total{arch="x86",code1="one1",foo1="bar1",instance="localhost:8080",job="cpu-exporter",os="linux"} %v`, 100+128),
227+
fmt.Sprintf(`test_metric_1_this_one_there_where_total{arch="x86",code1="one1",foo1="bar1",instance="localhost:8081",job="cpu-exporter",os="windows"} %v`, 99+128),
228+
fmt.Sprintf(`test_metric_1_this_one_there_where_total{arch="x86",code1="one1",foo1="bar1",instance="localhost:8081",job="cpu-exporter",os="linux"} %v`, 100+128),
229+
`# HELP test_metric_2_this_one_there_where_total Extra ones`,
230+
`# TYPE test_metric_2_this_one_there_where_total counter`,
231+
fmt.Sprintf(`test_metric_2_this_one_there_where_total{arch="x86",code1="one1",foo1="bar1",instance="localhost:8080",job="cpu-exporter",os="windows"} %v`, 99+delta),
232+
fmt.Sprintf(`test_metric_2_this_one_there_where_total{arch="x86",code1="one1",foo1="bar1",instance="localhost:8080",job="cpu-exporter",os="linux"} %v`, 100+delta),
233+
fmt.Sprintf(`test_metric_2_this_one_there_where_total{arch="x86",code1="one1",foo1="bar1",instance="localhost:8081",job="cpu-exporter",os="windows"} %v`, 99+delta),
234+
fmt.Sprintf(`test_metric_2_this_one_there_where_total{arch="x86",code1="one1",foo1="bar1",instance="localhost:8081",job="cpu-exporter",os="linux"} %v`, 100+delta),
235235
}
236236

237237
for _, w := range want {
@@ -300,14 +300,14 @@ func TestPrometheusExporter_endToEnd(t *testing.T) {
300300
blob, _ := io.ReadAll(res.Body)
301301
_ = res.Body.Close()
302302
want := []string{
303-
`# HELP test_metric_1_this_one_there_where Extra ones`,
304-
`# TYPE test_metric_1_this_one_there_where counter`,
305-
fmt.Sprintf(`test_metric_1_this_one_there_where{arch="x86",code1="one1",foo1="bar1",instance="localhost:8080",job="cpu-exporter",os="windows"} %v`, 99+128),
306-
fmt.Sprintf(`test_metric_1_this_one_there_where{arch="x86",code1="one1",foo1="bar1",instance="localhost:8080",job="cpu-exporter",os="linux"} %v`, 100+128),
307-
`# HELP test_metric_2_this_one_there_where Extra ones`,
308-
`# TYPE test_metric_2_this_one_there_where counter`,
309-
fmt.Sprintf(`test_metric_2_this_one_there_where{arch="x86",code1="one1",foo1="bar1",instance="localhost:8080",job="cpu-exporter",os="windows"} %v`, 99+delta),
310-
fmt.Sprintf(`test_metric_2_this_one_there_where{arch="x86",code1="one1",foo1="bar1",instance="localhost:8080",job="cpu-exporter",os="linux"} %v`, 100+delta),
303+
`# HELP test_metric_1_this_one_there_where_total Extra ones`,
304+
`# TYPE test_metric_1_this_one_there_where_total counter`,
305+
fmt.Sprintf(`test_metric_1_this_one_there_where_total{arch="x86",code1="one1",foo1="bar1",instance="localhost:8080",job="cpu-exporter",os="windows"} %v`, 99+128),
306+
fmt.Sprintf(`test_metric_1_this_one_there_where_total{arch="x86",code1="one1",foo1="bar1",instance="localhost:8080",job="cpu-exporter",os="linux"} %v`, 100+128),
307+
`# HELP test_metric_2_this_one_there_where_total Extra ones`,
308+
`# TYPE test_metric_2_this_one_there_where_total counter`,
309+
fmt.Sprintf(`test_metric_2_this_one_there_where_total{arch="x86",code1="one1",foo1="bar1",instance="localhost:8080",job="cpu-exporter",os="windows"} %v`, 99+delta),
310+
fmt.Sprintf(`test_metric_2_this_one_there_where_total{arch="x86",code1="one1",foo1="bar1",instance="localhost:8080",job="cpu-exporter",os="linux"} %v`, 100+delta),
311311
}
312312

313313
for _, w := range want {
@@ -377,14 +377,14 @@ func TestPrometheusExporter_endToEndWithTimestamps(t *testing.T) {
377377
blob, _ := io.ReadAll(res.Body)
378378
_ = res.Body.Close()
379379
want := []string{
380-
`# HELP test_metric_1_this_one_there_where Extra ones`,
381-
`# TYPE test_metric_1_this_one_there_where counter`,
382-
fmt.Sprintf(`test_metric_1_this_one_there_where{arch="x86",code2="one2",foo2="bar2",instance="localhost:8080",job="node-exporter",os="windows"} %v %v`, 99+128, 1543160298100+128000),
383-
fmt.Sprintf(`test_metric_1_this_one_there_where{arch="x86",code2="one2",foo2="bar2",instance="localhost:8080",job="node-exporter",os="linux"} %v %v`, 100+128, 1543160298100),
384-
`# HELP test_metric_2_this_one_there_where Extra ones`,
385-
`# TYPE test_metric_2_this_one_there_where counter`,
386-
fmt.Sprintf(`test_metric_2_this_one_there_where{arch="x86",code2="one2",foo2="bar2",instance="localhost:8080",job="node-exporter",os="windows"} %v %v`, 99+delta, 1543160298100+delta*1000),
387-
fmt.Sprintf(`test_metric_2_this_one_there_where{arch="x86",code2="one2",foo2="bar2",instance="localhost:8080",job="node-exporter",os="linux"} %v %v`, 100+delta, 1543160298100),
380+
`# HELP test_metric_1_this_one_there_where_total Extra ones`,
381+
`# TYPE test_metric_1_this_one_there_where_total counter`,
382+
fmt.Sprintf(`test_metric_1_this_one_there_where_total{arch="x86",code2="one2",foo2="bar2",instance="localhost:8080",job="node-exporter",os="windows"} %v %v`, 99+128, 1543160298100+128000),
383+
fmt.Sprintf(`test_metric_1_this_one_there_where_total{arch="x86",code2="one2",foo2="bar2",instance="localhost:8080",job="node-exporter",os="linux"} %v %v`, 100+128, 1543160298100),
384+
`# HELP test_metric_2_this_one_there_where_total Extra ones`,
385+
`# TYPE test_metric_2_this_one_there_where_total counter`,
386+
fmt.Sprintf(`test_metric_2_this_one_there_where_total{arch="x86",code2="one2",foo2="bar2",instance="localhost:8080",job="node-exporter",os="windows"} %v %v`, 99+delta, 1543160298100+delta*1000),
387+
fmt.Sprintf(`test_metric_2_this_one_there_where_total{arch="x86",code2="one2",foo2="bar2",instance="localhost:8080",job="node-exporter",os="linux"} %v %v`, 100+delta, 1543160298100),
388388
}
389389

390390
for _, w := range want {
@@ -457,10 +457,10 @@ func TestPrometheusExporter_endToEndWithResource(t *testing.T) {
457457
_ = rsp.Body.Close()
458458

459459
want := []string{
460-
`# HELP test_counter_int`,
461-
`# TYPE test_counter_int counter`,
462-
`test_counter_int{code2="one2",foo2="bar2",label_1="label-value-1",resource_attr="resource-attr-val-1"} 123 1581452773000`,
463-
`test_counter_int{code2="one2",foo2="bar2",label_2="label-value-2",resource_attr="resource-attr-val-1"} 456 1581452773000`,
460+
`# HELP test_counter_int_total`,
461+
`# TYPE test_counter_int_total counter`,
462+
`test_counter_int_total{code2="one2",foo2="bar2",label_1="label-value-1",resource_attr="resource-attr-val-1"} 123 1581452773000`,
463+
`test_counter_int_total{code2="one2",foo2="bar2",label_2="label-value-2",resource_attr="resource-attr-val-1"} 456 1581452773000`,
464464
}
465465

466466
for _, w := range want {

pkg/translator/prometheus/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
> **Warning**
1414
>
15-
> This feature can be enabled with [feature gate](https://github.com/open-telemetry/opentelemetry-collector/tree/main/featuregate) `pkg.translator.prometheus.NormalizeName`. It is disabled by default (alpha stage).
15+
> This feature can be disabled with [feature gate](https://github.com/open-telemetry/opentelemetry-collector/tree/main/featuregate) `pkg.translator.prometheus.NormalizeName`. It is enabled by default (beta stage).
1616
>
1717
> ```shell-session
18-
> $ otelcol --config=config.yaml --feature-gates=pkg.translator.prometheus.NormalizeName
18+
> $ otelcol --config=config.yaml --feature-gates=-pkg.translator.prometheus.NormalizeName
1919
> ```
2020
2121
#### List of transformations to convert OpenTelemetry metrics to Prometheus metrics

pkg/translator/prometheus/normalize_name.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var perUnitMap = map[string]string{
7373

7474
var normalizeNameGate = featuregate.GlobalRegistry().MustRegister(
7575
"pkg.translator.prometheus.NormalizeName",
76-
featuregate.StageAlpha,
76+
featuregate.StageBeta,
7777
featuregate.WithRegisterDescription("Controls whether metrics names are automatically normalized to follow Prometheus naming convention"),
7878
featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/8950"),
7979
)

pkg/translator/prometheus/normalize_name_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,7 @@ func TestOtelReceivers(t *testing.T) {
139139
}
140140

141141
func TestTrimPromSuffixes(t *testing.T) {
142-
registry := featuregate.NewRegistry()
143-
_, err := registry.Register(normalizeNameGate.ID(), featuregate.StageBeta)
144-
require.NoError(t, err)
145-
normalizer := NewNormalizer(registry)
142+
normalizer := NewNormalizer(featuregate.NewRegistry())
146143

147144
assert.Equal(t, "active_directory_ds_replication_network_io", normalizer.TrimPromSuffixes("active_directory_ds_replication_network_io_bytes_total", pmetric.MetricTypeSum, "bytes"))
148145
assert.Equal(t, "active_directory_ds_name_cache_hit_rate", normalizer.TrimPromSuffixes("active_directory_ds_name_cache_hit_rate_percent", pmetric.MetricTypeGauge, "percent"))
@@ -175,7 +172,10 @@ func TestTrimPromSuffixes(t *testing.T) {
175172
}
176173

177174
func TestTrimPromSuffixesWithFeatureGateDisabled(t *testing.T) {
178-
normalizer := NewNormalizer(featuregate.NewRegistry())
175+
registry := featuregate.NewRegistry()
176+
_, err := registry.Register(normalizeNameGate.ID(), featuregate.StageAlpha)
177+
require.NoError(t, err)
178+
normalizer := NewNormalizer(registry)
179179

180180
assert.Equal(t, "apache_current_connections", normalizer.TrimPromSuffixes("apache_current_connections", pmetric.MetricTypeGauge, "connections"))
181181
assert.Equal(t, "apache_requests_total", normalizer.TrimPromSuffixes("apache_requests_total", pmetric.MetricTypeSum, "1"))

pkg/translator/prometheusremotewrite/number_data_points_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ func TestAddSingleSumNumberDataPoint(t *testing.T) {
147147
},
148148
want: func() map[string]*prompb.TimeSeries {
149149
labels := []prompb.Label{
150-
{Name: model.MetricNameLabel, Value: "test_sum"},
150+
{Name: model.MetricNameLabel, Value: "test_sum_total"},
151151
}
152152
createdLabels := []prompb.Label{
153-
{Name: model.MetricNameLabel, Value: "test_sum" + createdSuffix},
153+
{Name: model.MetricNameLabel, Value: "test_sum_total" + createdSuffix},
154154
}
155155
return map[string]*prompb.TimeSeries{
156156
timeSeriesSignature(pmetric.MetricTypeSum.String(), &labels): {
@@ -183,7 +183,7 @@ func TestAddSingleSumNumberDataPoint(t *testing.T) {
183183
},
184184
want: func() map[string]*prompb.TimeSeries {
185185
labels := []prompb.Label{
186-
{Name: model.MetricNameLabel, Value: "test_sum"},
186+
{Name: model.MetricNameLabel, Value: "test_sum_total"},
187187
}
188188
return map[string]*prompb.TimeSeries{
189189
timeSeriesSignature(pmetric.MetricTypeSum.String(), &labels): {

receiver/prometheusreceiver/metrics_receiver_helper_test.go

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ type testData struct {
108108
pages []mockPrometheusResponse
109109
attributes pcommon.Map
110110
validateScrapes bool
111-
normalizedName bool
112111
validateFunc func(t *testing.T, td *testData, result []pmetric.ResourceMetrics)
113112
}
114113

@@ -223,13 +222,13 @@ func metricsCount(resourceMetric pmetric.ResourceMetrics) int {
223222
return metricsCount
224223
}
225224

226-
func getValidScrapes(t *testing.T, rms []pmetric.ResourceMetrics, normalizedNames bool) []pmetric.ResourceMetrics {
225+
func getValidScrapes(t *testing.T, rms []pmetric.ResourceMetrics) []pmetric.ResourceMetrics {
227226
var out []pmetric.ResourceMetrics
228227
// rms will include failed scrapes and scrapes that received no metrics but have internal scrape metrics, filter those out
229228
for i := 0; i < len(rms); i++ {
230229
allMetrics := getMetrics(rms[i])
231-
if expectedScrapeMetricCount < len(allMetrics) && countScrapeMetrics(allMetrics, normalizedNames) == expectedScrapeMetricCount {
232-
if isFirstFailedScrape(allMetrics, normalizedNames) {
230+
if expectedScrapeMetricCount < len(allMetrics) && countScrapeMetrics(allMetrics) == expectedScrapeMetricCount {
231+
if isFirstFailedScrape(allMetrics) {
233232
continue
234233
}
235234
assertUp(t, 1, allMetrics)
@@ -241,7 +240,7 @@ func getValidScrapes(t *testing.T, rms []pmetric.ResourceMetrics, normalizedName
241240
return out
242241
}
243242

244-
func isFirstFailedScrape(metrics []pmetric.Metric, normalizedNames bool) bool {
243+
func isFirstFailedScrape(metrics []pmetric.Metric) bool {
245244
for _, m := range metrics {
246245
if m.Name() == "up" {
247246
if m.Gauge().DataPoints().At(0).DoubleValue() == 1 { // assumed up will not have multiple datapoints
@@ -251,7 +250,7 @@ func isFirstFailedScrape(metrics []pmetric.Metric, normalizedNames bool) bool {
251250
}
252251

253252
for _, m := range metrics {
254-
if isDefaultMetrics(m, normalizedNames) {
253+
if isDefaultMetrics(m) {
255254
continue
256255
}
257256

@@ -295,43 +294,37 @@ func assertUp(t *testing.T, expected float64, metrics []pmetric.Metric) {
295294
t.Error("No 'up' metric found")
296295
}
297296

298-
func countScrapeMetricsRM(got pmetric.ResourceMetrics, normalizedNames bool) int {
297+
func countScrapeMetricsRM(got pmetric.ResourceMetrics) int {
299298
n := 0
300299
ilms := got.ScopeMetrics()
301300
for j := 0; j < ilms.Len(); j++ {
302301
ilm := ilms.At(j)
303302
for i := 0; i < ilm.Metrics().Len(); i++ {
304-
if isDefaultMetrics(ilm.Metrics().At(i), normalizedNames) {
303+
if isDefaultMetrics(ilm.Metrics().At(i)) {
305304
n++
306305
}
307306
}
308307
}
309308
return n
310309
}
311310

312-
func countScrapeMetrics(metrics []pmetric.Metric, normalizedNames bool) int {
311+
func countScrapeMetrics(metrics []pmetric.Metric) int {
313312
n := 0
314313
for _, m := range metrics {
315-
if isDefaultMetrics(m, normalizedNames) {
314+
if isDefaultMetrics(m) {
316315
n++
317316
}
318317
}
319318
return n
320319
}
321320

322-
func isDefaultMetrics(m pmetric.Metric, normalizedNames bool) bool {
321+
func isDefaultMetrics(m pmetric.Metric) bool {
323322
switch m.Name() {
324-
case "up", "scrape_samples_scraped", "scrape_samples_post_metric_relabeling", "scrape_series_added":
323+
case "up", "scrape_samples_scraped", "scrape_samples_post_metric_relabeling", "scrape_series_added", "scrape_duration":
325324
return true
326-
327-
// if normalizedNames is true, we expect unit `_seconds` to be trimmed.
328-
case "scrape_duration_seconds":
329-
return !normalizedNames
330-
case "scrape_duration":
331-
return normalizedNames
332325
default:
326+
return false
333327
}
334-
return false
335328
}
336329

337330
type metricTypeComparator func(*testing.T, pmetric.Metric)
@@ -348,12 +341,8 @@ type dataPointExpectation struct {
348341
type testExpectation func(*testing.T, pmetric.ResourceMetrics)
349342

350343
func doCompare(t *testing.T, name string, want pcommon.Map, got pmetric.ResourceMetrics, expectations []testExpectation) {
351-
doCompareNormalized(t, name, want, got, expectations, false)
352-
}
353-
354-
func doCompareNormalized(t *testing.T, name string, want pcommon.Map, got pmetric.ResourceMetrics, expectations []testExpectation, normalizedNames bool) {
355344
t.Run(name, func(t *testing.T) {
356-
assert.Equal(t, expectedScrapeMetricCount, countScrapeMetricsRM(got, normalizedNames))
345+
assert.Equal(t, expectedScrapeMetricCount, countScrapeMetricsRM(got))
357346
assert.Equal(t, want.Len(), got.Resource().Attributes().Len())
358347
for k, v := range want.AsRaw() {
359348
val, ok := got.Resource().Attributes().Get(k)
@@ -628,7 +617,7 @@ func testComponent(t *testing.T, targets []*testData, useStartTimeMetric bool, s
628617
}
629618
scrapes := pResults[name]
630619
if !target.validateScrapes {
631-
scrapes = getValidScrapes(t, pResults[name], target.normalizedName)
620+
scrapes = getValidScrapes(t, pResults[name])
632621
}
633622
target.validateFunc(t, target, scrapes)
634623
})

0 commit comments

Comments
 (0)