From b406a643022799986d062d60d22af4176c78baae Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Thu, 30 Sep 2021 17:28:02 -0700 Subject: [PATCH] Rename ExportKind to Temporality --- CHANGELOG.md | 1 + bridge/opencensus/exporter.go | 2 +- bridge/opencensus/exporter_test.go | 2 +- example/prometheus/main.go | 2 +- exporters/otlp/otlpmetric/exporter.go | 16 ++-- exporters/otlp/otlpmetric/exporter_test.go | 6 +- .../internal/metrictransform/metric.go | 28 +++--- .../internal/metrictransform/metric_test.go | 10 +- .../internal/otlpmetrictest/otlptest.go | 2 +- exporters/otlp/otlpmetric/options.go | 8 +- exporters/prometheus/prometheus.go | 6 +- exporters/prometheus/prometheus_test.go | 2 +- exporters/stdout/stdoutmetric/metric.go | 4 +- exporters/stdout/stdoutmetric/metric_test.go | 4 +- sdk/export/metric/exportkind_string.go | 25 ----- sdk/export/metric/metric.go | 92 +++++++++---------- sdk/export/metric/temporality_string.go | 25 +++++ ...exportkind_test.go => temporality_test.go} | 30 +++--- .../controller/basic/controller_test.go | 24 ++--- sdk/metric/controller/basic/pull_test.go | 14 +-- sdk/metric/controller/basic/push_test.go | 2 +- sdk/metric/controller/controllertest/test.go | 2 +- sdk/metric/processor/basic/basic.go | 32 +++---- sdk/metric/processor/basic/basic_test.go | 56 +++++------ sdk/metric/processor/processortest/test.go | 16 ++-- .../processor/processortest/test_test.go | 2 +- sdk/metric/processor/reducer/reducer_test.go | 2 +- 27 files changed, 208 insertions(+), 207 deletions(-) delete mode 100644 sdk/export/metric/exportkind_string.go create mode 100644 sdk/export/metric/temporality_string.go rename sdk/export/metric/{exportkind_test.go => temporality_test.go} (64%) diff --git a/CHANGELOG.md b/CHANGELOG.md index f80aa3ff0f4..bce411965c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Changed - NoopMeterProvider is now private and NewNoopMeterProvider must be used to obtain a noopMeterProvider. (#2237) +- Metric SDK `ExportKind`, `ExportKindSelector` types have been renamed `Temporality` and `TemporalitySelector` in line with current specification and protocol along with built-in selectors (e.g., `CumulativeTemporalitySelector`). (#xxxx) ## [1.0.0] - 2021-09-20 diff --git a/bridge/opencensus/exporter.go b/bridge/opencensus/exporter.go index 50f1242f266..6ff44a567d1 100644 --- a/bridge/opencensus/exporter.go +++ b/bridge/opencensus/exporter.go @@ -79,7 +79,7 @@ var _ export.Reader = &metricReader{} // ForEach iterates through the metrics data, synthesizing an // export.Record with the appropriate aggregation for the exporter. -func (d *metricReader) ForEach(exporter export.ExportKindSelector, f func(export.Record) error) error { +func (d *metricReader) ForEach(exporter export.TemporalitySelector, f func(export.Record) error) error { for _, m := range d.metrics { descriptor, err := convertDescriptor(m.Descriptor) if err != nil { diff --git a/bridge/opencensus/exporter_test.go b/bridge/opencensus/exporter_test.go index ee5d7607930..01d89847648 100644 --- a/bridge/opencensus/exporter_test.go +++ b/bridge/opencensus/exporter_test.go @@ -48,7 +48,7 @@ type fakeExporter struct { } func (f *fakeExporter) Export(ctx context.Context, res *resource.Resource, ilr exportmetric.InstrumentationLibraryReader) error { - return controllertest.ReadAll(ilr, export.StatelessExportKindSelector(), + return controllertest.ReadAll(ilr, export.StatelessTemporalitySelector(), func(_ instrumentation.Library, record exportmetric.Record) error { f.resource = res f.records = append(f.records, record) diff --git a/example/prometheus/main.go b/example/prometheus/main.go index 2ca4eb87443..f66e3d9b35e 100644 --- a/example/prometheus/main.go +++ b/example/prometheus/main.go @@ -44,7 +44,7 @@ func initMeter() { selector.NewWithHistogramDistribution( histogram.WithExplicitBoundaries(config.DefaultHistogramBoundaries), ), - export.CumulativeExportKindSelector(), + export.CumulativeTemporalitySelector(), processor.WithMemory(true), ), ) diff --git a/exporters/otlp/otlpmetric/exporter.go b/exporters/otlp/otlpmetric/exporter.go index 25930273aaf..3a0d3d63e38 100644 --- a/exporters/otlp/otlpmetric/exporter.go +++ b/exporters/otlp/otlpmetric/exporter.go @@ -33,8 +33,8 @@ var ( // Exporter exports metrics data in the OTLP wire format. type Exporter struct { - client Client - exportKindSelector metricsdk.ExportKindSelector + client Client + temporalitySelector metricsdk.TemporalitySelector mu sync.RWMutex started bool @@ -96,8 +96,8 @@ func (e *Exporter) Shutdown(ctx context.Context) error { return err } -func (e *Exporter) ExportKindFor(descriptor *metric.Descriptor, aggregatorKind aggregation.Kind) metricsdk.ExportKind { - return e.exportKindSelector.ExportKindFor(descriptor, aggregatorKind) +func (e *Exporter) TemporalityFor(descriptor *metric.Descriptor, aggregatorKind aggregation.Kind) metricsdk.Temporality { + return e.temporalitySelector.TemporalityFor(descriptor, aggregatorKind) } var _ metricsdk.Exporter = (*Exporter)(nil) @@ -114,10 +114,10 @@ func New(ctx context.Context, client Client, opts ...Option) (*Exporter, error) // NewUnstarted constructs a new Exporter and does not start it. func NewUnstarted(client Client, opts ...Option) *Exporter { cfg := config{ - // Note: the default ExportKindSelector is specified + // Note: the default TemporalitySelector is specified // as Cumulative: // https://github.com/open-telemetry/opentelemetry-specification/issues/731 - exportKindSelector: metricsdk.CumulativeExportKindSelector(), + temporalitySelector: metricsdk.CumulativeTemporalitySelector(), } for _, opt := range opts { @@ -125,8 +125,8 @@ func NewUnstarted(client Client, opts ...Option) *Exporter { } e := &Exporter{ - client: client, - exportKindSelector: cfg.exportKindSelector, + client: client, + temporalitySelector: cfg.temporalitySelector, } return e diff --git a/exporters/otlp/otlpmetric/exporter_test.go b/exporters/otlp/otlpmetric/exporter_test.go index f329627d0c4..e47754799d9 100644 --- a/exporters/otlp/otlpmetric/exporter_test.go +++ b/exporters/otlp/otlpmetric/exporter_test.go @@ -606,7 +606,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { ) } -func TestStatelessExportKind(t *testing.T) { +func TestStatelessTemporality(t *testing.T) { type testcase struct { name string instrumentKind sdkapi.InstrumentKind @@ -624,8 +624,8 @@ func TestStatelessExportKind(t *testing.T) { runMetricExportTests( t, []otlpmetric.Option{ - otlpmetric.WithMetricExportKindSelector( - metricsdk.StatelessExportKindSelector(), + otlpmetric.WithMetricTemporalitySelector( + metricsdk.StatelessTemporalitySelector(), ), }, testerAResource, diff --git a/exporters/otlp/otlpmetric/internal/metrictransform/metric.go b/exporters/otlp/otlpmetric/internal/metrictransform/metric.go index 8774db45f1e..1ea6fb30265 100644 --- a/exporters/otlp/otlpmetric/internal/metrictransform/metric.go +++ b/exporters/otlp/otlpmetric/internal/metrictransform/metric.go @@ -72,7 +72,7 @@ func toNanos(t time.Time) uint64 { // InstrumentationLibraryReader transforms all records contained in a checkpoint into // batched OTLP ResourceMetrics. -func InstrumentationLibraryReader(ctx context.Context, exportSelector export.ExportKindSelector, res *resource.Resource, ilmr export.InstrumentationLibraryReader, numWorkers uint) (*metricpb.ResourceMetrics, error) { +func InstrumentationLibraryReader(ctx context.Context, exportSelector export.TemporalitySelector, res *resource.Resource, ilmr export.InstrumentationLibraryReader, numWorkers uint) (*metricpb.ResourceMetrics, error) { var ilms []*metricpb.InstrumentationLibraryMetrics err := ilmr.ForEach(func(lib instrumentation.Library, mr export.Reader) error { @@ -134,7 +134,7 @@ func InstrumentationLibraryReader(ctx context.Context, exportSelector export.Exp // source starts a goroutine that sends each one of the Records yielded by // the Reader on the returned chan. Any error encountered will be sent // on the returned error chan after seeding is complete. -func source(ctx context.Context, exportSelector export.ExportKindSelector, mr export.Reader) (<-chan export.Record, <-chan error) { +func source(ctx context.Context, exportSelector export.TemporalitySelector, mr export.Reader) (<-chan export.Record, <-chan error) { errc := make(chan error, 1) out := make(chan export.Record) // Seed records into process. @@ -155,7 +155,7 @@ func source(ctx context.Context, exportSelector export.ExportKindSelector, mr ex // transformer transforms records read from the passed in chan into // OTLP Metrics which are sent on the out chan. -func transformer(ctx context.Context, exportSelector export.ExportKindSelector, in <-chan export.Record, out chan<- result) { +func transformer(ctx context.Context, exportSelector export.TemporalitySelector, in <-chan export.Record, out chan<- result) { for r := range in { m, err := Record(exportSelector, r) // Propagate errors, but do not send empty results. @@ -237,7 +237,7 @@ func sink(ctx context.Context, in <-chan result) ([]*metricpb.Metric, error) { // Record transforms a Record into an OTLP Metric. An ErrIncompatibleAgg // error is returned if the Record Aggregator is not supported. -func Record(exportSelector export.ExportKindSelector, r export.Record) (*metricpb.Metric, error) { +func Record(exportSelector export.TemporalitySelector, r export.Record) (*metricpb.Metric, error) { agg := r.Aggregation() switch agg.Kind() { case aggregation.MinMaxSumCountKind: @@ -252,7 +252,7 @@ func Record(exportSelector export.ExportKindSelector, r export.Record) (*metricp if !ok { return nil, fmt.Errorf("%w: %T", ErrIncompatibleAgg, agg) } - return histogramPoint(r, exportSelector.ExportKindFor(r.Descriptor(), aggregation.HistogramKind), h) + return histogramPoint(r, exportSelector.TemporalityFor(r.Descriptor(), aggregation.HistogramKind), h) case aggregation.SumKind: s, ok := agg.(aggregation.Sum) @@ -263,7 +263,7 @@ func Record(exportSelector export.ExportKindSelector, r export.Record) (*metricp if err != nil { return nil, err } - return sumPoint(r, sum, r.StartTime(), r.EndTime(), exportSelector.ExportKindFor(r.Descriptor(), aggregation.SumKind), r.Descriptor().InstrumentKind().Monotonic()) + return sumPoint(r, sum, r.StartTime(), r.EndTime(), exportSelector.TemporalityFor(r.Descriptor(), aggregation.SumKind), r.Descriptor().InstrumentKind().Monotonic()) case aggregation.LastValueKind: lv, ok := agg.(aggregation.LastValue) @@ -388,17 +388,17 @@ func gaugePoint(record export.Record, num number.Number, start, end time.Time) ( return m, nil } -func exportKindToTemporality(ek export.ExportKind) metricpb.AggregationTemporality { +func sdkTemporalityToTemporality(ek export.Temporality) metricpb.AggregationTemporality { switch ek { - case export.DeltaExportKind: + case export.DeltaTemporality: return metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA - case export.CumulativeExportKind: + case export.CumulativeTemporality: return metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE } return metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED } -func sumPoint(record export.Record, num number.Number, start, end time.Time, ek export.ExportKind, monotonic bool) (*metricpb.Metric, error) { +func sumPoint(record export.Record, num number.Number, start, end time.Time, ek export.Temporality, monotonic bool) (*metricpb.Metric, error) { desc := record.Descriptor() labels := record.Labels() @@ -413,7 +413,7 @@ func sumPoint(record export.Record, num number.Number, start, end time.Time, ek m.Data = &metricpb.Metric_Sum{ Sum: &metricpb.Sum{ IsMonotonic: monotonic, - AggregationTemporality: exportKindToTemporality(ek), + AggregationTemporality: sdkTemporalityToTemporality(ek), DataPoints: []*metricpb.NumberDataPoint{ { Value: &metricpb.NumberDataPoint_AsInt{ @@ -430,7 +430,7 @@ func sumPoint(record export.Record, num number.Number, start, end time.Time, ek m.Data = &metricpb.Metric_Sum{ Sum: &metricpb.Sum{ IsMonotonic: monotonic, - AggregationTemporality: exportKindToTemporality(ek), + AggregationTemporality: sdkTemporalityToTemporality(ek), DataPoints: []*metricpb.NumberDataPoint{ { Value: &metricpb.NumberDataPoint_AsDouble{ @@ -522,7 +522,7 @@ func histogramValues(a aggregation.Histogram) (boundaries []float64, counts []ui } // histogram transforms a Histogram Aggregator into an OTLP Metric. -func histogramPoint(record export.Record, ek export.ExportKind, a aggregation.Histogram) (*metricpb.Metric, error) { +func histogramPoint(record export.Record, ek export.Temporality, a aggregation.Histogram) (*metricpb.Metric, error) { desc := record.Descriptor() labels := record.Labels() boundaries, counts, err := histogramValues(a) @@ -546,7 +546,7 @@ func histogramPoint(record export.Record, ek export.ExportKind, a aggregation.Hi Unit: string(desc.Unit()), Data: &metricpb.Metric_Histogram{ Histogram: &metricpb.Histogram{ - AggregationTemporality: exportKindToTemporality(ek), + AggregationTemporality: sdkTemporalityToTemporality(ek), DataPoints: []*metricpb.HistogramDataPoint{ { Sum: sum.CoerceToFloat64(desc.NumberKind()), diff --git a/exporters/otlp/otlpmetric/internal/metrictransform/metric_test.go b/exporters/otlp/otlpmetric/internal/metrictransform/metric_test.go index 9b339edfe53..45d72a258bf 100644 --- a/exporters/otlp/otlpmetric/internal/metrictransform/metric_test.go +++ b/exporters/otlp/otlpmetric/internal/metrictransform/metric_test.go @@ -191,7 +191,7 @@ func TestSumIntDataPoints(t *testing.T) { value, err := ckpt.Sum() require.NoError(t, err) - if m, err := sumPoint(record, value, record.StartTime(), record.EndTime(), export.CumulativeExportKind, true); assert.NoError(t, err) { + if m, err := sumPoint(record, value, record.StartTime(), record.EndTime(), export.CumulativeTemporality, true); assert.NoError(t, err) { assert.Nil(t, m.GetGauge()) assert.Equal(t, &metricpb.Sum{ AggregationTemporality: otelCumulative, @@ -230,7 +230,7 @@ func TestSumFloatDataPoints(t *testing.T) { value, err := ckpt.Sum() require.NoError(t, err) - if m, err := sumPoint(record, value, record.StartTime(), record.EndTime(), export.DeltaExportKind, false); assert.NoError(t, err) { + if m, err := sumPoint(record, value, record.StartTime(), record.EndTime(), export.DeltaTemporality, false); assert.NoError(t, err) { assert.Nil(t, m.GetGauge()) assert.Equal(t, &metricpb.Sum{ IsMonotonic: false, @@ -368,7 +368,7 @@ func TestSumErrUnknownValueType(t *testing.T) { value, err := s.Sum() require.NoError(t, err) - _, err = sumPoint(record, value, record.StartTime(), record.EndTime(), export.CumulativeExportKind, true) + _, err = sumPoint(record, value, record.StartTime(), record.EndTime(), export.CumulativeTemporality, true) assert.Error(t, err) if !errors.Is(err, ErrUnknownValueType) { t.Errorf("expected ErrUnknownValueType, got %v", err) @@ -452,7 +452,7 @@ func TestRecordAggregatorIncompatibleErrors(t *testing.T) { kind: kind, agg: agg, } - return Record(export.CumulativeExportKindSelector(), export.NewRecord(&desc, &labels, test, intervalStart, intervalEnd)) + return Record(export.CumulativeTemporalitySelector(), export.NewRecord(&desc, &labels, test, intervalStart, intervalEnd)) } mpb, err := makeMpb(aggregation.SumKind, &lastvalue.New(1)[0]) @@ -484,7 +484,7 @@ func TestRecordAggregatorUnexpectedErrors(t *testing.T) { makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) { desc := metrictest.NewDescriptor("things", sdkapi.CounterInstrumentKind, number.Int64Kind) labels := attribute.NewSet() - return Record(export.CumulativeExportKindSelector(), export.NewRecord(&desc, &labels, agg, intervalStart, intervalEnd)) + return Record(export.CumulativeTemporalitySelector(), export.NewRecord(&desc, &labels, agg, intervalStart, intervalEnd)) } errEx := fmt.Errorf("timeout") diff --git a/exporters/otlp/otlpmetric/internal/otlpmetrictest/otlptest.go b/exporters/otlp/otlpmetric/internal/otlpmetrictest/otlptest.go index a1328312781..94fc5dbae85 100644 --- a/exporters/otlp/otlpmetric/internal/otlpmetrictest/otlptest.go +++ b/exporters/otlp/otlpmetric/internal/otlpmetrictest/otlptest.go @@ -40,7 +40,7 @@ import ( // themselves. func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlpmetric.Exporter, mcMetrics Collector) { selector := simple.NewWithInexpensiveDistribution() - proc := processor.NewFactory(selector, exportmetric.StatelessExportKindSelector()) + proc := processor.NewFactory(selector, exportmetric.StatelessTemporalitySelector()) cont := controller.New(proc, controller.WithExporter(exp)) require.NoError(t, cont.Start(ctx)) diff --git a/exporters/otlp/otlpmetric/options.go b/exporters/otlp/otlpmetric/options.go index 54ce1d0df79..be684b902bc 100644 --- a/exporters/otlp/otlpmetric/options.go +++ b/exporters/otlp/otlpmetric/options.go @@ -28,15 +28,15 @@ func (fn exporterOptionFunc) apply(cfg *config) { } type config struct { - exportKindSelector metricsdk.ExportKindSelector + temporalitySelector metricsdk.TemporalitySelector } -// WithMetricExportKindSelector defines the ExportKindSelector used +// WithMetricTemporalitySelector defines the TemporalitySelector used // for selecting AggregationTemporality (i.e., Cumulative vs. Delta // aggregation). If not specified otherwise, exporter will use a // cumulative export kind selector. -func WithMetricExportKindSelector(selector metricsdk.ExportKindSelector) Option { +func WithMetricTemporalitySelector(selector metricsdk.TemporalitySelector) Option { return exporterOptionFunc(func(cfg *config) { - cfg.exportKindSelector = selector + cfg.temporalitySelector = selector }) } diff --git a/exporters/prometheus/prometheus.go b/exporters/prometheus/prometheus.go index 572feff5701..4c2ae4d6388 100644 --- a/exporters/prometheus/prometheus.go +++ b/exporters/prometheus/prometheus.go @@ -131,9 +131,9 @@ func (e *Exporter) Controller() *controller.Controller { return e.controller } -// ExportKindFor implements ExportKindSelector. -func (e *Exporter) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) export.ExportKind { - return export.CumulativeExportKindSelector().ExportKindFor(desc, kind) +// TemporalityFor implements TemporalitySelector. +func (e *Exporter) TemporalityFor(desc *metric.Descriptor, kind aggregation.Kind) export.Temporality { + return export.CumulativeTemporalitySelector().TemporalityFor(desc, kind) } // ServeHTTP implements http.Handler. diff --git a/exporters/prometheus/prometheus_test.go b/exporters/prometheus/prometheus_test.go index f1b217541fb..0ad12a8eb28 100644 --- a/exporters/prometheus/prometheus_test.go +++ b/exporters/prometheus/prometheus_test.go @@ -88,7 +88,7 @@ func newPipeline(config prometheus.Config, options ...controller.Option) (*prome selector.NewWithHistogramDistribution( histogram.WithExplicitBoundaries(config.DefaultHistogramBoundaries), ), - export.CumulativeExportKindSelector(), + export.CumulativeTemporalitySelector(), processor.WithMemory(true), ), options..., diff --git a/exporters/stdout/stdoutmetric/metric.go b/exporters/stdout/stdoutmetric/metric.go index 7ad8495b0e0..3f6694b270f 100644 --- a/exporters/stdout/stdoutmetric/metric.go +++ b/exporters/stdout/stdoutmetric/metric.go @@ -47,8 +47,8 @@ type line struct { Timestamp *time.Time `json:"Timestamp,omitempty"` } -func (e *metricExporter) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) exportmetric.ExportKind { - return exportmetric.StatelessExportKindSelector().ExportKindFor(desc, kind) +func (e *metricExporter) TemporalityFor(desc *metric.Descriptor, kind aggregation.Kind) exportmetric.Temporality { + return exportmetric.StatelessTemporalitySelector().TemporalityFor(desc, kind) } func (e *metricExporter) Export(_ context.Context, res *resource.Resource, reader exportmetric.InstrumentationLibraryReader) error { diff --git a/exporters/stdout/stdoutmetric/metric_test.go b/exporters/stdout/stdoutmetric/metric_test.go index 85ae1f3fb8e..4083a13c95c 100644 --- a/exporters/stdout/stdoutmetric/metric_test.go +++ b/exporters/stdout/stdoutmetric/metric_test.go @@ -61,7 +61,7 @@ func newFixtureWithResource(t *testing.T, res *resource.Resource, opts ...stdout t.Fatal("Error building fixture: ", err) } aggSel := processortest.AggregatorSelector() - proc := processor.NewFactory(aggSel, export.StatelessExportKindSelector()) + proc := processor.NewFactory(aggSel, export.StatelessTemporalitySelector()) cont := controller.New(proc, controller.WithExporter(exp), controller.WithResource(res), @@ -87,7 +87,7 @@ func (fix testFixture) Output() string { func TestStdoutTimestamp(t *testing.T) { var buf bytes.Buffer aggSel := processortest.AggregatorSelector() - proc := processor.NewFactory(aggSel, export.CumulativeExportKindSelector()) + proc := processor.NewFactory(aggSel, export.CumulativeTemporalitySelector()) exporter, err := stdoutmetric.New( stdoutmetric.WithWriter(&buf), ) diff --git a/sdk/export/metric/exportkind_string.go b/sdk/export/metric/exportkind_string.go deleted file mode 100644 index 3a04abdd575..00000000000 --- a/sdk/export/metric/exportkind_string.go +++ /dev/null @@ -1,25 +0,0 @@ -// Code generated by "stringer -type=ExportKind"; DO NOT EDIT. - -package metric // import "go.opentelemetry.io/otel/sdk/export/metric" - -import "strconv" - -func _() { - // An "invalid array index" compiler error signifies that the constant values have changed. - // Re-run the stringer command to generate them again. - var x [1]struct{} - _ = x[CumulativeExportKind-1] - _ = x[DeltaExportKind-2] -} - -const _ExportKind_name = "CumulativeExportKindDeltaExportKind" - -var _ExportKind_index = [...]uint8{0, 20, 35} - -func (i ExportKind) String() string { - i -= 1 - if i < 0 || i >= ExportKind(len(_ExportKind_index)-1) { - return "ExportKind(" + strconv.FormatInt(int64(i+1), 10) + ")" - } - return _ExportKind_name[_ExportKind_index[i]:_ExportKind_index[i+1]] -} diff --git a/sdk/export/metric/metric.go b/sdk/export/metric/metric.go index 46c8d99a565..c1a7869d8d2 100644 --- a/sdk/export/metric/metric.go +++ b/sdk/export/metric/metric.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:generate stringer -type=ExportKind +//go:generate stringer -type=Temporality package metric // import "go.opentelemetry.io/otel/sdk/export/metric" @@ -220,20 +220,20 @@ type Exporter interface { // Processor that just completed collection. Export(ctx context.Context, resource *resource.Resource, reader InstrumentationLibraryReader) error - // ExportKindSelector is an interface used by the Processor + // TemporalitySelector is an interface used by the Processor // in deciding whether to compute Delta or Cumulative // Aggregations when passing Records to this Exporter. - ExportKindSelector + TemporalitySelector } -// ExportKindSelector is a sub-interface of Exporter used to indicate +// TemporalitySelector is a sub-interface of Exporter used to indicate // whether the Processor should compute Delta or Cumulative // Aggregations. -type ExportKindSelector interface { - // ExportKindFor should return the correct ExportKind that +type TemporalitySelector interface { + // TemporalityFor should return the correct Temporality that // should be used when exporting data for the given metric // instrument and Aggregator kind. - ExportKindFor(descriptor *metric.Descriptor, aggregatorKind aggregation.Kind) ExportKind + TemporalityFor(descriptor *metric.Descriptor, aggregatorKind aggregation.Kind) Temporality } // InstrumentationLibraryReader is an interface for exporters to iterate @@ -255,7 +255,7 @@ type Reader interface { // period. Each aggregated checkpoint returned by the // function parameter may return an error. // - // The ExportKindSelector argument is used to determine + // The TemporalitySelector argument is used to determine // whether the Record is computed using Delta or Cumulative // aggregation. // @@ -263,7 +263,7 @@ type Reader interface { // expected from the Meter implementation. Any other kind // of error will immediately halt ForEach and return // the error to the caller. - ForEach(kindSelector ExportKindSelector, recordFunc func(Record) error) error + ForEach(kindSelector TemporalitySelector, recordFunc func(Record) error) error // Locker supports locking the checkpoint set. Collection // into the checkpoint set cannot take place (in case of a @@ -366,38 +366,38 @@ func (r Record) EndTime() time.Time { return r.end } -// ExportKind indicates the kind of data exported by an exporter. +// Temporality indicates the kind of data exported by an exporter. // These bits may be OR-d together when multiple exporters are in use. -type ExportKind int +type Temporality int const ( - // CumulativeExportKind indicates that an Exporter expects a + // CumulativeTemporality indicates that an Exporter expects a // Cumulative Aggregation. - CumulativeExportKind ExportKind = 1 + CumulativeTemporality Temporality = 1 - // DeltaExportKind indicates that an Exporter expects a + // DeltaTemporality indicates that an Exporter expects a // Delta Aggregation. - DeltaExportKind ExportKind = 2 + DeltaTemporality Temporality = 2 ) // Includes tests whether `kind` includes a specific kind of // exporter. -func (kind ExportKind) Includes(has ExportKind) bool { +func (kind Temporality) Includes(has Temporality) bool { return kind&has != 0 } // MemoryRequired returns whether an exporter of this kind requires // memory to export correctly. -func (kind ExportKind) MemoryRequired(mkind sdkapi.InstrumentKind) bool { +func (kind Temporality) MemoryRequired(mkind sdkapi.InstrumentKind) bool { switch mkind { case sdkapi.HistogramInstrumentKind, sdkapi.GaugeObserverInstrumentKind, sdkapi.CounterInstrumentKind, sdkapi.UpDownCounterInstrumentKind: // Delta-oriented instruments: - return kind.Includes(CumulativeExportKind) + return kind.Includes(CumulativeTemporality) case sdkapi.CounterObserverInstrumentKind, sdkapi.UpDownCounterObserverInstrumentKind: // Cumulative-oriented instruments: - return kind.Includes(DeltaExportKind) + return kind.Includes(DeltaTemporality) } // Something unexpected is happening--we could panic. This // will become an error when the exporter tries to access a @@ -406,49 +406,49 @@ func (kind ExportKind) MemoryRequired(mkind sdkapi.InstrumentKind) bool { } type ( - constantExportKindSelector ExportKind - statelessExportKindSelector struct{} + constantTemporalitySelector Temporality + statelessTemporalitySelector struct{} ) var ( - _ ExportKindSelector = constantExportKindSelector(0) - _ ExportKindSelector = statelessExportKindSelector{} + _ TemporalitySelector = constantTemporalitySelector(0) + _ TemporalitySelector = statelessTemporalitySelector{} ) -// ConstantExportKindSelector returns an ExportKindSelector that returns -// a constant ExportKind, one that is either always cumulative or always delta. -func ConstantExportKindSelector(kind ExportKind) ExportKindSelector { - return constantExportKindSelector(kind) +// ConstantTemporalitySelector returns an TemporalitySelector that returns +// a constant Temporality, one that is either always cumulative or always delta. +func ConstantTemporalitySelector(kind Temporality) TemporalitySelector { + return constantTemporalitySelector(kind) } -// CumulativeExportKindSelector returns an ExportKindSelector that -// always returns CumulativeExportKind. -func CumulativeExportKindSelector() ExportKindSelector { - return ConstantExportKindSelector(CumulativeExportKind) +// CumulativeTemporalitySelector returns an TemporalitySelector that +// always returns CumulativeTemporality. +func CumulativeTemporalitySelector() TemporalitySelector { + return ConstantTemporalitySelector(CumulativeTemporality) } -// DeltaExportKindSelector returns an ExportKindSelector that -// always returns DeltaExportKind. -func DeltaExportKindSelector() ExportKindSelector { - return ConstantExportKindSelector(DeltaExportKind) +// DeltaTemporalitySelector returns an TemporalitySelector that +// always returns DeltaTemporality. +func DeltaTemporalitySelector() TemporalitySelector { + return ConstantTemporalitySelector(DeltaTemporality) } -// StatelessExportKindSelector returns an ExportKindSelector that -// always returns the ExportKind that avoids long-term memory +// StatelessTemporalitySelector returns an TemporalitySelector that +// always returns the Temporality that avoids long-term memory // requirements. -func StatelessExportKindSelector() ExportKindSelector { - return statelessExportKindSelector{} +func StatelessTemporalitySelector() TemporalitySelector { + return statelessTemporalitySelector{} } -// ExportKindFor implements ExportKindSelector. -func (c constantExportKindSelector) ExportKindFor(_ *metric.Descriptor, _ aggregation.Kind) ExportKind { - return ExportKind(c) +// TemporalityFor implements TemporalitySelector. +func (c constantTemporalitySelector) TemporalityFor(_ *metric.Descriptor, _ aggregation.Kind) Temporality { + return Temporality(c) } -// ExportKindFor implements ExportKindSelector. -func (s statelessExportKindSelector) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) ExportKind { +// TemporalityFor implements TemporalitySelector. +func (s statelessTemporalitySelector) TemporalityFor(desc *metric.Descriptor, kind aggregation.Kind) Temporality { if kind == aggregation.SumKind && desc.InstrumentKind().PrecomputedSum() { - return CumulativeExportKind + return CumulativeTemporality } - return DeltaExportKind + return DeltaTemporality } diff --git a/sdk/export/metric/temporality_string.go b/sdk/export/metric/temporality_string.go new file mode 100644 index 00000000000..7f43620f3d2 --- /dev/null +++ b/sdk/export/metric/temporality_string.go @@ -0,0 +1,25 @@ +// Code generated by "stringer -type=Temporality"; DO NOT EDIT. + +package metric // import "go.opentelemetry.io/otel/sdk/export/metric" + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[CumulativeTemporality-1] + _ = x[DeltaTemporality-2] +} + +const _Temporality_name = "CumulativeTemporalityDeltaTemporality" + +var _Temporality_index = [...]uint8{0, 21, 37} + +func (i Temporality) String() string { + i -= 1 + if i < 0 || i >= Temporality(len(_Temporality_index)-1) { + return "Temporality(" + strconv.FormatInt(int64(i+1), 10) + ")" + } + return _Temporality_name[_Temporality_index[i]:_Temporality_index[i+1]] +} diff --git a/sdk/export/metric/exportkind_test.go b/sdk/export/metric/temporality_test.go similarity index 64% rename from sdk/export/metric/exportkind_test.go rename to sdk/export/metric/temporality_test.go index 2d8c1602841..6d6800ff9c7 100644 --- a/sdk/export/metric/exportkind_test.go +++ b/sdk/export/metric/temporality_test.go @@ -25,9 +25,9 @@ import ( "go.opentelemetry.io/otel/sdk/export/metric/aggregation" ) -func TestExportKindIncludes(t *testing.T) { - require.True(t, CumulativeExportKind.Includes(CumulativeExportKind)) - require.True(t, DeltaExportKind.Includes(CumulativeExportKind|DeltaExportKind)) +func TestTemporalityIncludes(t *testing.T) { + require.True(t, CumulativeTemporality.Includes(CumulativeTemporality)) + require.True(t, DeltaTemporality.Includes(CumulativeTemporality|DeltaTemporality)) } var deltaMemoryKinds = []sdkapi.InstrumentKind{ @@ -42,22 +42,22 @@ var cumulativeMemoryKinds = []sdkapi.InstrumentKind{ sdkapi.UpDownCounterInstrumentKind, } -func TestExportKindMemoryRequired(t *testing.T) { +func TestTemporalityMemoryRequired(t *testing.T) { for _, kind := range deltaMemoryKinds { - require.True(t, DeltaExportKind.MemoryRequired(kind)) - require.False(t, CumulativeExportKind.MemoryRequired(kind)) + require.True(t, DeltaTemporality.MemoryRequired(kind)) + require.False(t, CumulativeTemporality.MemoryRequired(kind)) } for _, kind := range cumulativeMemoryKinds { - require.True(t, CumulativeExportKind.MemoryRequired(kind)) - require.False(t, DeltaExportKind.MemoryRequired(kind)) + require.True(t, CumulativeTemporality.MemoryRequired(kind)) + require.False(t, DeltaTemporality.MemoryRequired(kind)) } } -func TestExportKindSelectors(t *testing.T) { - ceks := CumulativeExportKindSelector() - deks := DeltaExportKindSelector() - seks := StatelessExportKindSelector() +func TestTemporalitySelectors(t *testing.T) { + ceks := CumulativeTemporalitySelector() + deks := DeltaTemporalitySelector() + seks := StatelessTemporalitySelector() for _, ikind := range append(deltaMemoryKinds, cumulativeMemoryKinds...) { desc := metrictest.NewDescriptor("instrument", ikind, number.Int64Kind) @@ -68,8 +68,8 @@ func TestExportKindSelectors(t *testing.T) { } else { akind = aggregation.HistogramKind } - require.Equal(t, CumulativeExportKind, ceks.ExportKindFor(&desc, akind)) - require.Equal(t, DeltaExportKind, deks.ExportKindFor(&desc, akind)) - require.False(t, seks.ExportKindFor(&desc, akind).MemoryRequired(ikind)) + require.Equal(t, CumulativeTemporality, ceks.TemporalityFor(&desc, akind)) + require.Equal(t, DeltaTemporality, deks.TemporalityFor(&desc, akind)) + require.False(t, seks.TemporalityFor(&desc, akind).MemoryRequired(ikind)) } } diff --git a/sdk/metric/controller/basic/controller_test.go b/sdk/metric/controller/basic/controller_test.go index 4cca2cc2442..6beadbd68c7 100644 --- a/sdk/metric/controller/basic/controller_test.go +++ b/sdk/metric/controller/basic/controller_test.go @@ -44,7 +44,7 @@ func getMap(t *testing.T, cont *controller.Controller) map[string]float64 { require.NoError(t, cont.ForEach( func(_ instrumentation.Library, reader export.Reader) error { return reader.ForEach( - export.CumulativeExportKindSelector(), + export.CumulativeTemporalitySelector(), func(record export.Record) error { return out.AddRecord(record) }, @@ -114,7 +114,7 @@ func TestControllerUsesResource(t *testing.T) { } for _, c := range cases { t.Run(fmt.Sprintf("case-%s", c.name), func(t *testing.T) { - sel := export.CumulativeExportKindSelector() + sel := export.CumulativeTemporalitySelector() exp := processortest.New(sel, attribute.DefaultEncoder()) cont := controller.New( processor.NewFactory( @@ -144,7 +144,7 @@ func TestStartNoExporter(t *testing.T) { cont := controller.New( processor.NewFactory( processortest.AggregatorSelector(), - export.CumulativeExportKindSelector(), + export.CumulativeTemporalitySelector(), ), controller.WithCollectPeriod(time.Second), controller.WithResource(resource.Empty()), @@ -213,7 +213,7 @@ func TestObserverCanceled(t *testing.T) { cont := controller.New( processor.NewFactory( processortest.AggregatorSelector(), - export.CumulativeExportKindSelector(), + export.CumulativeTemporalitySelector(), ), controller.WithCollectPeriod(0), controller.WithCollectTimeout(time.Millisecond), @@ -245,7 +245,7 @@ func TestObserverContext(t *testing.T) { cont := controller.New( processor.NewFactory( processortest.AggregatorSelector(), - export.CumulativeExportKindSelector(), + export.CumulativeTemporalitySelector(), ), controller.WithCollectTimeout(0), controller.WithResource(resource.Empty()), @@ -277,7 +277,7 @@ type blockingExporter struct { func newBlockingExporter() *blockingExporter { return &blockingExporter{ exporter: processortest.New( - export.CumulativeExportKindSelector(), + export.CumulativeTemporalitySelector(), attribute.DefaultEncoder(), ), } @@ -295,11 +295,11 @@ func (b *blockingExporter) Export(ctx context.Context, res *resource.Resource, o return err } -func (*blockingExporter) ExportKindFor( +func (*blockingExporter) TemporalityFor( *metric.Descriptor, aggregation.Kind, -) export.ExportKind { - return export.CumulativeExportKind +) export.Temporality { + return export.CumulativeTemporality } func TestExportTimeout(t *testing.T) { @@ -307,7 +307,7 @@ func TestExportTimeout(t *testing.T) { cont := controller.New( processor.NewFactory( processortest.AggregatorSelector(), - export.CumulativeExportKindSelector(), + export.CumulativeTemporalitySelector(), ), controller.WithCollectPeriod(time.Second), controller.WithPushTimeout(time.Millisecond), @@ -356,7 +356,7 @@ func TestExportTimeout(t *testing.T) { func TestCollectAfterStopThenStartAgain(t *testing.T) { exp := processortest.New( - export.CumulativeExportKindSelector(), + export.CumulativeTemporalitySelector(), attribute.DefaultEncoder(), ) cont := controller.New( @@ -435,7 +435,7 @@ func TestCollectAfterStopThenStartAgain(t *testing.T) { func TestRegistryFunction(t *testing.T) { exp := processortest.New( - export.CumulativeExportKindSelector(), + export.CumulativeTemporalitySelector(), attribute.DefaultEncoder(), ) cont := controller.New( diff --git a/sdk/metric/controller/basic/pull_test.go b/sdk/metric/controller/basic/pull_test.go index 04c25c23571..6a4b203d021 100644 --- a/sdk/metric/controller/basic/pull_test.go +++ b/sdk/metric/controller/basic/pull_test.go @@ -36,7 +36,7 @@ func TestPullNoCollect(t *testing.T) { puller := controller.New( processor.NewFactory( processortest.AggregatorSelector(), - export.CumulativeExportKindSelector(), + export.CumulativeTemporalitySelector(), processor.WithMemory(true), ), controller.WithCollectPeriod(0), @@ -51,7 +51,7 @@ func TestPullNoCollect(t *testing.T) { require.NoError(t, puller.Collect(ctx)) records := processortest.NewOutput(attribute.DefaultEncoder()) - require.NoError(t, controllertest.ReadAll(puller, export.CumulativeExportKindSelector(), records.AddInstrumentationLibraryRecord)) + require.NoError(t, controllertest.ReadAll(puller, export.CumulativeTemporalitySelector(), records.AddInstrumentationLibraryRecord)) require.EqualValues(t, map[string]float64{ "counter.sum/A=B/": 10, @@ -61,7 +61,7 @@ func TestPullNoCollect(t *testing.T) { require.NoError(t, puller.Collect(ctx)) records = processortest.NewOutput(attribute.DefaultEncoder()) - require.NoError(t, controllertest.ReadAll(puller, export.CumulativeExportKindSelector(), records.AddInstrumentationLibraryRecord)) + require.NoError(t, controllertest.ReadAll(puller, export.CumulativeTemporalitySelector(), records.AddInstrumentationLibraryRecord)) require.EqualValues(t, map[string]float64{ "counter.sum/A=B/": 20, @@ -72,7 +72,7 @@ func TestPullWithCollect(t *testing.T) { puller := controller.New( processor.NewFactory( processortest.AggregatorSelector(), - export.CumulativeExportKindSelector(), + export.CumulativeTemporalitySelector(), processor.WithMemory(true), ), controller.WithCollectPeriod(time.Second), @@ -89,7 +89,7 @@ func TestPullWithCollect(t *testing.T) { require.NoError(t, puller.Collect(ctx)) records := processortest.NewOutput(attribute.DefaultEncoder()) - require.NoError(t, controllertest.ReadAll(puller, export.CumulativeExportKindSelector(), records.AddInstrumentationLibraryRecord)) + require.NoError(t, controllertest.ReadAll(puller, export.CumulativeTemporalitySelector(), records.AddInstrumentationLibraryRecord)) require.EqualValues(t, map[string]float64{ "counter.sum/A=B/": 10, @@ -100,7 +100,7 @@ func TestPullWithCollect(t *testing.T) { // Cached value! require.NoError(t, puller.Collect(ctx)) records = processortest.NewOutput(attribute.DefaultEncoder()) - require.NoError(t, controllertest.ReadAll(puller, export.CumulativeExportKindSelector(), records.AddInstrumentationLibraryRecord)) + require.NoError(t, controllertest.ReadAll(puller, export.CumulativeTemporalitySelector(), records.AddInstrumentationLibraryRecord)) require.EqualValues(t, map[string]float64{ "counter.sum/A=B/": 10, @@ -112,7 +112,7 @@ func TestPullWithCollect(t *testing.T) { // Re-computed value! require.NoError(t, puller.Collect(ctx)) records = processortest.NewOutput(attribute.DefaultEncoder()) - require.NoError(t, controllertest.ReadAll(puller, export.CumulativeExportKindSelector(), records.AddInstrumentationLibraryRecord)) + require.NoError(t, controllertest.ReadAll(puller, export.CumulativeTemporalitySelector(), records.AddInstrumentationLibraryRecord)) require.EqualValues(t, map[string]float64{ "counter.sum/A=B/": 20, diff --git a/sdk/metric/controller/basic/push_test.go b/sdk/metric/controller/basic/push_test.go index 0b1b5474f3b..20a98cc5b4f 100644 --- a/sdk/metric/controller/basic/push_test.go +++ b/sdk/metric/controller/basic/push_test.go @@ -67,7 +67,7 @@ func init() { func newExporter() *processortest.Exporter { return processortest.New( - export.StatelessExportKindSelector(), + export.StatelessTemporalitySelector(), attribute.DefaultEncoder(), ) } diff --git a/sdk/metric/controller/controllertest/test.go b/sdk/metric/controller/controllertest/test.go index d4b8d3a3299..19a69f17bc9 100644 --- a/sdk/metric/controller/controllertest/test.go +++ b/sdk/metric/controller/controllertest/test.go @@ -64,7 +64,7 @@ func (t MockTicker) C() <-chan time.Time { // metric). func ReadAll( reader export.InstrumentationLibraryReader, - kind export.ExportKindSelector, + kind export.TemporalitySelector, apply func(instrumentation.Library, export.Record) error, ) error { return reader.ForEach(func(library instrumentation.Library, reader export.Reader) error { diff --git a/sdk/metric/processor/basic/basic.go b/sdk/metric/processor/basic/basic.go index a8340b8ecbc..a3948f3d25e 100644 --- a/sdk/metric/processor/basic/basic.go +++ b/sdk/metric/processor/basic/basic.go @@ -28,7 +28,7 @@ import ( type ( Processor struct { - export.ExportKindSelector + export.TemporalitySelector export.AggregatorSelector state @@ -118,25 +118,25 @@ var _ export.Reader = &state{} // ErrInconsistentState is returned when the sequence of collection's starts and finishes are incorrectly balanced. var ErrInconsistentState = fmt.Errorf("inconsistent processor state") -// ErrInvalidExportKind is returned for unknown metric.ExportKind. -var ErrInvalidExportKind = fmt.Errorf("invalid export kind") +// ErrInvalidTemporality is returned for unknown metric.Temporality. +var ErrInvalidTemporality = fmt.Errorf("invalid export kind") // New returns a basic Processor that is also a Checkpointer using the provided -// AggregatorSelector to select Aggregators. The ExportKindSelector +// AggregatorSelector to select Aggregators. The TemporalitySelector // is consulted to determine the kind(s) of exporter that will consume // data, so that this Processor can prepare to compute Delta or // Cumulative Aggregations as needed. -func New(aselector export.AggregatorSelector, eselector export.ExportKindSelector, opts ...Option) *Processor { +func New(aselector export.AggregatorSelector, eselector export.TemporalitySelector, opts ...Option) *Processor { return NewFactory(aselector, eselector, opts...).NewCheckpointer().(*Processor) } type factory struct { aselector export.AggregatorSelector - eselector export.ExportKindSelector + eselector export.TemporalitySelector config config } -func NewFactory(aselector export.AggregatorSelector, eselector export.ExportKindSelector, opts ...Option) export.CheckpointerFactory { +func NewFactory(aselector export.AggregatorSelector, eselector export.TemporalitySelector, opts ...Option) export.CheckpointerFactory { var config config for _, opt := range opts { opt.applyProcessor(&config) @@ -153,8 +153,8 @@ var _ export.CheckpointerFactory = factory{} func (f factory) NewCheckpointer() export.Checkpointer { now := time.Now() p := &Processor{ - AggregatorSelector: f.aselector, - ExportKindSelector: f.eselector, + AggregatorSelector: f.aselector, + TemporalitySelector: f.eselector, state: state{ values: map[stateKey]*stateValue{}, processStart: now, @@ -181,7 +181,7 @@ func (b *Processor) Process(accum export.Accumulation) error { // Check if there is an existing value. value, ok := b.state.values[key] if !ok { - stateful := b.ExportKindFor(desc, agg.Aggregation().Kind()).MemoryRequired(desc.InstrumentKind()) + stateful := b.TemporalityFor(desc, agg.Aggregation().Kind()).MemoryRequired(desc.InstrumentKind()) newValue := &stateValue{ labels: accum.Labels(), @@ -227,7 +227,7 @@ func (b *Processor) Process(accum export.Accumulation) error { // instrument reports a PrecomputedSum to a DeltaExporter or // the reverse, a non-PrecomputedSum instrument with a // CumulativeExporter. This logic is encapsulated in - // ExportKind.MemoryRequired(InstrumentKind). + // Temporality.MemoryRequired(InstrumentKind). // // Case (b) occurs when the variable `sameCollection` is true, // indicating that the stateKey for Accumulation has already @@ -340,7 +340,7 @@ func (b *Processor) FinishCollection() error { // ForEach iterates through the Reader, passing an // export.Record with the appropriate Cumulative or Delta aggregation // to an exporter. -func (b *state) ForEach(exporter export.ExportKindSelector, f func(export.Record) error) error { +func (b *state) ForEach(exporter export.TemporalitySelector, f func(export.Record) error) error { if b.startedCollection != b.finishedCollection { return ErrInconsistentState } @@ -356,9 +356,9 @@ func (b *state) ForEach(exporter export.ExportKindSelector, f func(export.Record continue } - ekind := exporter.ExportKindFor(key.descriptor, value.current.Aggregation().Kind()) + ekind := exporter.TemporalityFor(key.descriptor, value.current.Aggregation().Kind()) switch ekind { - case export.CumulativeExportKind: + case export.CumulativeTemporality: // If stateful, the sum has been computed. If stateless, the // input was already cumulative. Either way, use the checkpointed // value: @@ -369,7 +369,7 @@ func (b *state) ForEach(exporter export.ExportKindSelector, f func(export.Record } start = b.processStart - case export.DeltaExportKind: + case export.DeltaTemporality: // Precomputed sums are a special case. if mkind.PrecomputedSum() { agg = value.delta.Aggregation() @@ -379,7 +379,7 @@ func (b *state) ForEach(exporter export.ExportKindSelector, f func(export.Record start = b.intervalStart default: - return fmt.Errorf("%v: %w", ekind, ErrInvalidExportKind) + return fmt.Errorf("%v: %w", ekind, ErrInvalidTemporality) } if err := f(export.NewRecord( diff --git a/sdk/metric/processor/basic/basic_test.go b/sdk/metric/processor/basic/basic_test.go index dec7dbbeba5..8401fd4c500 100644 --- a/sdk/metric/processor/basic/basic_test.go +++ b/sdk/metric/processor/basic/basic_test.go @@ -47,7 +47,7 @@ func requireNotAfter(t *testing.T, t1, t2 time.Time) { // TestProcessor tests all the non-error paths in this package. func TestProcessor(t *testing.T) { type exportCase struct { - kind export.ExportKind + kind export.Temporality } type instrumentCase struct { kind sdkapi.InstrumentKind @@ -60,8 +60,8 @@ func TestProcessor(t *testing.T) { } for _, tc := range []exportCase{ - {kind: export.CumulativeExportKind}, - {kind: export.DeltaExportKind}, + {kind: export.CumulativeTemporality}, + {kind: export.DeltaTemporality}, } { t.Run(tc.kind.String(), func(t *testing.T) { for _, ic := range []instrumentCase{ @@ -121,7 +121,7 @@ func updateFor(t *testing.T, desc *metric.Descriptor, selector export.Aggregator func testProcessor( t *testing.T, - ekind export.ExportKind, + ekind export.Temporality, mkind sdkapi.InstrumentKind, nkind number.Kind, akind aggregation.Kind, @@ -134,7 +134,7 @@ func testProcessor( labs2 := []attribute.KeyValue{attribute.String("L2", "V")} testBody := func(t *testing.T, hasMemory bool, nAccum, nCheckpoint int) { - processor := basic.New(selector, export.ConstantExportKindSelector(ekind), basic.WithMemory(hasMemory)) + processor := basic.New(selector, export.ConstantTemporalitySelector(ekind), basic.WithMemory(hasMemory)) instSuffix := fmt.Sprint(".", strings.ToLower(akind.String())) @@ -166,7 +166,7 @@ func testProcessor( _, canSub := subr.(export.Subtractor) // Allow unsupported subraction case only when it is called for. - require.True(t, mkind.PrecomputedSum() && ekind == export.DeltaExportKind && !canSub) + require.True(t, mkind.PrecomputedSum() && ekind == export.DeltaTemporality && !canSub) return } else if err != nil { t.Fatal("unexpected FinishCollection error: ", err) @@ -190,7 +190,7 @@ func testProcessor( // Test the final checkpoint state. records1 := processorTest.NewOutput(attribute.DefaultEncoder()) - err = reader.ForEach(export.ConstantExportKindSelector(ekind), records1.AddRecord) + err = reader.ForEach(export.ConstantTemporalitySelector(ekind), records1.AddRecord) // Test for an allowed error: if err != nil && err != aggregation.ErrNoSubtraction { @@ -203,7 +203,7 @@ func testProcessor( // number of Accumulators, unless LastValue aggregation. // If a precomputed sum, we expect cumulative inputs. if mkind.PrecomputedSum() { - if ekind == export.DeltaExportKind && akind != aggregation.LastValueKind { + if ekind == export.DeltaTemporality && akind != aggregation.LastValueKind { multiplier = int64(nAccum) } else if akind == aggregation.LastValueKind { multiplier = cumulativeMultiplier @@ -211,7 +211,7 @@ func testProcessor( multiplier = cumulativeMultiplier * int64(nAccum) } } else { - if ekind == export.CumulativeExportKind && akind != aggregation.LastValueKind { + if ekind == export.CumulativeTemporality && akind != aggregation.LastValueKind { multiplier = cumulativeMultiplier * int64(nAccum) } else if akind == aggregation.LastValueKind { multiplier = 1 @@ -223,7 +223,7 @@ func testProcessor( // Synchronous accumulate results from multiple accumulators, // use that number as the baseline multiplier. multiplier = int64(nAccum) - if ekind == export.CumulativeExportKind { + if ekind == export.CumulativeTemporality { // If a cumulative exporter, include prior checkpoints. multiplier *= cumulativeMultiplier } @@ -265,7 +265,7 @@ func testProcessor( type bogusExporter struct{} -func (bogusExporter) ExportKindFor(*metric.Descriptor, aggregation.Kind) export.ExportKind { +func (bogusExporter) TemporalityFor(*metric.Descriptor, aggregation.Kind) export.Temporality { return 1000000 } @@ -275,39 +275,39 @@ func (bogusExporter) Export(context.Context, export.Reader) error { func TestBasicInconsistent(t *testing.T) { // Test double-start - b := basic.New(processorTest.AggregatorSelector(), export.StatelessExportKindSelector()) + b := basic.New(processorTest.AggregatorSelector(), export.StatelessTemporalitySelector()) b.StartCollection() b.StartCollection() require.Equal(t, basic.ErrInconsistentState, b.FinishCollection()) // Test finish without start - b = basic.New(processorTest.AggregatorSelector(), export.StatelessExportKindSelector()) + b = basic.New(processorTest.AggregatorSelector(), export.StatelessTemporalitySelector()) require.Equal(t, basic.ErrInconsistentState, b.FinishCollection()) // Test no finish - b = basic.New(processorTest.AggregatorSelector(), export.StatelessExportKindSelector()) + b = basic.New(processorTest.AggregatorSelector(), export.StatelessTemporalitySelector()) b.StartCollection() require.Equal( t, basic.ErrInconsistentState, b.ForEach( - export.StatelessExportKindSelector(), + export.StatelessTemporalitySelector(), func(export.Record) error { return nil }, ), ) // Test no start - b = basic.New(processorTest.AggregatorSelector(), export.StatelessExportKindSelector()) + b = basic.New(processorTest.AggregatorSelector(), export.StatelessTemporalitySelector()) desc := metrictest.NewDescriptor("inst", sdkapi.CounterInstrumentKind, number.Int64Kind) accum := export.NewAccumulation(&desc, attribute.EmptySet(), aggregatortest.NoopAggregator{}) require.Equal(t, basic.ErrInconsistentState, b.Process(accum)) // Test invalid kind: - b = basic.New(processorTest.AggregatorSelector(), export.StatelessExportKindSelector()) + b = basic.New(processorTest.AggregatorSelector(), export.StatelessTemporalitySelector()) b.StartCollection() require.NoError(t, b.Process(accum)) require.NoError(t, b.FinishCollection()) @@ -316,14 +316,14 @@ func TestBasicInconsistent(t *testing.T) { bogusExporter{}, func(export.Record) error { return nil }, ) - require.True(t, errors.Is(err, basic.ErrInvalidExportKind)) + require.True(t, errors.Is(err, basic.ErrInvalidTemporality)) } func TestBasicTimestamps(t *testing.T) { beforeNew := time.Now() time.Sleep(time.Nanosecond) - b := basic.New(processorTest.AggregatorSelector(), export.StatelessExportKindSelector()) + b := basic.New(processorTest.AggregatorSelector(), export.StatelessTemporalitySelector()) time.Sleep(time.Nanosecond) afterNew := time.Now() @@ -336,7 +336,7 @@ func TestBasicTimestamps(t *testing.T) { var start1, end1 time.Time - require.NoError(t, b.ForEach(export.StatelessExportKindSelector(), func(rec export.Record) error { + require.NoError(t, b.ForEach(export.StatelessTemporalitySelector(), func(rec export.Record) error { start1 = rec.StartTime() end1 = rec.EndTime() return nil @@ -353,7 +353,7 @@ func TestBasicTimestamps(t *testing.T) { var start2, end2 time.Time - require.NoError(t, b.ForEach(export.StatelessExportKindSelector(), func(rec export.Record) error { + require.NoError(t, b.ForEach(export.StatelessTemporalitySelector(), func(rec export.Record) error { start2 = rec.StartTime() end2 = rec.EndTime() return nil @@ -370,7 +370,7 @@ func TestBasicTimestamps(t *testing.T) { } func TestStatefulNoMemoryCumulative(t *testing.T) { - ekindSel := export.CumulativeExportKindSelector() + ekindSel := export.CumulativeTemporalitySelector() desc := metrictest.NewDescriptor("inst.sum", sdkapi.CounterInstrumentKind, number.Int64Kind) selector := processorTest.AggregatorSelector() @@ -403,7 +403,7 @@ func TestStatefulNoMemoryCumulative(t *testing.T) { } func TestStatefulNoMemoryDelta(t *testing.T) { - ekindSel := export.DeltaExportKindSelector() + ekindSel := export.DeltaTemporalitySelector() desc := metrictest.NewDescriptor("inst.sum", sdkapi.CounterObserverInstrumentKind, number.Int64Kind) selector := processorTest.AggregatorSelector() @@ -436,9 +436,9 @@ func TestStatefulNoMemoryDelta(t *testing.T) { } func TestMultiObserverSum(t *testing.T) { - for _, ekindSel := range []export.ExportKindSelector{ - export.CumulativeExportKindSelector(), - export.DeltaExportKindSelector(), + for _, ekindSel := range []export.TemporalitySelector{ + export.CumulativeTemporalitySelector(), + export.DeltaTemporalitySelector(), } { desc := metrictest.NewDescriptor("observe.sum", sdkapi.CounterObserverInstrumentKind, number.Int64Kind) @@ -457,7 +457,7 @@ func TestMultiObserverSum(t *testing.T) { // Multiplier is 1 for deltas, otherwise i. multiplier := i - if ekindSel.ExportKindFor(&desc, aggregation.SumKind) == export.DeltaExportKind { + if ekindSel.TemporalityFor(&desc, aggregation.SumKind) == export.DeltaTemporality { multiplier = 1 } @@ -473,7 +473,7 @@ func TestMultiObserverSum(t *testing.T) { func TestCounterObserverEndToEnd(t *testing.T) { ctx := context.Background() - eselector := export.CumulativeExportKindSelector() + eselector := export.CumulativeTemporalitySelector() proc := basic.New( processorTest.AggregatorSelector(), eselector, diff --git a/sdk/metric/processor/processortest/test.go b/sdk/metric/processor/processortest/test.go index 05fc7fb9b6b..50221d47ac7 100644 --- a/sdk/metric/processor/processortest/test.go +++ b/sdk/metric/processor/processortest/test.go @@ -82,7 +82,7 @@ type ( // Exporter is a testing implementation of export.Exporter that // assembles its results as a map[string]float64. Exporter struct { - export.ExportKindSelector + export.TemporalitySelector output *Output exportCount int @@ -230,7 +230,7 @@ func NewOutput(labelEncoder attribute.Encoder) *Output { } // ForEach implements export.Reader. -func (o *Output) ForEach(_ export.ExportKindSelector, ff func(export.Record) error) error { +func (o *Output) ForEach(_ export.TemporalitySelector, ff func(export.Record) error) error { for key, value := range o.m { if err := ff(export.NewRecord( key.desc, @@ -281,7 +281,7 @@ func (o *Output) AddRecordWithResource(rec export.Record, res *resource.Resource // is chosen, whichever is implemented by the underlying Aggregator. func (o *Output) Map() map[string]float64 { r := make(map[string]float64) - err := o.ForEach(export.StatelessExportKindSelector(), func(record export.Record) error { + err := o.ForEach(export.StatelessTemporalitySelector(), func(record export.Record) error { for key, entry := range o.m { encoded := entry.labels.Encoded(o.labelEncoder) rencoded := entry.resource.Encoded(o.labelEncoder) @@ -344,10 +344,10 @@ func (o *Output) AddAccumulation(acc export.Accumulation) error { // // Where in the example A=1,B=2 is the encoded labels and R=V is the // encoded resource value. -func New(selector export.ExportKindSelector, encoder attribute.Encoder) *Exporter { +func New(selector export.TemporalitySelector, encoder attribute.Encoder) *Exporter { return &Exporter{ - ExportKindSelector: selector, - output: NewOutput(encoder), + TemporalitySelector: selector, + output: NewOutput(encoder), } } @@ -356,7 +356,7 @@ func (e *Exporter) Export(_ context.Context, res *resource.Resource, ckpt export defer e.output.Unlock() e.exportCount++ return ckpt.ForEach(func(library instrumentation.Library, mr export.Reader) error { - return mr.ForEach(e.ExportKindSelector, func(r export.Record) error { + return mr.ForEach(e.TemporalitySelector, func(r export.Record) error { if e.InjectErr != nil { if err := e.InjectErr(r); err != nil { return err @@ -433,7 +433,7 @@ type metricReader struct { var _ export.Reader = &metricReader{} -func (m *metricReader) ForEach(_ export.ExportKindSelector, fn func(export.Record) error) error { +func (m *metricReader) ForEach(_ export.TemporalitySelector, fn func(export.Record) error) error { for _, record := range m.records { if err := fn(record); err != nil && err != aggregation.ErrNoData { return err diff --git a/sdk/metric/processor/processortest/test_test.go b/sdk/metric/processor/processortest/test_test.go index 8ee88b55278..132c5d386c7 100644 --- a/sdk/metric/processor/processortest/test_test.go +++ b/sdk/metric/processor/processortest/test_test.go @@ -71,7 +71,7 @@ func TestProcessorTesting(t *testing.T) { // Export the data and validate it again. exporter := processorTest.New( - export.StatelessExportKindSelector(), + export.StatelessTemporalitySelector(), attribute.DefaultEncoder(), ) diff --git a/sdk/metric/processor/reducer/reducer_test.go b/sdk/metric/processor/reducer/reducer_test.go index 3eb9ce3a268..3bf3e1cd12b 100644 --- a/sdk/metric/processor/reducer/reducer_test.go +++ b/sdk/metric/processor/reducer/reducer_test.go @@ -90,7 +90,7 @@ func TestFilterProcessor(t *testing.T) { // Test a filter with the ../basic Processor. func TestFilterBasicProcessor(t *testing.T) { - basicProc := basic.New(processorTest.AggregatorSelector(), export.CumulativeExportKindSelector()) + basicProc := basic.New(processorTest.AggregatorSelector(), export.CumulativeTemporalitySelector()) accum := metricsdk.NewAccumulator( reducer.New(testFilter{}, basicProc), )