-
Notifications
You must be signed in to change notification settings - Fork 628
Enable metric collection for Async Instruments - Delta and Cumulative #1334
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
Changes from all commits
0b6f8fb
0767f90
9c4740d
7198a0b
b93d4dd
3a6f8eb
2dda99a
77d344a
9dcaf1a
aafa07d
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 |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ class DefaultAggregation | |
| { | ||
| case InstrumentType::kCounter: | ||
| case InstrumentType::kUpDownCounter: | ||
| case InstrumentType::kObservableCounter: | ||
| case InstrumentType::kObservableUpDownCounter: | ||
| return (instrument_descriptor.value_type_ == InstrumentValueType::kLong) | ||
| ? std::move(std::unique_ptr<Aggregation>(new LongSumAggregation())) | ||
|
|
@@ -90,6 +91,53 @@ class DefaultAggregation | |
| return DefaultAggregation::CreateAggregation(instrument_descriptor); | ||
| } | ||
| } | ||
|
|
||
| static std::unique_ptr<Aggregation> CloneAggregation(AggregationType aggregation_type, | ||
| InstrumentDescriptor instrument_descriptor, | ||
| const Aggregation &to_copy) | ||
| { | ||
| const PointType point_data = to_copy.ToPoint(); | ||
| switch (aggregation_type) | ||
| { | ||
| case AggregationType::kDrop: | ||
| return std::unique_ptr<Aggregation>(new DropAggregation()); | ||
|
Contributor
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. Probably make assignment of the new Aggregation in the switch and return it at the end of the function?
Member
Author
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. you mean multiple stack unwinding code being generated. I think modern compilers should be smart enough to handle that. |
||
| case AggregationType::kHistogram: | ||
| if (instrument_descriptor.value_type_ == InstrumentValueType::kLong) | ||
| { | ||
| return std::unique_ptr<Aggregation>( | ||
| new LongHistogramAggregation(nostd::get<HistogramPointData>(point_data))); | ||
| } | ||
| else | ||
| { | ||
| return std::unique_ptr<Aggregation>( | ||
| new DoubleHistogramAggregation(nostd::get<HistogramPointData>(point_data))); | ||
| } | ||
| case AggregationType::kLastValue: | ||
| if (instrument_descriptor.value_type_ == InstrumentValueType::kLong) | ||
| { | ||
| return std::unique_ptr<Aggregation>( | ||
| new LongLastValueAggregation(nostd::get<LastValuePointData>(point_data))); | ||
| } | ||
| else | ||
| { | ||
| return std::unique_ptr<Aggregation>( | ||
| new DoubleLastValueAggregation(nostd::get<LastValuePointData>(point_data))); | ||
| } | ||
| case AggregationType::kSum: | ||
| if (instrument_descriptor.value_type_ == InstrumentValueType::kLong) | ||
| { | ||
| return std::unique_ptr<Aggregation>( | ||
| new LongSumAggregation(nostd::get<SumPointData>(point_data))); | ||
| } | ||
| else | ||
| { | ||
| return std::unique_ptr<Aggregation>( | ||
| new DoubleSumAggregation(nostd::get<SumPointData>(point_data))); | ||
| } | ||
| default: | ||
| return DefaultAggregation::CreateAggregation(instrument_descriptor); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| } // namespace metrics | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,21 +19,22 @@ class LongHistogramAggregation : public Aggregation | |
| public: | ||
| LongHistogramAggregation(); | ||
| LongHistogramAggregation(HistogramPointData &&); | ||
| LongHistogramAggregation(const HistogramPointData &); | ||
|
|
||
| void Aggregate(long value, const PointAttributes &attributes = {}) noexcept override; | ||
|
|
||
| void Aggregate(double value, const PointAttributes &attributes = {}) noexcept override {} | ||
|
|
||
| /* Returns the result of merge of the existing aggregation with delta aggregation with same | ||
| * boundaries */ | ||
| virtual std::unique_ptr<Aggregation> Merge(const Aggregation &delta) const noexcept override; | ||
|
Contributor
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. Why is virtual removed?
Member
Author
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. It is not required, as we won't need to subclass |
||
| std::unique_ptr<Aggregation> Merge(const Aggregation &delta) const noexcept override; | ||
|
|
||
| /* Returns the new delta aggregation by comparing existing aggregation with next aggregation with | ||
| * same boundaries. Data points for `next` aggregation (sum , bucket-counts) should be more than | ||
| * the current aggregation - which is the normal scenario as measurements values are monotonic | ||
| * increasing. | ||
| */ | ||
| virtual std::unique_ptr<Aggregation> Diff(const Aggregation &next) const noexcept override; | ||
| std::unique_ptr<Aggregation> Diff(const Aggregation &next) const noexcept override; | ||
|
|
||
| PointType ToPoint() const noexcept override; | ||
|
|
||
|
|
@@ -47,21 +48,22 @@ class DoubleHistogramAggregation : public Aggregation | |
| public: | ||
| DoubleHistogramAggregation(); | ||
| DoubleHistogramAggregation(HistogramPointData &&); | ||
| DoubleHistogramAggregation(const HistogramPointData &); | ||
|
|
||
| void Aggregate(long value, const PointAttributes &attributes = {}) noexcept override {} | ||
|
|
||
| void Aggregate(double value, const PointAttributes &attributes = {}) noexcept override; | ||
|
|
||
| /* Returns the result of merge of the existing aggregation with delta aggregation with same | ||
| * boundaries */ | ||
| virtual std::unique_ptr<Aggregation> Merge(const Aggregation &delta) const noexcept override; | ||
| std::unique_ptr<Aggregation> Merge(const Aggregation &delta) const noexcept override; | ||
|
|
||
| /* Returns the new delta aggregation by comparing existing aggregation with next aggregation with | ||
| * same boundaries. Data points for `next` aggregation (sum , bucket-counts) should be more than | ||
| * the current aggregation - which is the normal scenario as measurements values are monotonic | ||
| * increasing. | ||
| */ | ||
| virtual std::unique_ptr<Aggregation> Diff(const Aggregation &next) const noexcept override; | ||
| std::unique_ptr<Aggregation> Diff(const Aggregation &next) const noexcept override; | ||
|
|
||
| PointType ToPoint() const noexcept override; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #pragma once | ||
| #ifndef ENABLE_METRICS_PREVIEW | ||
| # include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" | ||
| # include "opentelemetry/sdk/metrics/state/metric_collector.h" | ||
|
|
||
| # include <memory> | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace metrics | ||
| { | ||
|
|
||
| struct LastReportedMetrics | ||
| { | ||
| std::unique_ptr<AttributesHashMap> attributes_map; | ||
| opentelemetry::common::SystemTimestamp collection_ts; | ||
| }; | ||
|
|
||
| class TemporalMetricStorage | ||
| { | ||
| public: | ||
| TemporalMetricStorage(InstrumentDescriptor instrument_descriptor); | ||
|
|
||
| bool buildMetrics(CollectorHandle *collector, | ||
| nostd::span<std::shared_ptr<CollectorHandle>> collectors, | ||
| opentelemetry::common::SystemTimestamp sdk_start_ts, | ||
| opentelemetry::common::SystemTimestamp collection_ts, | ||
| std::shared_ptr<AttributesHashMap> delta_metrics, | ||
| nostd::function_ref<bool(MetricData)> callback) noexcept; | ||
|
|
||
| private: | ||
| InstrumentDescriptor instrument_descriptor_; | ||
|
|
||
| // unreported metrics stash for all the collectors | ||
| std::unordered_map<CollectorHandle *, std::list<std::shared_ptr<AttributesHashMap>>> | ||
|
esigo marked this conversation as resolved.
|
||
| unreported_metrics_; | ||
| // last reported metrics stash for all the collectors. | ||
| std::unordered_map<CollectorHandle *, LastReportedMetrics> last_reported_metrics_; | ||
|
|
||
| // Lock while building metrics | ||
| mutable opentelemetry::common::SpinLockMutex lock_; | ||
| }; | ||
| } // namespace metrics | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE | ||
| #endif | ||
Uh oh!
There was an error while loading. Please reload this page.