Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move temporality to export/temporality #3017

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sdk/metric/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/metric/manual_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type manualReader struct {
producer atomic.Value
shutdownOnce sync.Once

temporalitySelector func(InstrumentKind) Temporality
temporalitySelector func(InstrumentKind) export.Temporality
aggregationSelector AggregationSelector
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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
}

Expand Down
14 changes: 8 additions & 6 deletions sdk/metric/manual_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -32,35 +34,35 @@ 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 {
name string
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",
options: []ManualReaderOption{
WithTemporalitySelector(deltaTemporalitySelector),
WithTemporalitySelector(cumulativeTemporalitySelector),
},
wantTemporality: CumulativeTemporality,
wantTemporality: export.CumulativeTemporality,
},
}

Expand Down
6 changes: 3 additions & 3 deletions sdk/metric/periodic_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
8 changes: 4 additions & 4 deletions sdk/metric/periodic_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,26 +191,26 @@ 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",
options: []PeriodicReaderOption{
WithTemporalitySelector(deltaTemporalitySelector),
WithTemporalitySelector(cumulativeTemporalitySelector),
},
wantTemporality: CumulativeTemporality,
wantTemporality: export.CumulativeTemporality,
},
}

Expand Down
10 changes: 5 additions & 5 deletions sdk/metric/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,6 @@ func TestDefaultTemporalitySelector(t *testing.T) {
AsyncUpDownCounter,
AsyncGauge,
} {
assert.Equal(t, CumulativeTemporality, DefaultTemporalitySelector(ik))
assert.Equal(t, export.CumulativeTemporality, DefaultTemporalitySelector(ik))
}
}
37 changes: 0 additions & 37 deletions sdk/metric/temporality.go

This file was deleted.