Use getPrometheusName for Otel2PrometheusConverter map keys (#6308)
This commit is contained in:
parent
d7370f3367
commit
c8ca99c54e
|
|
@ -550,7 +550,7 @@ final class Otel2PrometheusConverter {
|
|||
|
||||
private static void putOrMerge(
|
||||
Map<String, MetricSnapshot> snapshotsByName, MetricSnapshot snapshot) {
|
||||
String name = snapshot.getMetadata().getName();
|
||||
String name = snapshot.getMetadata().getPrometheusName();
|
||||
if (snapshotsByName.containsKey(name)) {
|
||||
MetricSnapshot merged = merge(snapshotsByName.get(name), snapshot);
|
||||
if (merged != null) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.exporter.prometheus;
|
|||
|
||||
import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
|
||||
|
|
@ -108,6 +109,34 @@ class Otel2PrometheusConverterTest {
|
|||
assertThat(metricLabels).isEqualTo(expectedMetricLabels);
|
||||
}
|
||||
|
||||
@Test
|
||||
void prometheusNameCollisionTest_Issue6277() {
|
||||
// NOTE: Metrics with the same resolved prometheus name should merge. However,
|
||||
// Otel2PrometheusConverter is not responsible for merging individual series, so the merge will
|
||||
// fail if the two different metrics contain overlapping series. Users should deal with this by
|
||||
// adding a view that renames one of the two metrics such that the conflict does not occur.
|
||||
MetricData dotName =
|
||||
createSampleMetricData(
|
||||
"my.metric",
|
||||
"units",
|
||||
MetricDataType.LONG_SUM,
|
||||
Attributes.builder().put("key", "a").build(),
|
||||
Resource.create(Attributes.empty()));
|
||||
MetricData underscoreName =
|
||||
createSampleMetricData(
|
||||
"my_metric",
|
||||
"units",
|
||||
MetricDataType.LONG_SUM,
|
||||
Attributes.builder().put("key", "b").build(),
|
||||
Resource.create(Attributes.empty()));
|
||||
|
||||
List<MetricData> metricData = new ArrayList<>();
|
||||
metricData.add(dotName);
|
||||
metricData.add(underscoreName);
|
||||
|
||||
assertThatCode(() -> converter.convert(metricData)).doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
private static Stream<Arguments> resourceAttributesAdditionArgs() {
|
||||
List<Arguments> arguments = new ArrayList<>();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue