From 3c344c76ae8cc19a0c30f253cd7e79efb4227a0d Mon Sep 17 00:00:00 2001 From: Aaron Clawson <3766680+MadVikingGod@users.noreply.github.com> Date: Thu, 14 Jul 2022 08:00:55 -0400 Subject: [PATCH] move temporality to export/temporality (#3017) * move temporality to export/temporality * fix lint errors Co-authored-by: Tyler Yahn --- sdk/metric/config_test.go | 6 ++--- sdk/metric/manual_reader.go | 6 ++--- sdk/metric/manual_reader_test.go | 14 ++++++----- sdk/metric/periodic_reader.go | 6 ++--- sdk/metric/periodic_reader_test.go | 8 +++---- sdk/metric/reader.go | 10 ++++---- sdk/metric/reader_test.go | 2 +- sdk/metric/temporality.go | 37 ------------------------------ 8 files changed, 27 insertions(+), 62 deletions(-) delete mode 100644 sdk/metric/temporality.go diff --git a/sdk/metric/config_test.go b/sdk/metric/config_test.go index bca21769743..6f0d5c665d7 100644 --- a/sdk/metric/config_test.go +++ b/sdk/metric/config_test.go @@ -32,7 +32,7 @@ import ( type reader struct { producer producer - temporalityFunc func(InstrumentKind) Temporality + temporalityFunc func(InstrumentKind) export.Temporality aggregationFunc AggregationSelector collectFunc func(context.Context) (export.ResourceMetrics, error) forceFlushFunc func(context.Context) error @@ -45,8 +45,8 @@ func (r *reader) aggregation(kind InstrumentKind) aggregation.Aggregation { // n return r.aggregationFunc(kind) } -func (r *reader) register(p producer) { r.producer = p } -func (r *reader) temporality(kind InstrumentKind) Temporality { return r.temporalityFunc(kind) } +func (r *reader) register(p producer) { r.producer = p } +func (r *reader) temporality(kind InstrumentKind) export.Temporality { return r.temporalityFunc(kind) } func (r *reader) Collect(ctx context.Context) (export.ResourceMetrics, error) { return r.collectFunc(ctx) } diff --git a/sdk/metric/manual_reader.go b/sdk/metric/manual_reader.go index 1ded52c00ca..46728a485e3 100644 --- a/sdk/metric/manual_reader.go +++ b/sdk/metric/manual_reader.go @@ -34,7 +34,7 @@ type manualReader struct { producer atomic.Value shutdownOnce sync.Once - temporalitySelector func(InstrumentKind) Temporality + temporalitySelector func(InstrumentKind) export.Temporality aggregationSelector AggregationSelector } @@ -61,7 +61,7 @@ func (mr *manualReader) register(p producer) { } // temporality reports the Temporality for the instrument kind provided. -func (mr *manualReader) temporality(kind InstrumentKind) Temporality { +func (mr *manualReader) temporality(kind InstrumentKind) export.Temporality { return mr.temporalitySelector(kind) } @@ -111,7 +111,7 @@ func (mr *manualReader) Collect(ctx context.Context) (export.ResourceMetrics, er // manualReaderConfig contains configuration options for a ManualReader. type manualReaderConfig struct { - temporalitySelector func(InstrumentKind) Temporality + temporalitySelector func(InstrumentKind) export.Temporality aggregationSelector AggregationSelector } diff --git a/sdk/metric/manual_reader_test.go b/sdk/metric/manual_reader_test.go index dad27022780..fe615d3e32d 100644 --- a/sdk/metric/manual_reader_test.go +++ b/sdk/metric/manual_reader_test.go @@ -22,6 +22,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" + + "go.opentelemetry.io/otel/sdk/metric/export" ) func TestManualReader(t *testing.T) { @@ -32,8 +34,8 @@ func BenchmarkManualReader(b *testing.B) { b.Run("Collect", benchReaderCollectFunc(NewManualReader())) } -var deltaTemporalitySelector = func(InstrumentKind) Temporality { return DeltaTemporality } -var cumulativeTemporalitySelector = func(InstrumentKind) Temporality { return CumulativeTemporality } +var deltaTemporalitySelector = func(InstrumentKind) export.Temporality { return export.DeltaTemporality } +var cumulativeTemporalitySelector = func(InstrumentKind) export.Temporality { return export.CumulativeTemporality } func TestManualReaderTemporality(t *testing.T) { tests := []struct { @@ -41,18 +43,18 @@ func TestManualReaderTemporality(t *testing.T) { options []ManualReaderOption // Currently only testing constant temporality. This should be expanded // if we put more advanced selection in the SDK - wantTemporality Temporality + wantTemporality export.Temporality }{ { name: "default", - wantTemporality: CumulativeTemporality, + wantTemporality: export.CumulativeTemporality, }, { name: "delta", options: []ManualReaderOption{ WithTemporalitySelector(deltaTemporalitySelector), }, - wantTemporality: DeltaTemporality, + wantTemporality: export.DeltaTemporality, }, { name: "repeats overwrite", @@ -60,7 +62,7 @@ func TestManualReaderTemporality(t *testing.T) { WithTemporalitySelector(deltaTemporalitySelector), WithTemporalitySelector(cumulativeTemporalitySelector), }, - wantTemporality: CumulativeTemporality, + wantTemporality: export.CumulativeTemporality, }, } diff --git a/sdk/metric/periodic_reader.go b/sdk/metric/periodic_reader.go index 8f600f1fbc1..b227a47ba4f 100644 --- a/sdk/metric/periodic_reader.go +++ b/sdk/metric/periodic_reader.go @@ -40,7 +40,7 @@ const ( type periodicReaderConfig struct { interval time.Duration timeout time.Duration - temporalitySelector func(InstrumentKind) Temporality + temporalitySelector func(InstrumentKind) export.Temporality aggregationSelector AggregationSelector } @@ -140,7 +140,7 @@ type periodicReader struct { timeout time.Duration exporter Exporter - temporalitySelector func(InstrumentKind) Temporality + temporalitySelector func(InstrumentKind) export.Temporality aggregationSelector AggregationSelector wg sync.WaitGroup @@ -185,7 +185,7 @@ func (r *periodicReader) register(p producer) { } // temporality reports the Temporality for the instrument kind provided. -func (r *periodicReader) temporality(kind InstrumentKind) Temporality { +func (r *periodicReader) temporality(kind InstrumentKind) export.Temporality { return r.temporalitySelector(kind) } diff --git a/sdk/metric/periodic_reader_test.go b/sdk/metric/periodic_reader_test.go index 27cbda7e3ca..54b7c39e9a0 100644 --- a/sdk/metric/periodic_reader_test.go +++ b/sdk/metric/periodic_reader_test.go @@ -191,18 +191,18 @@ func TestPeriodiclReaderTemporality(t *testing.T) { options []PeriodicReaderOption // Currently only testing constant temporality. This should be expanded // if we put more advanced selection in the SDK - wantTemporality Temporality + wantTemporality export.Temporality }{ { name: "default", - wantTemporality: CumulativeTemporality, + wantTemporality: export.CumulativeTemporality, }, { name: "delta", options: []PeriodicReaderOption{ WithTemporalitySelector(deltaTemporalitySelector), }, - wantTemporality: DeltaTemporality, + wantTemporality: export.DeltaTemporality, }, { name: "repeats overwrite", @@ -210,7 +210,7 @@ func TestPeriodiclReaderTemporality(t *testing.T) { WithTemporalitySelector(deltaTemporalitySelector), WithTemporalitySelector(cumulativeTemporalitySelector), }, - wantTemporality: CumulativeTemporality, + wantTemporality: export.CumulativeTemporality, }, } diff --git a/sdk/metric/reader.go b/sdk/metric/reader.go index 3b71cac089c..dbbb25986be 100644 --- a/sdk/metric/reader.go +++ b/sdk/metric/reader.go @@ -58,7 +58,7 @@ type Reader interface { register(producer) // temporality reports the Temporality for the instrument kind provided. - temporality(InstrumentKind) Temporality + temporality(InstrumentKind) export.Temporality // aggregation returns what Aggregation to use for an instrument kind. aggregation(InstrumentKind) aggregation.Aggregation // nolint:revive // import-shadow for method scoped by type. @@ -118,13 +118,13 @@ type ReaderOption interface { } // TemporalitySelector selects the temporality to use based on the InstrumentKind. -type TemporalitySelector func(InstrumentKind) Temporality +type TemporalitySelector func(InstrumentKind) export.Temporality // DefaultTemporalitySelector is the default TemporalitySelector used if // WithTemporalitySelector is not provided. CumulativeTemporality will be used // for all instrument kinds if this TemporalitySelector is used. -func DefaultTemporalitySelector(InstrumentKind) Temporality { - return CumulativeTemporality +func DefaultTemporalitySelector(InstrumentKind) export.Temporality { + return export.CumulativeTemporality } // WithTemporalitySelector sets the TemporalitySelector a reader will use to @@ -135,7 +135,7 @@ func WithTemporalitySelector(selector TemporalitySelector) ReaderOption { } type temporalitySelectorOption struct { - selector func(instrument InstrumentKind) Temporality + selector func(instrument InstrumentKind) export.Temporality } // applyManual returns a manualReaderConfig with option applied. diff --git a/sdk/metric/reader_test.go b/sdk/metric/reader_test.go index 4a3c3429b44..41d8e5c6088 100644 --- a/sdk/metric/reader_test.go +++ b/sdk/metric/reader_test.go @@ -210,6 +210,6 @@ func TestDefaultTemporalitySelector(t *testing.T) { AsyncUpDownCounter, AsyncGauge, } { - assert.Equal(t, CumulativeTemporality, DefaultTemporalitySelector(ik)) + assert.Equal(t, export.CumulativeTemporality, DefaultTemporalitySelector(ik)) } } diff --git a/sdk/metric/temporality.go b/sdk/metric/temporality.go deleted file mode 100644 index fa896748287..00000000000 --- a/sdk/metric/temporality.go +++ /dev/null @@ -1,37 +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 metric // import "go.opentelemetry.io/otel/sdk/metric" - -// Temporality defines the window that an aggregation was calculated over. -type Temporality uint8 - -const ( - // undefinedTemporality represents an unset Temporality. - //nolint:deadcode,unused,varcheck - undefinedTemporality Temporality = iota - - // CumulativeTemporality defines a measurement interval that continues to - // expand forward in time from a starting point. New measurements are - // added to all previous measurements since a start time. - CumulativeTemporality - - // DeltaTemporality defines a measurement interval that resets each cycle. - // Measurements from one cycle are recorded independently, measurements - // from other cycles do not affect them. - DeltaTemporality -)