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

Fix Prometheus exporter failure #1460

Merged
merged 3 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions exporters/prometheus/src/exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ PrometheusExporter::PrometheusExporter(const PrometheusExporterOptions &options)
*/
PrometheusExporter::PrometheusExporter() : is_shutdown_(false)
{
collector_ = std::unique_ptr<PrometheusCollector>(new PrometheusCollector);
collector_ = std::unique_ptr<PrometheusCollector>(new PrometheusCollector(3));
}

/**
Expand All @@ -45,10 +45,15 @@ sdk::common::ExportResult PrometheusExporter::Export(
{
return sdk::common::ExportResult::kFailure;
}
else if (collector_->GetCollection().size() + 1 > (size_t)collector_->GetMaxCollectionSize())
else if (collector_->GetCollection().size() + data.instrumentation_info_metric_data_.size() >
(size_t)collector_->GetMaxCollectionSize())
{
return sdk::common::ExportResult::kFailureFull;
}
else if (data.instrumentation_info_metric_data_.empty())
{
return sdk::common::ExportResult::kFailureInvalidArgument;
}
else
{
collector_->AddMetricData(data);
Expand Down
14 changes: 11 additions & 3 deletions exporters/prometheus/src/exporter_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,17 @@ std::vector<prometheus_client::MetricFamily> PrometheusExporterUtils::TranslateT
nostd::get<sdk::metrics::HistogramPointData>(point_data_attr.point_data);
auto boundaries = histogram_point_data.boundaries_;
auto counts = histogram_point_data.counts_;
SetData(std::vector<double>{nostd::get<double>(histogram_point_data.sum_),
(double)histogram_point_data.count_},
boundaries, counts, point_data_attr.attributes, time, &metric_family);
double sum = 0.0;
if (nostd::holds_alternative<double>(histogram_point_data.sum_))
{
sum = nostd::get<double>(histogram_point_data.sum_);
}
else
{
sum = nostd::get<long>(histogram_point_data.sum_);
}
SetData(std::vector<double>{sum, (double)histogram_point_data.count_}, boundaries,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - Why do we have std::vector<double> as first argument. Will we need to pass vector of aggregated values in this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That came from the legacy exporter code that I reused. The vector is used in SetValue called by SetData, supposedly to have slightly similar overload signature.

counts, point_data_attr.attributes, time, &metric_family);
}
else // Counter, Untyped
{
Expand Down