From c75b54922e7dc2eedfca9419cd139215e7634184 Mon Sep 17 00:00:00 2001 From: Ankit Bhargava Date: Fri, 24 Jul 2020 16:29:23 -0400 Subject: [PATCH] adding virtual functions --- .../sdk/metrics/aggregator/aggregator.h | 51 ++++++++++++------- .../metrics/aggregator/counter_aggregator.h | 4 +- .../metrics/aggregator/histogram_aggregator.h | 17 +++++-- 3 files changed, 50 insertions(+), 22 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregator/aggregator.h b/sdk/include/opentelemetry/sdk/metrics/aggregator/aggregator.h index c17a5ae8da..fe2ec1bb90 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregator/aggregator.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregator/aggregator.h @@ -7,7 +7,6 @@ #include - namespace metrics_api = opentelemetry::metrics; OPENTELEMETRY_BEGIN_NAMESPACE @@ -18,12 +17,12 @@ namespace metrics enum class AggregatorKind { - Counter = 0, - MinMaxSumCount = 1, - Gauge = 2, - Sketch = 3, - Histogram = 4, - Exact = 5, + Counter = 0, + MinMaxSumCount = 1, + Gauge = 2, + Sketch = 3, + Histogram = 4, + Exact = 5, }; /* @@ -39,6 +38,8 @@ class Aggregator Aggregator() = default; + virtual ~Aggregator() = default; + /** * Receives a captured value from the instrument and applies it to the current aggregator value. * @@ -83,27 +84,43 @@ class Aggregator virtual std::vector get_values() = 0; /** - * Returns the instrument kind which this aggregator is associated with - * - * @param none - * @return the InstrumentKind of the aggregator's owner - */ + * Returns the instrument kind which this aggregator is associated with + * + * @param none + * @return the InstrumentKind of the aggregator's owner + */ virtual opentelemetry::metrics::InstrumentKind get_instrument_kind() final { return kind_; } /** - * Returns the type of this aggregator - * - * @param none - * @return the AggregatorKind of this instrument - */ + * Returns the type of this aggregator + * + * @param none + * @return the AggregatorKind of this instrument + */ virtual AggregatorKind get_aggregator_kind() final { return agg_kind_; } + virtual std::vector get_boundaries() { + return std::vector(); + } + + virtual std::vector get_counts() { + return std::vector(); + } + + virtual bool get_quant_estimation () { + return false; + } + + virtual T get_quantiles(double q) { + return values_[0]; + } + // Custom copy constructor to handle the mutex Aggregator(const Aggregator &cp) { diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregator/counter_aggregator.h b/sdk/include/opentelemetry/sdk/metrics/aggregator/counter_aggregator.h index ecdfae35aa..61e68e840c 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregator/counter_aggregator.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregator/counter_aggregator.h @@ -80,7 +80,7 @@ class CounterAggregator final : public Aggregator * @param none * @return the value of the checkpoint */ - std::vector get_checkpoint() override + virtual std::vector get_checkpoint() override { return this->checkpoint_; } @@ -91,7 +91,7 @@ class CounterAggregator final : public Aggregator * @param none * @return the present aggregator values */ - std::vector get_values() override + virtual std::vector get_values() override { return this->values_; } diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h b/sdk/include/opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h index 995ad7ae87..9fa70ac524 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregator/histogram_aggregator.h @@ -152,9 +152,9 @@ class HistogramAggregator final : public Aggregator * @param none * @return the aggregator boundaries */ - std::vector get_boundaries() + virtual std::vector get_boundaries() override { - return bucketCounts_; + return boundaries_; } /** @@ -163,11 +163,22 @@ class HistogramAggregator final : public Aggregator * @param none * @return the aggregator bucket counts */ - std::vector get_counts() + virtual std::vector get_counts() override { return bucketCounts_; } + HistogramAggregator(const HistogramAggregator &cp) + { + this->values_ = cp.values_; + this->checkpoint_ = cp.checkpoint_; + this->kind_ = cp.kind_; + this->agg_kind_ = cp.agg_kind_; + boundaries_ = cp.boundaries_; + bucketCounts_ = cp.bucketCounts_; + // use default initialized mutex as they cannot be copied + } + private: std::vector boundaries_; std::vector bucketCounts_;