From 8483cc3d2347ccd930a607b5952faf6b6e2ba7c1 Mon Sep 17 00:00:00 2001 From: jmacd Date: Wed, 10 Jun 2020 00:32:14 -0700 Subject: [PATCH] Add Aggregation.Kind() --- sdk/export/metric/aggregation/aggregation.go | 30 +++++++++++++++----- sdk/metric/aggregator/array/array.go | 5 ++++ sdk/metric/aggregator/ddsketch/ddsketch.go | 5 ++++ sdk/metric/aggregator/histogram/histogram.go | 5 ++++ sdk/metric/aggregator/lastvalue/lastvalue.go | 5 ++++ sdk/metric/aggregator/minmaxsumcount/mmsc.go | 5 ++++ sdk/metric/aggregator/sum/sum.go | 5 ++++ 7 files changed, 53 insertions(+), 7 deletions(-) diff --git a/sdk/export/metric/aggregation/aggregation.go b/sdk/export/metric/aggregation/aggregation.go index f7951b63e..e87d1cca2 100644 --- a/sdk/export/metric/aggregation/aggregation.go +++ b/sdk/export/metric/aggregation/aggregation.go @@ -27,6 +27,9 @@ import ( type ( // Aggregation is an interface returned by the Aggregator // containing an interval of metric data. + // + // Note that the interfaces below do not embed this interface. + // Aggregators are expected to Aggregation interface { // Kind returns a short identifying string to identify // the Aggregator that was used to produce the @@ -36,37 +39,44 @@ type ( // Sum returns an aggregated sum. Sum interface { + Aggregation Sum() (metric.Number, error) } // Sum returns the number of values that were aggregated. Count interface { + Aggregation Count() (int64, error) } // Min returns the minimum value over the set of values that were aggregated. Min interface { + Aggregation Min() (metric.Number, error) } // Max returns the maximum value over the set of values that were aggregated. Max interface { + Aggregation Max() (metric.Number, error) } // Quantile returns an exact or estimated quantile over the // set of values that were aggregated. Quantile interface { + Aggregation Quantile(float64) (metric.Number, error) } // LastValue returns the latest value that was aggregated. LastValue interface { + Aggregation LastValue() (metric.Number, time.Time, error) } // Points returns the raw set of values that were aggregated. Points interface { + Aggregation Points() ([]metric.Number, error) } @@ -87,23 +97,29 @@ type ( // Histogram returns the count of events in pre-determined buckets. Histogram interface { - Sum + Aggregation + Sum() (metric.Number, error) Histogram() (Buckets, error) } // MinMaxSumCount supports the Min, Max, Sum, and Count interfaces. MinMaxSumCount interface { - Min - Max - Sum - Count + Aggregation + Min() (metric.Number, error) + Max() (metric.Number, error) + Sum() (metric.Number, error) + Count() (int64, error) } // Distribution supports the Min, Max, Sum, Count, and Quantile // interfaces. Distribution interface { - MinMaxSumCount - Quantile + Aggregation + Min() (metric.Number, error) + Max() (metric.Number, error) + Sum() (metric.Number, error) + Count() (int64, error) + Quantile(float64) (metric.Number, error) } ) diff --git a/sdk/metric/aggregator/array/array.go b/sdk/metric/aggregator/array/array.go index 028400052..6557f693b 100644 --- a/sdk/metric/aggregator/array/array.go +++ b/sdk/metric/aggregator/array/array.go @@ -53,6 +53,11 @@ func New() *Aggregator { return &Aggregator{} } +// Kind returns aggregation.ExactKind. +func (c *Aggregator) Kind() aggregation.Kind { + return aggregation.ExactKind +} + // Sum returns the sum of values in the checkpoint. func (c *Aggregator) Sum() (metric.Number, error) { return c.ckptSum, nil diff --git a/sdk/metric/aggregator/ddsketch/ddsketch.go b/sdk/metric/aggregator/ddsketch/ddsketch.go index 19047c4d9..01f30a57e 100644 --- a/sdk/metric/aggregator/ddsketch/ddsketch.go +++ b/sdk/metric/aggregator/ddsketch/ddsketch.go @@ -52,6 +52,11 @@ func New(desc *metric.Descriptor, cfg *Config) *Aggregator { } } +// Kind returns aggregation.SketchKind. +func (c *Aggregator) Kind() aggregation.Kind { + return aggregation.SketchKind +} + // NewDefaultConfig returns a new, default DDSketch config. // // TODO: Should the Config constructor set minValue to -Inf to diff --git a/sdk/metric/aggregator/histogram/histogram.go b/sdk/metric/aggregator/histogram/histogram.go index e72e8038f..8319b2e62 100644 --- a/sdk/metric/aggregator/histogram/histogram.go +++ b/sdk/metric/aggregator/histogram/histogram.go @@ -80,6 +80,11 @@ func New(desc *metric.Descriptor, boundaries []float64) *Aggregator { } } +// Kind returns aggregation.HistogramKind. +func (c *Aggregator) Kind() aggregation.Kind { + return aggregation.HistogramKind +} + // Sum returns the sum of all values in the checkpoint. func (c *Aggregator) Sum() (metric.Number, error) { c.lock.Lock() diff --git a/sdk/metric/aggregator/lastvalue/lastvalue.go b/sdk/metric/aggregator/lastvalue/lastvalue.go index a5837f48e..cd7c5b926 100644 --- a/sdk/metric/aggregator/lastvalue/lastvalue.go +++ b/sdk/metric/aggregator/lastvalue/lastvalue.go @@ -68,6 +68,11 @@ func New() *Aggregator { } } +// Kind returns aggregation.LastValueKind. +func (g *Aggregator) Kind() aggregation.Kind { + return aggregation.LastValueKind +} + // LastValue returns the last-recorded lastValue value and the // corresponding timestamp. The error value aggregation.ErrNoData // will be returned if (due to a race condition) the checkpoint was diff --git a/sdk/metric/aggregator/minmaxsumcount/mmsc.go b/sdk/metric/aggregator/minmaxsumcount/mmsc.go index 11c3c2c82..44bdd3402 100644 --- a/sdk/metric/aggregator/minmaxsumcount/mmsc.go +++ b/sdk/metric/aggregator/minmaxsumcount/mmsc.go @@ -63,6 +63,11 @@ func New(desc *metric.Descriptor) *Aggregator { } } +// Kind returns aggregation.MinMaxSumCountKind. +func (c *Aggregator) Kind() aggregation.Kind { + return aggregation.MinMaxSumCountKind +} + // Sum returns the sum of values in the checkpoint. func (c *Aggregator) Sum() (metric.Number, error) { c.lock.Lock() diff --git a/sdk/metric/aggregator/sum/sum.go b/sdk/metric/aggregator/sum/sum.go index ce35ef8ae..9fcedc848 100644 --- a/sdk/metric/aggregator/sum/sum.go +++ b/sdk/metric/aggregator/sum/sum.go @@ -44,6 +44,11 @@ func New() *Aggregator { return &Aggregator{} } +// Kind returns aggregation.SumKind. +func (c *Aggregator) Kind() aggregation.Kind { + return aggregation.SumKind +} + // Sum returns the last-checkpointed sum. This will never return an // error. func (c *Aggregator) Sum() (metric.Number, error) {