-
Notifications
You must be signed in to change notification settings - Fork 438
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 Histogram crash #1685
fix Histogram crash #1685
Changes from 4 commits
deb58af
1f79ad9
cd578a5
8150560
b00b03d
01bcb71
b16d524
5d96ae8
15c3654
f6dee09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,11 +1,13 @@ | ||||
// Copyright The OpenTelemetry Authors | ||||
// SPDX-License-Identifier: Apache-2.0 | ||||
|
||||
#include <memory> | ||||
esigo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
#ifndef ENABLE_METRICS_PREVIEW | ||||
# include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h" | ||||
# include <algorithm> | ||||
# include <iomanip> | ||||
# include <iostream> | ||||
esigo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
# include <limits> | ||||
# include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h" | ||||
# include "opentelemetry/version.h" | ||||
|
||||
# include <mutex> | ||||
|
@@ -16,21 +18,22 @@ namespace metrics | |||
{ | ||||
|
||||
LongHistogramAggregation::LongHistogramAggregation( | ||||
const HistogramAggregationConfig<long> *aggregation_config) | ||||
std::shared_ptr<AggregationConfig> aggregation_config) | ||||
{ | ||||
if (aggregation_config && aggregation_config->boundaries_.size()) | ||||
auto ac = std::dynamic_pointer_cast<HistogramAggregationConfig>(aggregation_config); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use static_pointer_case here, or use dynamic cast only if RTTI macro is enabled. Something similar to what we do here -
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure yet if I want to keep the shard_ptr. The main issue was in the lambda that was passing the pointer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using static cast now. |
||||
if (ac && ac->boundaries_.size()) | ||||
{ | ||||
point_data_.boundaries_ = aggregation_config->boundaries_; | ||||
point_data_.boundaries_ = ac->boundaries_; | ||||
} | ||||
else | ||||
{ | ||||
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) | ||||
if (ac) | ||||
{ | ||||
record_min_max_ = aggregation_config->record_min_max_; | ||||
record_min_max_ = ac->record_min_max_; | ||||
} | ||||
point_data_.counts_ = std::vector<uint64_t>(point_data_.boundaries_.size() + 1, 0); | ||||
point_data_.sum_ = 0l; | ||||
|
@@ -99,20 +102,21 @@ PointType LongHistogramAggregation::ToPoint() const noexcept | |||
} | ||||
|
||||
DoubleHistogramAggregation::DoubleHistogramAggregation( | ||||
const HistogramAggregationConfig<double> *aggregation_config) | ||||
std::shared_ptr<AggregationConfig> aggregation_config) | ||||
{ | ||||
if (aggregation_config && aggregation_config->boundaries_.size()) | ||||
auto ac = std::dynamic_pointer_cast<HistogramAggregationConfig>(aggregation_config); | ||||
if (ac && ac->boundaries_.size()) | ||||
{ | ||||
point_data_.boundaries_ = aggregation_config->boundaries_; | ||||
point_data_.boundaries_ = ac->boundaries_; | ||||
} | ||||
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}; | ||||
} | ||||
if (aggregation_config) | ||||
if (ac) | ||||
{ | ||||
record_min_max_ = aggregation_config->record_min_max_; | ||||
record_min_max_ = ac->record_min_max_; | ||||
} | ||||
point_data_.counts_ = std::vector<uint64_t>(point_data_.boundaries_.size() + 1, 0); | ||||
point_data_.sum_ = 0.0; | ||||
|
@@ -159,7 +163,12 @@ std::unique_ptr<Aggregation> DoubleHistogramAggregation::Merge( | |||
auto curr_value = nostd::get<HistogramPointData>(ToPoint()); | ||||
auto delta_value = nostd::get<HistogramPointData>( | ||||
(static_cast<const DoubleHistogramAggregation &>(delta).ToPoint())); | ||||
DoubleHistogramAggregation *aggr = new DoubleHistogramAggregation(); | ||||
std::shared_ptr<AggregationConfig> aggregation_config(new HistogramAggregationConfig); | ||||
static_cast<opentelemetry::sdk::metrics::HistogramAggregationConfig *>(aggregation_config.get()) | ||||
->boundaries_ = curr_value.boundaries_; | ||||
static_cast<opentelemetry::sdk::metrics::HistogramAggregationConfig *>(aggregation_config.get()) | ||||
->record_min_max_ = record_min_max_; | ||||
DoubleHistogramAggregation *aggr = new DoubleHistogramAggregation(aggregation_config); | ||||
HistogramMerge<double>(curr_value, delta_value, aggr->point_data_); | ||||
return std::unique_ptr<Aggregation>(aggr); | ||||
} | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I should have realized these changes to be done while converting boundaries to double. Sorry about that :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just changed them to introduce the crash into our CI :)