From 5d16bd4fa1105b5c2fcc9a9a0862cc071666b440 Mon Sep 17 00:00:00 2001 From: zengxilong Date: Thu, 19 Jan 2023 15:52:23 +0800 Subject: [PATCH 1/4] fix: prometheus counters should have _total suffix --- opentelemetry-prometheus/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/opentelemetry-prometheus/src/lib.rs b/opentelemetry-prometheus/src/lib.rs index 6415592857..15d76d6266 100644 --- a/opentelemetry-prometheus/src/lib.rs +++ b/opentelemetry-prometheus/src/lib.rs @@ -107,6 +107,10 @@ mod sanitize; use sanitize::sanitize; +/// Monotonic Sum metric points MUST have _total added as a suffix to the metric name +/// https://github.com/open-telemetry/opentelemetry-specification/blob/v1.14.0/specification/metrics/data-model.md#sums-1 +const MONOTONIC_COUNTER_SUFFIX: &str = "_total"; + /// Create a new prometheus exporter builder. pub fn exporter(controller: BasicController) -> ExporterBuilder { ExporterBuilder::new(controller) @@ -330,7 +334,7 @@ fn build_monotonic_counter( m.set_counter(c); let mut mf = prometheus::proto::MetricFamily::default(); - mf.set_name(desc.name); + mf.set_name(desc.name+MONOTONIC_SUM_SUFFIX); mf.set_help(desc.help); mf.set_field_type(prometheus::proto::MetricType::COUNTER); mf.set_metric(protobuf::RepeatedField::from_vec(vec![m])); From 9d53be2677f8f13aa99a9849eab938c926c30374 Mon Sep 17 00:00:00 2001 From: zengxilong Date: Thu, 19 Jan 2023 16:39:56 +0800 Subject: [PATCH 2/4] style: fix code style --- opentelemetry-prometheus/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-prometheus/src/lib.rs b/opentelemetry-prometheus/src/lib.rs index 15d76d6266..8f7801f5ba 100644 --- a/opentelemetry-prometheus/src/lib.rs +++ b/opentelemetry-prometheus/src/lib.rs @@ -334,7 +334,7 @@ fn build_monotonic_counter( m.set_counter(c); let mut mf = prometheus::proto::MetricFamily::default(); - mf.set_name(desc.name+MONOTONIC_SUM_SUFFIX); + mf.set_name(desc.name + MONOTONIC_SUM_SUFFIX); mf.set_help(desc.help); mf.set_field_type(prometheus::proto::MetricType::COUNTER); mf.set_metric(protobuf::RepeatedField::from_vec(vec![m])); From 9bad29f5d8874a31a5d04bf8632d88c46736fc7b Mon Sep 17 00:00:00 2001 From: zengxilong Date: Thu, 19 Jan 2023 16:46:30 +0800 Subject: [PATCH 3/4] fix: const name error --- opentelemetry-prometheus/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-prometheus/src/lib.rs b/opentelemetry-prometheus/src/lib.rs index 8f7801f5ba..11268d7d51 100644 --- a/opentelemetry-prometheus/src/lib.rs +++ b/opentelemetry-prometheus/src/lib.rs @@ -334,7 +334,7 @@ fn build_monotonic_counter( m.set_counter(c); let mut mf = prometheus::proto::MetricFamily::default(); - mf.set_name(desc.name + MONOTONIC_SUM_SUFFIX); + mf.set_name(desc.name + MONOTONIC_COUNTER_SUFFIX); mf.set_help(desc.help); mf.set_field_type(prometheus::proto::MetricType::COUNTER); mf.set_metric(protobuf::RepeatedField::from_vec(vec![m])); From cd013fa6a2af9a4f19d4043d910e0cf9e453c0c9 Mon Sep 17 00:00:00 2001 From: zengxilong Date: Thu, 19 Jan 2023 17:11:49 +0800 Subject: [PATCH 4/4] feat: test --- opentelemetry-prometheus/tests/integration_test.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-prometheus/tests/integration_test.rs b/opentelemetry-prometheus/tests/integration_test.rs index 0fae5e3ab1..6341c0e4c8 100644 --- a/opentelemetry-prometheus/tests/integration_test.rs +++ b/opentelemetry-prometheus/tests/integration_test.rs @@ -33,7 +33,7 @@ fn free_unused_instruments() { counter.add(&cx, 10.0, &attributes); counter.add(&cx, 5.3, &attributes); - expected.push(r#"counter{A="B",C="D",R="V"} 15.3"#); + expected.push(r#"counter_total{A="B",C="D",R="V"} 15.3"#); } // Standard export compare_export(&exporter, expected.clone()); @@ -73,7 +73,7 @@ fn test_add() { counter.add(&cx, 10.0, &attributes); counter.add(&cx, 5.3, &attributes); - expected.push(r#"counter{A="B",C="D",R="V"} 15.3"#); + expected.push(r#"counter_total{A="B",C="D",R="V"} 15.3"#); let cb_attributes = attributes.clone(); let gauge = meter.i64_observable_gauge("intgauge").init();