Skip to content

Commit

Permalink
[exporters/prometheus] More namespace cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
punya committed Sep 24, 2023
1 parent 1d40cf5 commit 31dabd8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion exporters/prometheus/src/collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ std::vector<prometheus_client::MetricFamily> PrometheusCollector::Collect() cons

std::vector<prometheus_client::MetricFamily> 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;
Expand Down
3 changes: 1 addition & 2 deletions exporters/prometheus/src/exporter_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<prometheus_client::MetricFamily> PrometheusExporterUtils::TranslateToPrometheus(
std::vector<prometheus_client::MetricFamily> TranslateToPrometheus(
const sdk::metrics::ResourceMetrics &data)
{

Expand Down Expand Up @@ -362,7 +362,6 @@ std::vector<prometheus_client::MetricFamily> PrometheusExporterUtils::TranslateT
}
return output;
}

} // namespace metrics
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
20 changes: 10 additions & 10 deletions exporters/prometheus/test/exporter_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
void assert_basic(prometheus_client::MetricFamily &metric,
const std::string &sanitized_name,
Expand Down Expand Up @@ -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);
}

Expand All @@ -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];
Expand All @@ -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];
Expand All @@ -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];
Expand All @@ -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<prometheus::MetricFamily> result = PrometheusExporterUtils::TranslateToPrometheus(
std::vector<prometheus::MetricFamily> result = TranslateToPrometheus(
{&resource_,
{{instrumentation_scope_.get(), {{instrument_descriptor, {}, {}, {}, {{}}}}}}});
EXPECT_EQ(result.begin()->name, sanitized + "_unit");
Expand Down

0 comments on commit 31dabd8

Please sign in to comment.