Skip to content

Commit

Permalink
fix prometheus exporter failure type (#1460)
Browse files Browse the repository at this point in the history
  • Loading branch information
esigo authored Jun 22, 2022
1 parent 96534a7 commit 5ccca49
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
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,
counts, point_data_attr.attributes, time, &metric_family);
}
else // Counter, Untyped
{
Expand Down

1 comment on commit 5ccca49

@github-actions
Copy link

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp sdk Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 5ccca49 Previous: 96534a7 Ratio
BM_BaselineBuffer/1 11402583.122253418 ns/iter 524055.00411987305 ns/iter 21.76
BM_LockFreeBuffer/1 3763816.8334960938 ns/iter 361703.9913438493 ns/iter 10.41
BM_LockFreeBuffer/2 4072211.078695349 ns/iter 1722775.2208709717 ns/iter 2.36

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.