From 425e9ce2ff08474a5f143b2006f54c2bce325d28 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Thu, 14 Jul 2022 04:44:45 -0700 Subject: [PATCH] Use export.Aggregation instead of internal.Aggregation (#3007) * Use export.Aggregation instead of internal * Return an export.Aggregation instead of a slice --- sdk/metric/internal/aggregation.go | 61 ------------------- sdk/metric/internal/aggregator.go | 11 ++-- .../internal/aggregator_example_test.go | 12 ++-- sdk/metric/internal/histogram.go | 5 +- sdk/metric/internal/lastvalue.go | 7 ++- sdk/metric/internal/sum.go | 9 ++- 6 files changed, 27 insertions(+), 78 deletions(-) delete mode 100644 sdk/metric/internal/aggregation.go diff --git a/sdk/metric/internal/aggregation.go b/sdk/metric/internal/aggregation.go deleted file mode 100644 index f161d2debbf..00000000000 --- a/sdk/metric/internal/aggregation.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build go1.18 -// +build go1.18 - -package internal // import "go.opentelemetry.io/otel/sdk/metric/internal" - -import ( - "go.opentelemetry.io/otel/attribute" -) - -// Aggregation is a single data point in a timeseries that summarizes -// measurements made during a time span. -type Aggregation struct { - // TODO(#2968): Replace this with the export.Aggregation type once #2961 - // is merged. - - // Timestamp defines the time the last measurement was made. If zero, no - // measurements were made for this time span. The time is represented as a - // unix timestamp with nanosecond precision. - Timestamp uint64 - - // Attributes are the unique dimensions Value describes. - Attributes attribute.Set - - // Value is the summarization of the measurements made. - Value value -} - -type value interface { - private() -} - -// SingleValue summarizes a set of measurements as a single value. -type SingleValue[N int64 | float64] struct { - Value N -} - -func (SingleValue[N]) private() {} - -// HistogramValue summarizes a set of measurements as a histogram. -type HistogramValue struct { - Bounds []float64 - Counts []uint64 - Sum float64 - Min, Max float64 -} - -func (HistogramValue) private() {} diff --git a/sdk/metric/internal/aggregator.go b/sdk/metric/internal/aggregator.go index df8b59e84bb..c81c6f5432b 100644 --- a/sdk/metric/internal/aggregator.go +++ b/sdk/metric/internal/aggregator.go @@ -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" +) // Aggregator forms an aggregation from a collection of recorded measurements. type Aggregator[N int64 | float64] interface { @@ -25,7 +28,7 @@ type Aggregator[N int64 | float64] interface { // 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 } diff --git a/sdk/metric/internal/aggregator_example_test.go b/sdk/metric/internal/aggregator_example_test.go index 47fe2253818..c89acdd12f6 100644 --- a/sdk/metric/internal/aggregator_example_test.go +++ b/sdk/metric/internal/aggregator_example_test.go @@ -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 { @@ -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) @@ -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) @@ -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) diff --git a/sdk/metric/internal/histogram.go b/sdk/metric/internal/histogram.go index 6931c01f344..ddebf840b69 100644 --- a/sdk/metric/internal/histogram.go +++ b/sdk/metric/internal/histogram.go @@ -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 @@ -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 } @@ -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 } diff --git a/sdk/metric/internal/lastvalue.go b/sdk/metric/internal/lastvalue.go index 986a2313ad0..7c439d43e7d 100644 --- a/sdk/metric/internal/lastvalue.go +++ b/sdk/metric/internal/lastvalue.go @@ -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 { @@ -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 } diff --git a/sdk/metric/internal/sum.go b/sdk/metric/internal/sum.go index 6d01183fb03..35766e98dd3 100644 --- a/sdk/metric/internal/sum.go +++ b/sdk/metric/internal/sum.go @@ -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 { @@ -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 } @@ -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 }