From 31dabd8d3bd2b00f02a3385e57942a30f1487259 Mon Sep 17 00:00:00 2001 From: Punya Biswal Date: Sun, 24 Sep 2023 08:26:41 -0400 Subject: [PATCH] [exporters/prometheus] More namespace cleanup --- .../exporters/prometheus/exporter_utils.h | 20 ++++++------------- exporters/prometheus/src/collector.cc | 2 +- exporters/prometheus/src/exporter_utils.cc | 3 +-- .../prometheus/test/exporter_utils_test.cc | 20 +++++++++---------- 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h index 9122626ede..7cd3bfed50 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h @@ -16,21 +16,13 @@ namespace exporter namespace metrics { /** - * The Prometheus Utils contains utility functions for Prometheus Exporter + * Convert OpenTelemetry metrics data collection to Prometheus metrics data collection + * + * @param data a collection of metrics in OpenTelemetry + * @return a collection of translated metrics that is acceptable by Prometheus */ -class PrometheusExporterUtils -{ -public: - /** - * Helper function to convert OpenTelemetry metrics data collection - * to Prometheus metrics data collection - * - * @param data a collection of metrics in OpenTelemetry - * @return a collection of translated metrics that is acceptable by Prometheus - */ - static std::vector<::prometheus::MetricFamily> TranslateToPrometheus( - const sdk::metrics::ResourceMetrics &data); -}; +std::vector<::prometheus::MetricFamily> TranslateToPrometheus( + const sdk::metrics::ResourceMetrics &data); } // namespace metrics } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/prometheus/src/collector.cc b/exporters/prometheus/src/collector.cc index 29c0bc8db2..20bb6c3e1d 100644 --- a/exporters/prometheus/src/collector.cc +++ b/exporters/prometheus/src/collector.cc @@ -37,7 +37,7 @@ std::vector PrometheusCollector::Collect() cons std::vector result; reader_->Collect([&result](sdk::metrics::ResourceMetrics &metric_data) { - auto prometheus_metric_data = PrometheusExporterUtils::TranslateToPrometheus(metric_data); + auto prometheus_metric_data = TranslateToPrometheus(metric_data); for (auto &data : prometheus_metric_data) result.emplace_back(data); return true; diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index 053841f623..6c1704947b 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -268,7 +268,7 @@ struct MetricFamilyWrapper * @param records a collection of metrics in OpenTelemetry * @return a collection of translated metrics that is acceptable by Prometheus */ -std::vector PrometheusExporterUtils::TranslateToPrometheus( +std::vector TranslateToPrometheus( const sdk::metrics::ResourceMetrics &data) { @@ -362,7 +362,6 @@ std::vector PrometheusExporterUtils::TranslateT } return output; } - } // namespace metrics } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc index f5a6983e43..5839caa106 100644 --- a/exporters/prometheus/test/exporter_utils_test.cc +++ b/exporters/prometheus/test/exporter_utils_test.cc @@ -8,13 +8,13 @@ #include "opentelemetry/exporters/prometheus/exporter_utils.h" #include "prometheus_test_helper.h" -using opentelemetry::exporter::metrics::PrometheusExporterUtils; -namespace metric_sdk = opentelemetry::sdk::metrics; -namespace metric_api = opentelemetry::metrics; -namespace prometheus_client = ::prometheus; - OPENTELEMETRY_BEGIN_NAMESPACE +using exporter::metrics::TranslateToPrometheus; +namespace metric_sdk = sdk::metrics; +namespace metric_api = metrics; +namespace prometheus_client = ::prometheus; + template void assert_basic(prometheus_client::MetricFamily &metric, const std::string &sanitized_name, @@ -91,7 +91,7 @@ void assert_histogram(prometheus_client::MetricFamily &metric, TEST(PrometheusExporterUtils, TranslateToPrometheusEmptyInputReturnsEmptyCollection) { metric_sdk::ResourceMetrics metrics_data = {}; - auto translated = PrometheusExporterUtils::TranslateToPrometheus(metrics_data); + auto translated = TranslateToPrometheus(metrics_data); ASSERT_EQ(translated.size(), 0); } @@ -100,7 +100,7 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusIntegerCounter) TestDataPoints dp; metric_sdk::ResourceMetrics metrics_data = dp.CreateSumPointData(); - auto translated = PrometheusExporterUtils::TranslateToPrometheus(metrics_data); + auto translated = TranslateToPrometheus(metrics_data); ASSERT_EQ(translated.size(), 1); auto metric1 = translated[0]; @@ -114,7 +114,7 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusIntegerLastValue) TestDataPoints dp; metric_sdk::ResourceMetrics metrics_data = dp.CreateLastValuePointData(); - auto translated = PrometheusExporterUtils::TranslateToPrometheus(metrics_data); + auto translated = TranslateToPrometheus(metrics_data); ASSERT_EQ(translated.size(), 1); auto metric1 = translated[0]; @@ -128,7 +128,7 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusHistogramNormal) TestDataPoints dp; metric_sdk::ResourceMetrics metrics_data = dp.CreateHistogramPointData(); - auto translated = PrometheusExporterUtils::TranslateToPrometheus(metrics_data); + auto translated = TranslateToPrometheus(metrics_data); ASSERT_EQ(translated.size(), 1); auto metric = translated[0]; @@ -150,7 +150,7 @@ class SanitizeNameTest : public ::testing::Test metric_sdk::InstrumentDescriptor instrument_descriptor{ original, "description", "unit", metric_sdk::InstrumentType::kCounter, metric_sdk::InstrumentValueType::kDouble}; - std::vector result = PrometheusExporterUtils::TranslateToPrometheus( + std::vector result = TranslateToPrometheus( {&resource_, {{instrumentation_scope_.get(), {{instrument_descriptor, {}, {}, {}, {{}}}}}}}); EXPECT_EQ(result.begin()->name, sanitized + "_unit");