diff --git a/prometheus-metrics-simpleclient-bridge/src/main/java/io/prometheus/metrics/simpleclient/bridge/SimpleclientCollector.java b/prometheus-metrics-simpleclient-bridge/src/main/java/io/prometheus/metrics/simpleclient/bridge/SimpleclientCollector.java index a775b2f55..e1b5a3113 100644 --- a/prometheus-metrics-simpleclient-bridge/src/main/java/io/prometheus/metrics/simpleclient/bridge/SimpleclientCollector.java +++ b/prometheus-metrics-simpleclient-bridge/src/main/java/io/prometheus/metrics/simpleclient/bridge/SimpleclientCollector.java @@ -1,5 +1,7 @@ package io.prometheus.metrics.simpleclient.bridge; +import static io.prometheus.metrics.model.snapshots.PrometheusNaming.sanitizeMetricName; + import io.prometheus.client.Collector; import io.prometheus.client.CollectorRegistry; import io.prometheus.metrics.config.PrometheusProperties; @@ -99,7 +101,7 @@ private MetricSnapshots convert(Enumeration sampl private MetricSnapshot convertCounter(Collector.MetricFamilySamples samples) { CounterSnapshot.Builder counter = CounterSnapshot.builder() - .name(stripSuffix(samples.name, "_total")) + .name(sanitizeMetricName(samples.name)) .help(samples.help) .unit(convertUnit(samples)); Map dataPoints = new HashMap<>(); @@ -123,7 +125,7 @@ private MetricSnapshot convertCounter(Collector.MetricFamilySamples samples) { private MetricSnapshot convertGauge(Collector.MetricFamilySamples samples) { GaugeSnapshot.Builder gauge = GaugeSnapshot.builder() - .name(samples.name) + .name(sanitizeMetricName(samples.name)) .help(samples.help) .unit(convertUnit(samples)); for (Collector.MetricFamilySamples.Sample sample : samples.samples) { @@ -141,7 +143,7 @@ private MetricSnapshot convertGauge(Collector.MetricFamilySamples samples) { private MetricSnapshot convertHistogram(Collector.MetricFamilySamples samples, boolean isGaugeHistogram) { HistogramSnapshot.Builder histogram = HistogramSnapshot.builder() - .name(samples.name) + .name(sanitizeMetricName(samples.name)) .help(samples.help) .unit(convertUnit(samples)) .gaugeHistogram(isGaugeHistogram); @@ -181,7 +183,7 @@ private MetricSnapshot convertHistogram(Collector.MetricFamilySamples samples, b private MetricSnapshot convertSummary(Collector.MetricFamilySamples samples) { SummarySnapshot.Builder summary = SummarySnapshot.builder() - .name(samples.name) + .name(sanitizeMetricName(samples.name)) .help(samples.help) .unit(convertUnit(samples)); Map dataPoints = new HashMap<>(); @@ -225,7 +227,7 @@ private MetricSnapshot convertSummary(Collector.MetricFamilySamples samples) { private MetricSnapshot convertStateSet(Collector.MetricFamilySamples samples) { StateSetSnapshot.Builder stateSet = StateSetSnapshot.builder() - .name(samples.name) + .name(sanitizeMetricName(samples.name)) .help(samples.help); Map dataPoints = new HashMap<>(); for (Collector.MetricFamilySamples.Sample sample : samples.samples) { @@ -254,7 +256,7 @@ private MetricSnapshot convertStateSet(Collector.MetricFamilySamples samples) { private MetricSnapshot convertUnknown(Collector.MetricFamilySamples samples) { UnknownSnapshot.Builder unknown = UnknownSnapshot.builder() - .name(samples.name) + .name(sanitizeMetricName(samples.name)) .help(samples.help) .unit(convertUnit(samples)); for (Collector.MetricFamilySamples.Sample sample : samples.samples) { @@ -334,7 +336,7 @@ private Labels labelsWithout(Collector.MetricFamilySamples.Sample sample, String private MetricSnapshot convertInfo(Collector.MetricFamilySamples samples) { InfoSnapshot.Builder info = InfoSnapshot.builder() - .name(stripSuffix(samples.name, "_info")) + .name(sanitizeMetricName(samples.name)) .help(samples.help); for (Collector.MetricFamilySamples.Sample sample : samples.samples) { info.dataPoint(InfoSnapshot.InfoDataPointSnapshot.builder()