Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[exporters/prometheus] Omit underscore suffix for unitless metrics #2323

Closed
wants to merge 1 commit into from

Conversation

punya
Copy link
Member

@punya punya commented Sep 22, 2023

Fixes #2317

Changes

Please provide a brief description of the changes here.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@codecov
Copy link

codecov bot commented Sep 22, 2023

Codecov Report

Merging #2323 (d23b902) into main (ca67af0) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2323   +/-   ##
=======================================
  Coverage   87.45%   87.45%           
=======================================
  Files         199      199           
  Lines        5997     5997           
=======================================
  Hits         5244     5244           
  Misses        753      753           

@marcalff
Copy link
Member

@punya

Our CI uses clang-format 10

To fix the format error, either run clang-format, or take the diff from the ci format logs and apply it manually:

diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc
index 95ff12a..e115500 100644
--- a/exporters/prometheus/src/exporter_utils.cc
+++ b/exporters/prometheus/src/exporter_utils.cc
@@ -43,7 +43,8 @@ std::vector<prometheus_client::MetricFamily> PrometheusExporterUtils::TranslateT
       auto sanitized   = SanitizeNames(origin_name);
       prometheus_client::MetricFamily metric_family;
       metric_family.name = sanitized;
-      if (!unit.empty()) {
+      if (!unit.empty())
+      {
         metric_family.name += "_" + unit;
       };
       metric_family.help = metric_data.instrument_descriptor.description_;
diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc
index 8de1721..679c291 100644
--- a/exporters/prometheus/test/exporter_utils_test.cc
+++ b/exporters/prometheus/test/exporter_utils_test.cc
@@ -162,7 +162,7 @@ TEST(PrometheusExporterUtils, HandleMissingUnit)
   TestDataPoints dp;
   metric_sdk::ResourceMetrics data = dp.CreateSumPointData("");
   std::vector<prometheus::MetricFamily> family =
-    PrometheusExporterUtils::TranslateToPrometheus(data);
+      PrometheusExporterUtils::TranslateToPrometheus(data);
   ASSERT_EQ(family.begin()->name, "library_name");
 }

@punya punya marked this pull request as ready for review September 23, 2023 09:25
@punya punya requested a review from a team September 23, 2023 09:25
@punya punya marked this pull request as draft September 23, 2023 09:27
@punya
Copy link
Member Author

punya commented Sep 23, 2023

Abandoning because this problem is already solved in #2213 as part of a larger change.

@punya punya closed this Sep 23, 2023
@punya punya deleted the underscore-suffix branch September 23, 2023 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prometheus exporter adds underscore suffix for metrics without unit
2 participants