Skip to content

Commit

Permalink
adding virtual functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ankit-bhargava committed Jul 24, 2020
1 parent a0a98a2 commit c75b549
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 22 deletions.
51 changes: 34 additions & 17 deletions sdk/include/opentelemetry/sdk/metrics/aggregator/aggregator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <vector>



namespace metrics_api = opentelemetry::metrics;

OPENTELEMETRY_BEGIN_NAMESPACE
Expand All @@ -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,
};

/*
Expand All @@ -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.
*
Expand Down Expand Up @@ -83,27 +84,43 @@ class Aggregator
virtual std::vector<T> 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<double> get_boundaries() {
return std::vector<double>();
}

virtual std::vector<int> get_counts() {
return std::vector<int>();
}

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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class CounterAggregator final : public Aggregator<T>
* @param none
* @return the value of the checkpoint
*/
std::vector<T> get_checkpoint() override
virtual std::vector<T> get_checkpoint() override
{
return this->checkpoint_;
}
Expand All @@ -91,7 +91,7 @@ class CounterAggregator final : public Aggregator<T>
* @param none
* @return the present aggregator values
*/
std::vector<T> get_values() override
virtual std::vector<T> get_values() override
{
return this->values_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ class HistogramAggregator final : public Aggregator<T>
* @param none
* @return the aggregator boundaries
*/
std::vector<double> get_boundaries()
virtual std::vector<double> get_boundaries() override
{
return bucketCounts_;
return boundaries_;
}

/**
Expand All @@ -163,11 +163,22 @@ class HistogramAggregator final : public Aggregator<T>
* @param none
* @return the aggregator bucket counts
*/
std::vector<int> get_counts()
virtual std::vector<int> 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<double> boundaries_;
std::vector<int> bucketCounts_;
Expand Down

0 comments on commit c75b549

Please sign in to comment.