1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-07-13 01:00:22 +02:00

Add Aggregation.Kind()

This commit is contained in:
jmacd
2020-06-10 00:32:14 -07:00
parent bb2eb8ee26
commit 8483cc3d23
7 changed files with 53 additions and 7 deletions

View File

@ -27,6 +27,9 @@ import (
type ( type (
// Aggregation is an interface returned by the Aggregator // Aggregation is an interface returned by the Aggregator
// containing an interval of metric data. // containing an interval of metric data.
//
// Note that the interfaces below do not embed this interface.
// Aggregators are expected to
Aggregation interface { Aggregation interface {
// Kind returns a short identifying string to identify // Kind returns a short identifying string to identify
// the Aggregator that was used to produce the // the Aggregator that was used to produce the
@ -36,37 +39,44 @@ type (
// Sum returns an aggregated sum. // Sum returns an aggregated sum.
Sum interface { Sum interface {
Aggregation
Sum() (metric.Number, error) Sum() (metric.Number, error)
} }
// Sum returns the number of values that were aggregated. // Sum returns the number of values that were aggregated.
Count interface { Count interface {
Aggregation
Count() (int64, error) Count() (int64, error)
} }
// Min returns the minimum value over the set of values that were aggregated. // Min returns the minimum value over the set of values that were aggregated.
Min interface { Min interface {
Aggregation
Min() (metric.Number, error) Min() (metric.Number, error)
} }
// Max returns the maximum value over the set of values that were aggregated. // Max returns the maximum value over the set of values that were aggregated.
Max interface { Max interface {
Aggregation
Max() (metric.Number, error) Max() (metric.Number, error)
} }
// Quantile returns an exact or estimated quantile over the // Quantile returns an exact or estimated quantile over the
// set of values that were aggregated. // set of values that were aggregated.
Quantile interface { Quantile interface {
Aggregation
Quantile(float64) (metric.Number, error) Quantile(float64) (metric.Number, error)
} }
// LastValue returns the latest value that was aggregated. // LastValue returns the latest value that was aggregated.
LastValue interface { LastValue interface {
Aggregation
LastValue() (metric.Number, time.Time, error) LastValue() (metric.Number, time.Time, error)
} }
// Points returns the raw set of values that were aggregated. // Points returns the raw set of values that were aggregated.
Points interface { Points interface {
Aggregation
Points() ([]metric.Number, error) Points() ([]metric.Number, error)
} }
@ -87,23 +97,29 @@ type (
// Histogram returns the count of events in pre-determined buckets. // Histogram returns the count of events in pre-determined buckets.
Histogram interface { Histogram interface {
Sum Aggregation
Sum() (metric.Number, error)
Histogram() (Buckets, error) Histogram() (Buckets, error)
} }
// MinMaxSumCount supports the Min, Max, Sum, and Count interfaces. // MinMaxSumCount supports the Min, Max, Sum, and Count interfaces.
MinMaxSumCount interface { MinMaxSumCount interface {
Min Aggregation
Max Min() (metric.Number, error)
Sum Max() (metric.Number, error)
Count Sum() (metric.Number, error)
Count() (int64, error)
} }
// Distribution supports the Min, Max, Sum, Count, and Quantile // Distribution supports the Min, Max, Sum, Count, and Quantile
// interfaces. // interfaces.
Distribution interface { Distribution interface {
MinMaxSumCount Aggregation
Quantile Min() (metric.Number, error)
Max() (metric.Number, error)
Sum() (metric.Number, error)
Count() (int64, error)
Quantile(float64) (metric.Number, error)
} }
) )

View File

@ -53,6 +53,11 @@ func New() *Aggregator {
return &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. // Sum returns the sum of values in the checkpoint.
func (c *Aggregator) Sum() (metric.Number, error) { func (c *Aggregator) Sum() (metric.Number, error) {
return c.ckptSum, nil return c.ckptSum, nil

View File

@ -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. // NewDefaultConfig returns a new, default DDSketch config.
// //
// TODO: Should the Config constructor set minValue to -Inf to // TODO: Should the Config constructor set minValue to -Inf to

View File

@ -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. // Sum returns the sum of all values in the checkpoint.
func (c *Aggregator) Sum() (metric.Number, error) { func (c *Aggregator) Sum() (metric.Number, error) {
c.lock.Lock() c.lock.Lock()

View File

@ -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 // LastValue returns the last-recorded lastValue value and the
// corresponding timestamp. The error value aggregation.ErrNoData // corresponding timestamp. The error value aggregation.ErrNoData
// will be returned if (due to a race condition) the checkpoint was // will be returned if (due to a race condition) the checkpoint was

View File

@ -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. // Sum returns the sum of values in the checkpoint.
func (c *Aggregator) Sum() (metric.Number, error) { func (c *Aggregator) Sum() (metric.Number, error) {
c.lock.Lock() c.lock.Lock()

View File

@ -44,6 +44,11 @@ func New() *Aggregator {
return &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 // Sum returns the last-checkpointed sum. This will never return an
// error. // error.
func (c *Aggregator) Sum() (metric.Number, error) { func (c *Aggregator) Sum() (metric.Number, error) {