Skip to content

Commit

Permalink
Use export.Aggregation instead of internal.Aggregation (#3007)
Browse files Browse the repository at this point in the history
* Use export.Aggregation instead of internal

* Return an export.Aggregation instead of a slice
  • Loading branch information
MrAlias authored Jul 14, 2022
1 parent 5e69b7f commit 425e9ce
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 78 deletions.
61 changes: 0 additions & 61 deletions sdk/metric/internal/aggregation.go

This file was deleted.

11 changes: 7 additions & 4 deletions sdk/metric/internal/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@

package internal // import "go.opentelemetry.io/otel/sdk/metric/internal"

import "go.opentelemetry.io/otel/attribute"
import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/metric/export"
)

// Aggregator forms an aggregation from a collection of recorded measurements.
type Aggregator[N int64 | float64] interface {
// Aggregate records the measurement, scoped by attr, and aggregates it
// into an aggregation.
Aggregate(measurement N, attr attribute.Set)

// Aggregations returns a slice of Aggregation, one per each attribute set
// used to scope measurement aggregation, and ends an aggregation cycle.
Aggregations() []Aggregation
// Aggregation returns an Aggregation, for all the aggregated
// measurements made and ends an aggregation cycle.
Aggregation() export.Aggregation
}
12 changes: 6 additions & 6 deletions sdk/metric/internal/aggregator_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import (
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/instrument/syncint64"
"go.opentelemetry.io/otel/sdk/metric/aggregation"
"go.opentelemetry.io/otel/sdk/metric/export"
)

type meter struct {
// When a reader initiates a collection, the meter would collect
// aggregations from each of these functions. In this process they will
// progress the aggregation period of each instrument's aggregator.
aggregationFuncs []func() []Aggregation
// aggregations from each of these functions.
aggregations []export.Aggregation
}

func (m *meter) SyncInt64() syncint64.InstrumentProvider {
Expand All @@ -51,7 +51,7 @@ func (p *syncInt64Provider) Counter(string, ...instrument.Option) (syncint64.Cou
aggregator := NewCumulativeSum[int64]()
count := inst{aggregateFunc: aggregator.Aggregate}

p.aggregationFuncs = append(p.aggregationFuncs, aggregator.Aggregations)
p.aggregations = append(p.aggregations, aggregator.Aggregation())

fmt.Printf("using %T aggregator for counter\n", aggregator)

Expand All @@ -69,7 +69,7 @@ func (p *syncInt64Provider) UpDownCounter(string, ...instrument.Option) (syncint
aggregator := NewLastValue[int64]()
upDownCount := inst{aggregateFunc: aggregator.Aggregate}

p.aggregationFuncs = append(p.aggregationFuncs, aggregator.Aggregations)
p.aggregations = append(p.aggregations, aggregator.Aggregation())

fmt.Printf("using %T aggregator for up-down counter\n", aggregator)

Expand All @@ -89,7 +89,7 @@ func (p *syncInt64Provider) Histogram(string, ...instrument.Option) (syncint64.H
})
hist := inst{aggregateFunc: aggregator.Aggregate}

p.aggregationFuncs = append(p.aggregationFuncs, aggregator.Aggregations)
p.aggregations = append(p.aggregations, aggregator.Aggregation())

fmt.Printf("using %T aggregator for histogram\n", aggregator)

Expand Down
5 changes: 3 additions & 2 deletions sdk/metric/internal/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package internal // import "go.opentelemetry.io/otel/sdk/metric/internal"
import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/metric/aggregation"
"go.opentelemetry.io/otel/sdk/metric/export"
)

// histogram summarizes a set of measurements as an histogram with
Expand Down Expand Up @@ -51,7 +52,7 @@ type deltaHistogram[N int64 | float64] struct {
// TODO(#2970): implement.
}

func (s *deltaHistogram[N]) Aggregations() []Aggregation {
func (s *deltaHistogram[N]) Aggregation() export.Aggregation {
// TODO(#2970): implement.
return nil
}
Expand All @@ -74,7 +75,7 @@ type cumulativeHistogram[N int64 | float64] struct {
// TODO(#2970): implement.
}

func (s *cumulativeHistogram[N]) Aggregations() []Aggregation {
func (s *cumulativeHistogram[N]) Aggregation() export.Aggregation {
// TODO(#2970): implement.
return nil
}
7 changes: 5 additions & 2 deletions sdk/metric/internal/lastvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

package internal // import "go.opentelemetry.io/otel/sdk/metric/internal"

import "go.opentelemetry.io/otel/attribute"
import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/metric/export"
)

// lastValue summarizes a set of measurements as the last one made.
type lastValue[N int64 | float64] struct {
Expand All @@ -34,7 +37,7 @@ func (s *lastValue[N]) Aggregate(value N, attr attribute.Set) {
// TODO(#2971): implement.
}

func (s *lastValue[N]) Aggregations() []Aggregation {
func (s *lastValue[N]) Aggregation() export.Aggregation {
// TODO(#2971): implement.
return nil
}
9 changes: 6 additions & 3 deletions sdk/metric/internal/sum.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

package internal // import "go.opentelemetry.io/otel/sdk/metric/internal"

import "go.opentelemetry.io/otel/attribute"
import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/metric/export"
)

// sum summarizes a set of measurements as their arithmetic sum.
type sum[N int64 | float64] struct {
Expand Down Expand Up @@ -47,7 +50,7 @@ type deltaSum[N int64 | float64] struct {
// TODO(#2972): implement.
}

func (s *deltaSum[N]) Aggregations() []Aggregation {
func (s *deltaSum[N]) Aggregation() export.Aggregation {
// TODO(#2972): implement.
return nil
}
Expand All @@ -71,7 +74,7 @@ type cumulativeSum[N int64 | float64] struct {
// TODO(#2972): implement.
}

func (s *cumulativeSum[N]) Aggregations() []Aggregation {
func (s *cumulativeSum[N]) Aggregation() export.Aggregation {
// TODO(#2972): implement.
return nil
}

0 comments on commit 425e9ce

Please sign in to comment.