|
| 1 | +// Copyright The OpenTelemetry Authors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +#pragma once |
| 5 | + |
| 6 | +#include "opentelemetry/common/spin_lock_mutex.h" |
| 7 | +#include "opentelemetry/sdk/metrics/aggregation/aggregation.h" |
| 8 | +#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" |
| 9 | +#include "opentelemetry/sdk/metrics/aggregation/base2_exponential_histogram_indexer.h" |
| 10 | + |
| 11 | +#include <memory> |
| 12 | +#include <mutex> |
| 13 | + |
| 14 | +OPENTELEMETRY_BEGIN_NAMESPACE |
| 15 | +namespace sdk |
| 16 | +{ |
| 17 | +namespace metrics |
| 18 | +{ |
| 19 | + |
| 20 | +class Base2ExponentialHistogramAggregation : public Aggregation |
| 21 | +{ |
| 22 | +public: |
| 23 | + Base2ExponentialHistogramAggregation(const AggregationConfig *aggregation_config = nullptr); |
| 24 | + Base2ExponentialHistogramAggregation(const Base2ExponentialHistogramPointData &point_data); |
| 25 | + Base2ExponentialHistogramAggregation(Base2ExponentialHistogramPointData &&point_data); |
| 26 | + |
| 27 | + |
| 28 | + void Aggregate(int64_t value, const PointAttributes &attributes = {}) noexcept override; |
| 29 | + void Aggregate(double value, const PointAttributes &attributes = {}) noexcept override; |
| 30 | + |
| 31 | + /* Returns the result of merge of the existing aggregation with delta |
| 32 | + * aggregation with same boundaries */ |
| 33 | + std::unique_ptr<Aggregation> Merge(const Aggregation &delta) const noexcept override; |
| 34 | + |
| 35 | + /* Returns the new delta aggregation by comparing existing aggregation with |
| 36 | + * next aggregation with same boundaries. Data points for `next` aggregation |
| 37 | + * (sum , bucket-counts) should be more than the current aggregation - which |
| 38 | + * is the normal scenario as measurements values are monotonic increasing. |
| 39 | + */ |
| 40 | + std::unique_ptr<Aggregation> Diff(const Aggregation &next) const noexcept override; |
| 41 | + |
| 42 | + PointType ToPoint() const noexcept override; |
| 43 | + |
| 44 | +private: |
| 45 | + void AggregateIntoBuckets(AdaptingCircularBufferCounter *buckets, double value) noexcept; |
| 46 | + void Downscale(uint32_t by) noexcept; |
| 47 | + |
| 48 | + mutable opentelemetry::common::SpinLockMutex lock_; |
| 49 | + Base2ExponentialHistogramPointData point_data_; |
| 50 | + Base2ExponentialHistogramIndexer indexer_; |
| 51 | + bool record_min_max_ = true; |
| 52 | +}; |
| 53 | + |
| 54 | +} // namespace metrics |
| 55 | +} // namespace sdk |
| 56 | +OPENTELEMETRY_END_NAMESPACE |
0 commit comments