Skip to content

Commit

Permalink
Add Backwards-Compatibility (#911)
Browse files Browse the repository at this point in the history
* Add Backwards-Compatibility
- metrics name

Signed-off-by: thinker0 <[email protected]>

* Update code

Signed-off-by: thinker0 <[email protected]>

* Update code

Signed-off-by: thinker0 <[email protected]>

---------

Signed-off-by: thinker0 <[email protected]>
  • Loading branch information
thinker0 authored Jan 17, 2024
1 parent 60f72b6 commit 1fd8c7d
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -99,7 +101,7 @@ private MetricSnapshots convert(Enumeration<Collector.MetricFamilySamples> 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<Labels, CounterSnapshot.CounterDataPointSnapshot.Builder> dataPoints = new HashMap<>();
Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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<Labels, SummarySnapshot.SummaryDataPointSnapshot.Builder> dataPoints = new HashMap<>();
Expand Down Expand Up @@ -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<Labels, StateSetSnapshot.StateSetDataPointSnapshot.Builder> dataPoints = new HashMap<>();
for (Collector.MetricFamilySamples.Sample sample : samples.samples) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 1fd8c7d

Please sign in to comment.