Skip to content

Commit 207b687

Browse files
dmitryaxCaleb-Hurshman
authored andcommitted
[pkg/translator/prometheus] Switch NormalizeName FG back to alpha (open-telemetry#23229)
Disable `pkg.translator.prometheus.NormalizeName` feature gate by default The feature gate `pkg.translator.prometheus.NormalizeName` was enabled prematurely while translation on the prometheus receiver was incomplete. To address this, the feature gate has been reverted back to alpha status. This will remain the case until the translation on the receiver side aligns with the translation on the exporter side, or until it is replaced with a configuration option or completely removed. To maintain the current behavior, you can enable the feature gate using the `--feature-gates=pkg.translator.prometheus.NormalizeName` command argument. However, please note that the translation in the prometheus receiver is a subject to future changes.
1 parent 5a2e810 commit 207b687

13 files changed

+180
-134
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: breaking
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
5+
component: prometheusreceiver, prometheusexporter, prometheusremotewrite
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Disable `pkg.translator.prometheus.NormalizeName` feature gate by default
9+
10+
# One or more tracking issues related to the change
11+
issues: [23208]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext: |
17+
The feature gate `pkg.translator.prometheus.NormalizeName` was enabled prematurely while translation
18+
on the prometheus receiver was incomplete. To address this, the feature gate has been reverted back to alpha status.
19+
This will remain the case until the translation on the receiver side aligns with the translation on the exporter side,
20+
or until it is replaced with a configuration option or completely removed. To maintain the current behavior, you can
21+
enable the feature gate using the `--feature-gates=pkg.translator.prometheus.NormalizeName` command argument.
22+
However, please note that the translation in the prometheus receiver is a subject to future changes.

exporter/prometheusexporter/collector_test.go

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

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

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

467468
switch tt.metricType {
468469
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\"")
476475
require.Equal(t, tt.value, *pbMetric.Gauge.Value)
477476
require.Nil(t, pbMetric.Counter)
478477
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_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`,
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`,
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_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),
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),
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_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),
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),
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_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),
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),
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_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`,
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`,
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 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).
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).
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.StageBeta,
76+
featuregate.StageAlpha,
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,7 +139,10 @@ func TestOtelReceivers(t *testing.T) {
139139
}
140140

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

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

174177
func TestTrimPromSuffixesWithFeatureGateDisabled(t *testing.T) {
175-
registry := featuregate.NewRegistry()
176-
_, err := registry.Register(normalizeNameGate.ID(), featuregate.StageAlpha)
177-
require.NoError(t, err)
178-
normalizer := NewNormalizer(registry)
178+
normalizer := NewNormalizer(featuregate.NewRegistry())
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_total"},
150+
{Name: model.MetricNameLabel, Value: "test_sum"},
151151
}
152152
createdLabels := []prompb.Label{
153-
{Name: model.MetricNameLabel, Value: "test_sum_total" + createdSuffix},
153+
{Name: model.MetricNameLabel, Value: "test_sum" + 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_total"},
186+
{Name: model.MetricNameLabel, Value: "test_sum"},
187187
}
188188
return map[string]*prompb.TimeSeries{
189189
timeSeriesSignature(pmetric.MetricTypeSum.String(), &labels): {

receiver/prometheusreceiver/metrics_receiver_helper_test.go

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

@@ -222,13 +223,13 @@ func metricsCount(resourceMetric pmetric.ResourceMetrics) int {
222223
return metricsCount
223224
}
224225

225-
func getValidScrapes(t *testing.T, rms []pmetric.ResourceMetrics) []pmetric.ResourceMetrics {
226+
func getValidScrapes(t *testing.T, rms []pmetric.ResourceMetrics, normalizedNames bool) []pmetric.ResourceMetrics {
226227
var out []pmetric.ResourceMetrics
227228
// rms will include failed scrapes and scrapes that received no metrics but have internal scrape metrics, filter those out
228229
for i := 0; i < len(rms); i++ {
229230
allMetrics := getMetrics(rms[i])
230-
if expectedScrapeMetricCount < len(allMetrics) && countScrapeMetrics(allMetrics) == expectedScrapeMetricCount {
231-
if isFirstFailedScrape(allMetrics) {
231+
if expectedScrapeMetricCount < len(allMetrics) && countScrapeMetrics(allMetrics, normalizedNames) == expectedScrapeMetricCount {
232+
if isFirstFailedScrape(allMetrics, normalizedNames) {
232233
continue
233234
}
234235
assertUp(t, 1, allMetrics)
@@ -240,7 +241,7 @@ func getValidScrapes(t *testing.T, rms []pmetric.ResourceMetrics) []pmetric.Reso
240241
return out
241242
}
242243

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

252253
for _, m := range metrics {
253-
if isDefaultMetrics(m) {
254+
if isDefaultMetrics(m, normalizedNames) {
254255
continue
255256
}
256257

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

297-
func countScrapeMetricsRM(got pmetric.ResourceMetrics) int {
298+
func countScrapeMetricsRM(got pmetric.ResourceMetrics, normalizedNames bool) int {
298299
n := 0
299300
ilms := got.ScopeMetrics()
300301
for j := 0; j < ilms.Len(); j++ {
301302
ilm := ilms.At(j)
302303
for i := 0; i < ilm.Metrics().Len(); i++ {
303-
if isDefaultMetrics(ilm.Metrics().At(i)) {
304+
if isDefaultMetrics(ilm.Metrics().At(i), normalizedNames) {
304305
n++
305306
}
306307
}
307308
}
308309
return n
309310
}
310311

311-
func countScrapeMetrics(metrics []pmetric.Metric) int {
312+
func countScrapeMetrics(metrics []pmetric.Metric, normalizedNames bool) int {
312313
n := 0
313314
for _, m := range metrics {
314-
if isDefaultMetrics(m) {
315+
if isDefaultMetrics(m, normalizedNames) {
315316
n++
316317
}
317318
}
318319
return n
319320
}
320321

321-
func isDefaultMetrics(m pmetric.Metric) bool {
322+
func isDefaultMetrics(m pmetric.Metric, normalizedNames bool) bool {
322323
switch m.Name() {
323-
case "up", "scrape_samples_scraped", "scrape_samples_post_metric_relabeling", "scrape_series_added", "scrape_duration":
324+
case "up", "scrape_samples_scraped", "scrape_samples_post_metric_relabeling", "scrape_series_added":
324325
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
325332
default:
326-
return false
327333
}
334+
return false
328335
}
329336

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

343350
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) {
344355
t.Run(name, func(t *testing.T) {
345-
assert.Equal(t, expectedScrapeMetricCount, countScrapeMetricsRM(got))
356+
assert.Equal(t, expectedScrapeMetricCount, countScrapeMetricsRM(got, normalizedNames))
346357
assert.Equal(t, want.Len(), got.Resource().Attributes().Len())
347358
for k, v := range want.AsRaw() {
348359
val, ok := got.Resource().Attributes().Get(k)
@@ -617,7 +628,7 @@ func testComponent(t *testing.T, targets []*testData, useStartTimeMetric bool, s
617628
}
618629
scrapes := pResults[name]
619630
if !target.validateScrapes {
620-
scrapes = getValidScrapes(t, pResults[name])
631+
scrapes = getValidScrapes(t, pResults[name], target.normalizedName)
621632
}
622633
target.validateFunc(t, target, scrapes)
623634
})

0 commit comments

Comments
 (0)