Skip to content

Commit

Permalink
update bucket range, and fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Sep 22, 2022
1 parent decceba commit c25c08a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 36 deletions.
17 changes: 3 additions & 14 deletions exporters/otlp/src/otlp_metric_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,10 @@ void OtlpMetricUtils::ConvertHistogramMetric(
}
}
// buckets
if ((nostd::holds_alternative<std::list<double>>(histogram_data.boundaries_)))
{
auto boundaries = nostd::get<std::list<double>>(histogram_data.boundaries_);
for (auto bound : boundaries)
{
proto_histogram_point_data->add_explicit_bounds(bound);
}
}
else

for (auto bound : histogram_data.boundaries_)
{
auto boundaries = nostd::get<std::list<long>>(histogram_data.boundaries_);
for (auto bound : boundaries)
{
proto_histogram_point_data->add_explicit_bounds(bound);
}
proto_histogram_point_data->add_explicit_bounds(bound);
}
// bucket counts
for (auto bucket_value : histogram_data.counts_)
Expand Down
8 changes: 4 additions & 4 deletions exporters/otlp/test/otlp_http_metric_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -482,14 +482,14 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test
auto exporter = GetExporter(std::unique_ptr<OtlpHttpClient>{mock_otlp_http_client});

opentelemetry::sdk::metrics::HistogramPointData histogram_point_data{};
histogram_point_data.boundaries_ = std::list<double>{10.1, 20.2, 30.2};
histogram_point_data.boundaries_ = {10.1, 20.2, 30.2};
histogram_point_data.count_ = 3;
histogram_point_data.counts_ = {200, 300, 400, 500};
histogram_point_data.sum_ = 900.5;
histogram_point_data.min_ = 1.8;
histogram_point_data.max_ = 19.0;
opentelemetry::sdk::metrics::HistogramPointData histogram_point_data2{};
histogram_point_data2.boundaries_ = std::list<long>{10, 20, 30};
histogram_point_data2.boundaries_ = {10.0, 20.0, 30.0};
histogram_point_data2.count_ = 3;
histogram_point_data2.counts_ = {200, 300, 400, 500};
histogram_point_data2.sum_ = 900l;
Expand Down Expand Up @@ -619,12 +619,12 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test
"library_name", "1.5.0");

opentelemetry::sdk::metrics::HistogramPointData histogram_point_data{};
histogram_point_data.boundaries_ = std::list<double>{10.1, 20.2, 30.2};
histogram_point_data.boundaries_ = {10.1, 20.2, 30.2};
histogram_point_data.count_ = 3;
histogram_point_data.counts_ = {200, 300, 400, 500};
histogram_point_data.sum_ = 900.5;
opentelemetry::sdk::metrics::HistogramPointData histogram_point_data2{};
histogram_point_data2.boundaries_ = std::list<long>{10, 20, 30};
histogram_point_data2.boundaries_ = {10.0, 20.0, 30.0};
histogram_point_data2.count_ = 3;
histogram_point_data2.counts_ = {200, 300, 400, 500};
histogram_point_data2.sum_ = 900l;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class PrometheusExporterUtils
*/
template <typename T>
static void SetData(std::vector<T> values,
const opentelemetry::sdk::metrics::ListType &boundaries,
const std::list<double> &boundaries,
const std::vector<uint64_t> &counts,
const opentelemetry::sdk::metrics::PointAttributes &labels,
std::chrono::nanoseconds time,
Expand Down Expand Up @@ -103,9 +103,9 @@ class PrometheusExporterUtils
/**
* Handle Histogram
*/
template <typename T, typename U>
template <typename T>
static void SetValue(std::vector<T> values,
const std::list<U> &boundaries,
const std::list<double> &boundaries,
const std::vector<uint64_t> &counts,
::prometheus::ClientMetric *metric);
};
Expand Down
15 changes: 4 additions & 11 deletions exporters/prometheus/src/exporter_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void PrometheusExporterUtils::SetData(std::vector<T> values,
*/
template <typename T>
void PrometheusExporterUtils::SetData(std::vector<T> values,
const opentelemetry::sdk::metrics::ListType &boundaries,
const std::list<double> &boundaries,
const std::vector<uint64_t> &counts,
const metric_sdk::PointAttributes &labels,
std::chrono::nanoseconds time,
Expand All @@ -206,14 +206,7 @@ void PrometheusExporterUtils::SetData(std::vector<T> values,
metric_family->metric.emplace_back();
prometheus_client::ClientMetric &metric = metric_family->metric.back();
SetMetricBasic(metric, time, labels);
if (nostd::holds_alternative<std::list<long>>(boundaries))
{
SetValue(values, nostd::get<std::list<long>>(boundaries), counts, &metric);
}
else
{
SetValue(values, nostd::get<std::list<double>>(boundaries), counts, &metric);
}
SetValue(values, boundaries, counts, &metric);
}

/**
Expand Down Expand Up @@ -321,9 +314,9 @@ void PrometheusExporterUtils::SetValue(std::vector<T> values,
/**
* Handle Histogram
*/
template <typename T, typename U>
template <typename T>
void PrometheusExporterUtils::SetValue(std::vector<T> values,
const std::list<U> &boundaries,
const std::list<double> &boundaries,
const std::vector<uint64_t> &counts,
prometheus_client::ClientMetric *metric)
{
Expand Down
4 changes: 2 additions & 2 deletions exporters/prometheus/test/prometheus_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ inline metric_sdk::ResourceMetrics CreateSumPointData()
inline metric_sdk::ResourceMetrics CreateHistogramPointData()
{
metric_sdk::HistogramPointData histogram_point_data{};
histogram_point_data.boundaries_ = std::list<double>{10.1, 20.2, 30.2};
histogram_point_data.boundaries_ = {10.1, 20.2, 30.2};
histogram_point_data.count_ = 3;
histogram_point_data.counts_ = {200, 300, 400, 500};
histogram_point_data.sum_ = 900.5;
metric_sdk::HistogramPointData histogram_point_data2{};
histogram_point_data2.boundaries_ = std::list<long>{10, 20, 30};
histogram_point_data2.boundaries_ = {10.0, 20.0, 30.0};
histogram_point_data2.count_ = 3;
histogram_point_data2.counts_ = {200, 300, 400, 500};
histogram_point_data2.sum_ = 900l;
Expand Down
5 changes: 3 additions & 2 deletions sdk/src/metrics/aggregation/histogram_aggregation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ LongHistogramAggregation::LongHistogramAggregation(
}
else
{
point_data_.boundaries_ =
std::list<double>{0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 1000.0};
point_data_.boundaries_ = {0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0,
500.0, 750.0, 1000.0, 2500.0, 5000.0, 7500.0, 10000.0};
}

if (aggregation_config)
{
record_min_max_ = aggregation_config->record_min_max_;
Expand Down

0 comments on commit c25c08a

Please sign in to comment.