diff --git a/attribute/type_string.go b/attribute/type_string.go index 642e269516b..e584b24776b 100644 --- a/attribute/type_string.go +++ b/attribute/type_string.go @@ -1,6 +1,6 @@ // Code generated by "stringer -type=Type"; DO NOT EDIT. -package attribute // import "go.opentelemetry.io/otel/attribute" +package attribute import "strconv" diff --git a/bridge/opencensus/exporter.go b/bridge/opencensus/exporter.go index 50f1242f266..1bc4d5fc115 100644 --- a/bridge/opencensus/exporter.go +++ b/bridge/opencensus/exporter.go @@ -147,7 +147,7 @@ func convertResource(res *ocresource.Resource) *resource.Resource { } // convertDescriptor converts an OpenCensus Descriptor to an OpenTelemetry Descriptor -func convertDescriptor(ocDescriptor metricdata.Descriptor) (metric.Descriptor, error) { +func convertDescriptor(ocDescriptor metricdata.Descriptor) (sdkapi.Descriptor, error) { var ( nkind number.Kind ikind sdkapi.InstrumentKind @@ -167,7 +167,7 @@ func convertDescriptor(ocDescriptor metricdata.Descriptor) (metric.Descriptor, e ikind = sdkapi.CounterObserverInstrumentKind default: // Includes TypeGaugeDistribution, TypeCumulativeDistribution, TypeSummary - return metric.Descriptor{}, fmt.Errorf("%w; descriptor type: %v", errConversion, ocDescriptor.Type) + return sdkapi.Descriptor{}, fmt.Errorf("%w; descriptor type: %v", errConversion, ocDescriptor.Type) } opts := []metric.InstrumentOption{ metric.WithDescription(ocDescriptor.Description), @@ -181,5 +181,5 @@ func convertDescriptor(ocDescriptor metricdata.Descriptor) (metric.Descriptor, e opts = append(opts, metric.WithUnit(unit.Milliseconds)) } cfg := metric.NewInstrumentConfig(opts...) - return metric.NewDescriptor(ocDescriptor.Name, ikind, nkind, cfg.Description(), cfg.Unit()), nil + return sdkapi.NewDescriptor(ocDescriptor.Name, ikind, nkind, cfg.Description(), cfg.Unit()), nil } diff --git a/bridge/opencensus/exporter_test.go b/bridge/opencensus/exporter_test.go index ee5d7607930..3c0d89db8a5 100644 --- a/bridge/opencensus/exporter_test.go +++ b/bridge/opencensus/exporter_test.go @@ -391,7 +391,7 @@ func TestConvertDescriptor(t *testing.T) { for _, tc := range []struct { desc string input metricdata.Descriptor - expected metric.Descriptor + expected sdkapi.Descriptor expectedErr error }{ { diff --git a/exporters/otlp/otlpmetric/exporter.go b/exporters/otlp/otlpmetric/exporter.go index 25930273aaf..cc3e0658842 100644 --- a/exporters/otlp/otlpmetric/exporter.go +++ b/exporters/otlp/otlpmetric/exporter.go @@ -20,7 +20,7 @@ import ( "sync" "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal/metrictransform" - "go.opentelemetry.io/otel/metric" + "go.opentelemetry.io/otel/metric/sdkapi" metricsdk "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/resource" @@ -96,7 +96,7 @@ func (e *Exporter) Shutdown(ctx context.Context) error { return err } -func (e *Exporter) ExportKindFor(descriptor *metric.Descriptor, aggregatorKind aggregation.Kind) metricsdk.ExportKind { +func (e *Exporter) ExportKindFor(descriptor *sdkapi.Descriptor, aggregatorKind aggregation.Kind) metricsdk.ExportKind { return e.exportKindSelector.ExportKindFor(descriptor, aggregatorKind) } diff --git a/exporters/otlp/otlpmetric/internal/metrictransform/metric_test.go b/exporters/otlp/otlpmetric/internal/metrictransform/metric_test.go index 9b339edfe53..d697ae398fb 100644 --- a/exporters/otlp/otlpmetric/internal/metrictransform/metric_test.go +++ b/exporters/otlp/otlpmetric/internal/metrictransform/metric_test.go @@ -25,7 +25,6 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/metrictest" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/sdkapi" @@ -101,18 +100,18 @@ func TestStringKeyValues(t *testing.T) { } func TestMinMaxSumCountValue(t *testing.T) { - mmscs := minmaxsumcount.New(2, &metric.Descriptor{}) + mmscs := minmaxsumcount.New(2, &sdkapi.Descriptor{}) mmsc, ckpt := &mmscs[0], &mmscs[1] - assert.NoError(t, mmsc.Update(context.Background(), 1, &metric.Descriptor{})) - assert.NoError(t, mmsc.Update(context.Background(), 10, &metric.Descriptor{})) + assert.NoError(t, mmsc.Update(context.Background(), 1, &sdkapi.Descriptor{})) + assert.NoError(t, mmsc.Update(context.Background(), 10, &sdkapi.Descriptor{})) // Prior to checkpointing ErrNoData should be returned. _, _, _, _, err := minMaxSumCountValues(ckpt) assert.EqualError(t, err, aggregation.ErrNoData.Error()) // Checkpoint to set non-zero values - require.NoError(t, mmsc.SynchronizedMove(ckpt, &metric.Descriptor{})) + require.NoError(t, mmsc.SynchronizedMove(ckpt, &sdkapi.Descriptor{})) min, max, sum, count, err := minMaxSumCountValues(ckpt) if assert.NoError(t, err) { assert.Equal(t, min, number.NewInt64Number(1)) @@ -125,7 +124,7 @@ func TestMinMaxSumCountValue(t *testing.T) { func TestMinMaxSumCountDatapoints(t *testing.T) { desc := metrictest.NewDescriptor("", sdkapi.HistogramInstrumentKind, number.Int64Kind) labels := attribute.NewSet(attribute.String("one", "1")) - mmscs := minmaxsumcount.New(2, &metric.Descriptor{}) + mmscs := minmaxsumcount.New(2, &sdkapi.Descriptor{}) mmsc, ckpt := &mmscs[0], &mmscs[1] assert.NoError(t, mmsc.Update(context.Background(), 1, &desc)) @@ -172,7 +171,7 @@ func TestMinMaxSumCountPropagatesErrors(t *testing.T) { // ErrNoData should be returned by both the Min and Max values of // a MinMaxSumCount Aggregator. Use this fact to check the error is // correctly returned. - mmsc := &minmaxsumcount.New(1, &metric.Descriptor{})[0] + mmsc := &minmaxsumcount.New(1, &sdkapi.Descriptor{})[0] _, _, _, _, err := minMaxSumCountValues(mmsc) assert.Error(t, err) assert.Equal(t, aggregation.ErrNoData, err) @@ -390,13 +389,13 @@ func (t *testAgg) Aggregation() aggregation.Aggregation { // None of these three are used: -func (t *testAgg) Update(ctx context.Context, number number.Number, descriptor *metric.Descriptor) error { +func (t *testAgg) Update(ctx context.Context, number number.Number, descriptor *sdkapi.Descriptor) error { return nil } -func (t *testAgg) SynchronizedMove(destination export.Aggregator, descriptor *metric.Descriptor) error { +func (t *testAgg) SynchronizedMove(destination export.Aggregator, descriptor *sdkapi.Descriptor) error { return nil } -func (t *testAgg) Merge(aggregator export.Aggregator, descriptor *metric.Descriptor) error { +func (t *testAgg) Merge(aggregator export.Aggregator, descriptor *sdkapi.Descriptor) error { return nil } diff --git a/exporters/prometheus/prometheus.go b/exporters/prometheus/prometheus.go index 572feff5701..f191aa43d2b 100644 --- a/exporters/prometheus/prometheus.go +++ b/exporters/prometheus/prometheus.go @@ -30,6 +30,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" + "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/instrumentation" @@ -132,7 +133,7 @@ func (e *Exporter) Controller() *controller.Controller { } // ExportKindFor implements ExportKindSelector. -func (e *Exporter) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) export.ExportKind { +func (e *Exporter) ExportKindFor(desc *sdkapi.Descriptor, kind aggregation.Kind) export.ExportKind { return export.CumulativeExportKindSelector().ExportKindFor(desc, kind) } diff --git a/exporters/stdout/stdoutmetric/metric.go b/exporters/stdout/stdoutmetric/metric.go index 7ad8495b0e0..9fd6b28d154 100644 --- a/exporters/stdout/stdoutmetric/metric.go +++ b/exporters/stdout/stdoutmetric/metric.go @@ -22,7 +22,7 @@ import ( "time" "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric" + "go.opentelemetry.io/otel/metric/sdkapi" exportmetric "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/instrumentation" @@ -47,7 +47,7 @@ type line struct { Timestamp *time.Time `json:"Timestamp,omitempty"` } -func (e *metricExporter) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) exportmetric.ExportKind { +func (e *metricExporter) ExportKindFor(desc *sdkapi.Descriptor, kind aggregation.Kind) exportmetric.ExportKind { return exportmetric.StatelessExportKindSelector().ExportKindFor(desc, kind) } diff --git a/internal/metric/global/meter.go b/internal/metric/global/meter.go index f8f0992b7ef..7409f5f97aa 100644 --- a/internal/metric/global/meter.go +++ b/internal/metric/global/meter.go @@ -24,6 +24,7 @@ import ( "go.opentelemetry.io/otel/internal/metric/registry" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" + "go.opentelemetry.io/otel/metric/sdkapi" ) // This file contains the forwarding implementation of MeterProvider used as @@ -78,7 +79,7 @@ type meterEntry struct { } type instrument struct { - descriptor metric.Descriptor + descriptor sdkapi.Descriptor } type syncImpl struct { @@ -122,7 +123,7 @@ var _ metric.InstrumentImpl = &syncImpl{} var _ metric.BoundSyncImpl = &syncHandle{} var _ metric.AsyncImpl = &asyncImpl{} -func (inst *instrument) Descriptor() metric.Descriptor { +func (inst *instrument) Descriptor() sdkapi.Descriptor { return inst.descriptor } @@ -197,7 +198,7 @@ func (m *meterImpl) setDelegate(key meterKey, provider metric.MeterProvider) { m.asyncInsts = nil } -func (m *meterImpl) NewSyncInstrument(desc metric.Descriptor) (metric.SyncImpl, error) { +func (m *meterImpl) NewSyncInstrument(desc sdkapi.Descriptor) (metric.SyncImpl, error) { m.lock.Lock() defer m.lock.Unlock() @@ -265,7 +266,7 @@ func (bound *syncHandle) Unbind() { // Async delegation func (m *meterImpl) NewAsyncInstrument( - desc metric.Descriptor, + desc sdkapi.Descriptor, runner metric.AsyncRunner, ) (metric.AsyncImpl, error) { diff --git a/internal/metric/global/meter_test.go b/internal/metric/global/meter_test.go index 7f4cd0eb696..204dd3c51f2 100644 --- a/internal/metric/global/meter_test.go +++ b/internal/metric/global/meter_test.go @@ -27,6 +27,7 @@ import ( metricglobal "go.opentelemetry.io/otel/metric/global" "go.opentelemetry.io/otel/metric/metrictest" "go.opentelemetry.io/otel/metric/number" + "go.opentelemetry.io/otel/metric/sdkapi" ) var Must = metric.Must @@ -239,7 +240,7 @@ func (m *meterProviderWithConstructorError) Meter(iName string, opts ...metric.M return metric.WrapMeterImpl(&meterWithConstructorError{m.MeterProvider.Meter(iName, opts...).MeterImpl()}) } -func (m *meterWithConstructorError) NewSyncInstrument(_ metric.Descriptor) (metric.SyncImpl, error) { +func (m *meterWithConstructorError) NewSyncInstrument(_ sdkapi.Descriptor) (metric.SyncImpl, error) { return metric.NoopSync{}, errors.New("constructor error") } diff --git a/internal/metric/registry/registry.go b/internal/metric/registry/registry.go index 5eafa540d31..b6eac14ac62 100644 --- a/internal/metric/registry/registry.go +++ b/internal/metric/registry/registry.go @@ -21,6 +21,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" + "go.opentelemetry.io/otel/metric/sdkapi" ) // UniqueInstrumentMeterImpl implements the metric.MeterImpl interface, adding @@ -60,7 +61,7 @@ func (u *UniqueInstrumentMeterImpl) RecordBatch(ctx context.Context, labels []at // NewMetricKindMismatchError formats an error that describes a // mismatched metric instrument definition. -func NewMetricKindMismatchError(desc metric.Descriptor) error { +func NewMetricKindMismatchError(desc sdkapi.Descriptor) error { return fmt.Errorf("metric %s registered as %s %s: %w", desc.Name(), desc.NumberKind(), @@ -68,9 +69,9 @@ func NewMetricKindMismatchError(desc metric.Descriptor) error { ErrMetricKindMismatch) } -// Compatible determines whether two metric.Descriptors are considered +// Compatible determines whether two sdkapi.Descriptors are considered // the same for the purpose of uniqueness checking. -func Compatible(candidate, existing metric.Descriptor) bool { +func Compatible(candidate, existing sdkapi.Descriptor) bool { return candidate.InstrumentKind() == existing.InstrumentKind() && candidate.NumberKind() == existing.NumberKind() } @@ -80,7 +81,7 @@ func Compatible(candidate, existing metric.Descriptor) bool { // `descriptor` argument. If there is an existing compatible // registration, this returns the already-registered instrument. If // there is no conflict and no prior registration, returns (nil, nil). -func (u *UniqueInstrumentMeterImpl) checkUniqueness(descriptor metric.Descriptor) (metric.InstrumentImpl, error) { +func (u *UniqueInstrumentMeterImpl) checkUniqueness(descriptor sdkapi.Descriptor) (metric.InstrumentImpl, error) { impl, ok := u.state[descriptor.Name()] if !ok { return nil, nil @@ -94,7 +95,7 @@ func (u *UniqueInstrumentMeterImpl) checkUniqueness(descriptor metric.Descriptor } // NewSyncInstrument implements metric.MeterImpl. -func (u *UniqueInstrumentMeterImpl) NewSyncInstrument(descriptor metric.Descriptor) (metric.SyncImpl, error) { +func (u *UniqueInstrumentMeterImpl) NewSyncInstrument(descriptor sdkapi.Descriptor) (metric.SyncImpl, error) { u.lock.Lock() defer u.lock.Unlock() @@ -116,7 +117,7 @@ func (u *UniqueInstrumentMeterImpl) NewSyncInstrument(descriptor metric.Descript // NewAsyncInstrument implements metric.MeterImpl. func (u *UniqueInstrumentMeterImpl) NewAsyncInstrument( - descriptor metric.Descriptor, + descriptor sdkapi.Descriptor, runner metric.AsyncRunner, ) (metric.AsyncImpl, error) { u.lock.Lock() diff --git a/metric/metric.go b/metric/metric.go index 6314e9ca6d1..a045c8d45b9 100644 --- a/metric/metric.go +++ b/metric/metric.go @@ -20,7 +20,6 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/sdkapi" - "go.opentelemetry.io/otel/metric/unit" ) // MeterProvider supports named Meter instances. @@ -285,7 +284,7 @@ func (m Meter) newAsync( return NoopAsync{}, nil } cfg := NewInstrumentConfig(opts...) - desc := NewDescriptor(name, mkind, nkind, cfg.description, cfg.unit) + desc := sdkapi.NewDescriptor(name, mkind, nkind, cfg.description, cfg.unit) return m.impl.NewAsyncInstrument(desc, runner) } @@ -303,7 +302,7 @@ func (m Meter) newSync( return NoopSync{}, nil } cfg := NewInstrumentConfig(opts...) - desc := NewDescriptor(name, metricKind, numberKind, cfg.description, cfg.unit) + desc := sdkapi.NewDescriptor(name, metricKind, numberKind, cfg.description, cfg.unit) return m.impl.NewSyncInstrument(desc) } @@ -513,53 +512,3 @@ func (bm BatchObserverMust) NewFloat64UpDownCounterObserver(name string, oos ... return inst } } - -// Descriptor contains all the settings that describe an instrument, -// including its name, metric kind, number kind, and the configurable -// options. -type Descriptor struct { - name string - instrumentKind sdkapi.InstrumentKind - numberKind number.Kind - description string - unit unit.Unit -} - -// NewDescriptor returns a Descriptor with the given contents. -func NewDescriptor(name string, ikind sdkapi.InstrumentKind, nkind number.Kind, description string, unit unit.Unit) Descriptor { - return Descriptor{ - name: name, - instrumentKind: ikind, - numberKind: nkind, - description: description, - unit: unit, - } -} - -// Name returns the metric instrument's name. -func (d Descriptor) Name() string { - return d.name -} - -// InstrumentKind returns the specific kind of instrument. -func (d Descriptor) InstrumentKind() sdkapi.InstrumentKind { - return d.instrumentKind -} - -// Description provides a human-readable description of the metric -// instrument. -func (d Descriptor) Description() string { - return d.description -} - -// Unit describes the units of the metric instrument. Unitless -// metrics return the empty string. -func (d Descriptor) Unit() unit.Unit { - return d.unit -} - -// NumberKind returns whether this instrument is declared over int64, -// float64, or uint64 values. -func (d Descriptor) NumberKind() number.Kind { - return d.numberKind -} diff --git a/metric/metric_sdkapi.go b/metric/metric_sdkapi.go index c7748d1bdc7..d39a08dbcb8 100644 --- a/metric/metric_sdkapi.go +++ b/metric/metric_sdkapi.go @@ -19,6 +19,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric/number" + "go.opentelemetry.io/otel/metric/sdkapi" ) // MeterImpl is the interface an SDK must implement to supply a Meter @@ -30,13 +31,13 @@ type MeterImpl interface { // NewSyncInstrument returns a newly constructed // synchronous instrument implementation or an error, should // one occur. - NewSyncInstrument(descriptor Descriptor) (SyncImpl, error) + NewSyncInstrument(descriptor sdkapi.Descriptor) (SyncImpl, error) // NewAsyncInstrument returns a newly constructed // asynchronous instrument implementation or an error, should // one occur. NewAsyncInstrument( - descriptor Descriptor, + descriptor sdkapi.Descriptor, runner AsyncRunner, ) (AsyncImpl, error) } @@ -50,7 +51,7 @@ type InstrumentImpl interface { Implementation() interface{} // Descriptor returns a copy of the instrument's Descriptor. - Descriptor() Descriptor + Descriptor() sdkapi.Descriptor } // SyncImpl is the implementation-level interface to a generic diff --git a/metric/metric_test.go b/metric/metric_test.go index 29e433ad898..3bf9336679d 100644 --- a/metric/metric_test.go +++ b/metric/metric_test.go @@ -473,11 +473,11 @@ var _ metric.MeterImpl = testWrappedMeter{} func (testWrappedMeter) RecordBatch(context.Context, []attribute.KeyValue, ...metric.Measurement) { } -func (testWrappedMeter) NewSyncInstrument(_ metric.Descriptor) (metric.SyncImpl, error) { +func (testWrappedMeter) NewSyncInstrument(_ sdkapi.Descriptor) (metric.SyncImpl, error) { return nil, nil } -func (testWrappedMeter) NewAsyncInstrument(_ metric.Descriptor, _ metric.AsyncRunner) (metric.AsyncImpl, error) { +func (testWrappedMeter) NewAsyncInstrument(_ sdkapi.Descriptor, _ metric.AsyncRunner) (metric.AsyncImpl, error) { return nil, errors.New("Test wrap error") } diff --git a/metric/metrictest/meter.go b/metric/metrictest/meter.go index 957f894f142..5bde993fcf3 100644 --- a/metric/metrictest/meter.go +++ b/metric/metrictest/meter.go @@ -71,7 +71,7 @@ type ( Instrument struct { meter *MeterImpl - descriptor metric.Descriptor + descriptor sdkapi.Descriptor } Async struct { @@ -94,12 +94,12 @@ var ( // NewDescriptor is a test helper for constructing test metric // descriptors using standard options. -func NewDescriptor(name string, ikind sdkapi.InstrumentKind, nkind number.Kind, opts ...metric.InstrumentOption) metric.Descriptor { +func NewDescriptor(name string, ikind sdkapi.InstrumentKind, nkind number.Kind, opts ...metric.InstrumentOption) sdkapi.Descriptor { cfg := metric.NewInstrumentConfig(opts...) - return metric.NewDescriptor(name, ikind, nkind, cfg.Description(), cfg.Unit()) + return sdkapi.NewDescriptor(name, ikind, nkind, cfg.Description(), cfg.Unit()) } -func (i Instrument) Descriptor() metric.Descriptor { +func (i Instrument) Descriptor() sdkapi.Descriptor { return i.descriptor } @@ -161,7 +161,7 @@ func (p *MeterProvider) Meter(name string, opts ...metric.MeterOption) metric.Me } // NewSyncInstrument implements metric.MeterImpl. -func (m *MeterImpl) NewSyncInstrument(descriptor metric.Descriptor) (metric.SyncImpl, error) { +func (m *MeterImpl) NewSyncInstrument(descriptor sdkapi.Descriptor) (metric.SyncImpl, error) { return &Sync{ Instrument{ descriptor: descriptor, @@ -171,7 +171,7 @@ func (m *MeterImpl) NewSyncInstrument(descriptor metric.Descriptor) (metric.Sync } // NewAsyncInstrument implements metric.MeterImpl. -func (m *MeterImpl) NewAsyncInstrument(descriptor metric.Descriptor, runner metric.AsyncRunner) (metric.AsyncImpl, error) { +func (m *MeterImpl) NewAsyncInstrument(descriptor sdkapi.Descriptor, runner metric.AsyncRunner) (metric.AsyncImpl, error) { a := &Async{ Instrument: Instrument{ descriptor: descriptor, diff --git a/metric/noop.go b/metric/noop.go index 5b51af759f3..cbcc96ff5c1 100644 --- a/metric/noop.go +++ b/metric/noop.go @@ -19,6 +19,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric/number" + "go.opentelemetry.io/otel/metric/sdkapi" ) // NewNoopMeterProvider returns an implementation of MeterProvider that @@ -48,8 +49,8 @@ func (noopInstrument) Implementation() interface{} { return nil } -func (noopInstrument) Descriptor() Descriptor { - return Descriptor{} +func (noopInstrument) Descriptor() sdkapi.Descriptor { + return sdkapi.Descriptor{} } func (noopBoundInstrument) RecordOne(context.Context, number.Number) { diff --git a/metric/sdkapi/descriptor.go b/metric/sdkapi/descriptor.go new file mode 100644 index 00000000000..14eb0532e45 --- /dev/null +++ b/metric/sdkapi/descriptor.go @@ -0,0 +1,70 @@ +// 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. + +package sdkapi // import "go.opentelemetry.io/otel/metric/sdkapi" + +import ( + "go.opentelemetry.io/otel/metric/number" + "go.opentelemetry.io/otel/metric/unit" +) + +// Descriptor contains all the settings that describe an instrument, +// including its name, metric kind, number kind, and the configurable +// options. +type Descriptor struct { + name string + instrumentKind InstrumentKind + numberKind number.Kind + description string + unit unit.Unit +} + +// NewDescriptor returns a Descriptor with the given contents. +func NewDescriptor(name string, ikind InstrumentKind, nkind number.Kind, description string, unit unit.Unit) Descriptor { + return Descriptor{ + name: name, + instrumentKind: ikind, + numberKind: nkind, + description: description, + unit: unit, + } +} + +// Name returns the metric instrument's name. +func (d Descriptor) Name() string { + return d.name +} + +// InstrumentKind returns the specific kind of instrument. +func (d Descriptor) InstrumentKind() InstrumentKind { + return d.instrumentKind +} + +// Description provides a human-readable description of the metric +// instrument. +func (d Descriptor) Description() string { + return d.description +} + +// Unit describes the units of the metric instrument. Unitless +// metrics return the empty string. +func (d Descriptor) Unit() unit.Unit { + return d.unit +} + +// NumberKind returns whether this instrument is declared over int64, +// float64, or uint64 values. +func (d Descriptor) NumberKind() number.Kind { + return d.numberKind +} diff --git a/metric/sdkapi/descriptor_test.go b/metric/sdkapi/descriptor_test.go new file mode 100644 index 00000000000..6b6927075f9 --- /dev/null +++ b/metric/sdkapi/descriptor_test.go @@ -0,0 +1,33 @@ +// 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. + +package sdkapi + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "go.opentelemetry.io/otel/metric/number" + "go.opentelemetry.io/otel/metric/unit" +) + +func TestDescriptorGetters(t *testing.T) { + d := NewDescriptor("name", HistogramInstrumentKind, number.Int64Kind, "my description", "my unit") + require.Equal(t, "name", d.Name()) + require.Equal(t, HistogramInstrumentKind, d.InstrumentKind()) + require.Equal(t, number.Int64Kind, d.NumberKind()) + require.Equal(t, "my description", d.Description()) + require.Equal(t, unit.Unit("my unit"), d.Unit()) +} diff --git a/sdk/export/metric/metric.go b/sdk/export/metric/metric.go index 46c8d99a565..a9a77415f5b 100644 --- a/sdk/export/metric/metric.go +++ b/sdk/export/metric/metric.go @@ -22,7 +22,6 @@ import ( "time" "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/sdkapi" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" @@ -97,7 +96,7 @@ type AggregatorSelector interface { // Note: This is context-free because the aggregator should // not relate to the incoming context. This call should not // block. - AggregatorFor(descriptor *metric.Descriptor, aggregator ...*Aggregator) + AggregatorFor(descriptor *sdkapi.Descriptor, aggregator ...*Aggregator) } // Checkpointer is the interface used by a Controller to coordinate @@ -161,7 +160,7 @@ type Aggregator interface { // // The Context argument comes from user-level code and could be // inspected for a `correlation.Map` or `trace.SpanContext`. - Update(ctx context.Context, number number.Number, descriptor *metric.Descriptor) error + Update(ctx context.Context, number number.Number, descriptor *sdkapi.Descriptor) error // SynchronizedMove is called during collection to finish one // period of aggregation by atomically saving the @@ -185,7 +184,7 @@ type Aggregator interface { // // When called with a nil `destination`, this Aggregator is reset // and the current value is discarded. - SynchronizedMove(destination Aggregator, descriptor *metric.Descriptor) error + SynchronizedMove(destination Aggregator, descriptor *sdkapi.Descriptor) error // Merge combines the checkpointed state from the argument // Aggregator into this Aggregator. Merge is not synchronized @@ -193,7 +192,7 @@ type Aggregator interface { // // The owner of an Aggregator being merged is responsible for // synchronization of both Aggregator states. - Merge(aggregator Aggregator, descriptor *metric.Descriptor) error + Merge(aggregator Aggregator, descriptor *sdkapi.Descriptor) error } // Subtractor is an optional interface implemented by some @@ -203,7 +202,7 @@ type Aggregator interface { type Subtractor interface { // Subtract subtracts the `operand` from this Aggregator and // outputs the value in `result`. - Subtract(operand, result Aggregator, descriptor *metric.Descriptor) error + Subtract(operand, result Aggregator, descriptor *sdkapi.Descriptor) error } // Exporter handles presentation of the checkpoint of aggregate @@ -233,7 +232,7 @@ type ExportKindSelector interface { // ExportKindFor should return the correct ExportKind that // should be used when exporting data for the given metric // instrument and Aggregator kind. - ExportKindFor(descriptor *metric.Descriptor, aggregatorKind aggregation.Kind) ExportKind + ExportKindFor(descriptor *sdkapi.Descriptor, aggregatorKind aggregation.Kind) ExportKind } // InstrumentationLibraryReader is an interface for exporters to iterate @@ -283,7 +282,7 @@ type Reader interface { // are shared by the Accumulator->Processor and Processor->Exporter // steps. type Metadata struct { - descriptor *metric.Descriptor + descriptor *sdkapi.Descriptor labels *attribute.Set } @@ -305,7 +304,7 @@ type Record struct { } // Descriptor describes the metric instrument being exported. -func (m Metadata) Descriptor() *metric.Descriptor { +func (m Metadata) Descriptor() *sdkapi.Descriptor { return m.descriptor } @@ -319,7 +318,7 @@ func (m Metadata) Labels() *attribute.Set { // Accumulations to send to Processors. The Descriptor, Labels, // and Aggregator represent aggregate metric events received over a single // collection period. -func NewAccumulation(descriptor *metric.Descriptor, labels *attribute.Set, aggregator Aggregator) Accumulation { +func NewAccumulation(descriptor *sdkapi.Descriptor, labels *attribute.Set, aggregator Aggregator) Accumulation { return Accumulation{ Metadata: Metadata{ descriptor: descriptor, @@ -338,7 +337,7 @@ func (r Accumulation) Aggregator() Aggregator { // NewRecord allows Processor implementations to construct export // records. The Descriptor, Labels, and Aggregator represent // aggregate metric events received over a single collection period. -func NewRecord(descriptor *metric.Descriptor, labels *attribute.Set, aggregation aggregation.Aggregation, start, end time.Time) Record { +func NewRecord(descriptor *sdkapi.Descriptor, labels *attribute.Set, aggregation aggregation.Aggregation, start, end time.Time) Record { return Record{ Metadata: Metadata{ descriptor: descriptor, @@ -441,12 +440,12 @@ func StatelessExportKindSelector() ExportKindSelector { } // ExportKindFor implements ExportKindSelector. -func (c constantExportKindSelector) ExportKindFor(_ *metric.Descriptor, _ aggregation.Kind) ExportKind { +func (c constantExportKindSelector) ExportKindFor(_ *sdkapi.Descriptor, _ aggregation.Kind) ExportKind { return ExportKind(c) } // ExportKindFor implements ExportKindSelector. -func (s statelessExportKindSelector) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) ExportKind { +func (s statelessExportKindSelector) ExportKindFor(desc *sdkapi.Descriptor, kind aggregation.Kind) ExportKind { if kind == aggregation.SumKind && desc.InstrumentKind().PrecomputedSum() { return CumulativeExportKind } diff --git a/sdk/metric/aggregator/aggregator.go b/sdk/metric/aggregator/aggregator.go index 478d6fc2130..13a315e2d4a 100644 --- a/sdk/metric/aggregator/aggregator.go +++ b/sdk/metric/aggregator/aggregator.go @@ -18,7 +18,6 @@ import ( "fmt" "math" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" @@ -36,7 +35,7 @@ func NewInconsistentAggregatorError(a1, a2 export.Aggregator) error { // This rejects NaN values. This rejects negative values when the // metric instrument does not support negative values, including // monotonic counter metrics and absolute Histogram metrics. -func RangeTest(num number.Number, descriptor *metric.Descriptor) error { +func RangeTest(num number.Number, descriptor *sdkapi.Descriptor) error { numberKind := descriptor.NumberKind() if numberKind == number.Float64Kind && math.IsNaN(num.AsFloat64()) { diff --git a/sdk/metric/aggregator/aggregator_test.go b/sdk/metric/aggregator/aggregator_test.go index 24e91a7d7e6..fd85297ed1d 100644 --- a/sdk/metric/aggregator/aggregator_test.go +++ b/sdk/metric/aggregator/aggregator_test.go @@ -21,7 +21,6 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/metrictest" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/sdkapi" @@ -41,7 +40,7 @@ func TestInconsistentAggregatorErr(t *testing.T) { require.True(t, errors.Is(err, aggregation.ErrInconsistentType)) } -func testRangeNaN(t *testing.T, desc *metric.Descriptor) { +func testRangeNaN(t *testing.T, desc *sdkapi.Descriptor) { // If the descriptor uses int64 numbers, this won't register as NaN nan := number.NewFloat64Number(math.NaN()) err := aggregator.RangeTest(nan, desc) @@ -53,7 +52,7 @@ func testRangeNaN(t *testing.T, desc *metric.Descriptor) { } } -func testRangeNegative(t *testing.T, desc *metric.Descriptor) { +func testRangeNegative(t *testing.T, desc *sdkapi.Descriptor) { var neg, pos number.Number if desc.NumberKind() == number.Float64Kind { diff --git a/sdk/metric/aggregator/aggregatortest/test.go b/sdk/metric/aggregator/aggregatortest/test.go index a6b5a964977..2fbfca5eed9 100644 --- a/sdk/metric/aggregator/aggregatortest/test.go +++ b/sdk/metric/aggregator/aggregatortest/test.go @@ -26,7 +26,6 @@ import ( "github.com/stretchr/testify/require" ottest "go.opentelemetry.io/otel/internal/internaltest" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/metrictest" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/sdkapi" @@ -66,7 +65,7 @@ func newProfiles() []Profile { } } -func NewAggregatorTest(mkind sdkapi.InstrumentKind, nkind number.Kind) *metric.Descriptor { +func NewAggregatorTest(mkind sdkapi.InstrumentKind, nkind number.Kind) *sdkapi.Descriptor { desc := metrictest.NewDescriptor("test.name", mkind, nkind) return &desc } @@ -151,7 +150,7 @@ func (n *Numbers) Points() []number.Number { } // CheckedUpdate performs the same range test the SDK does on behalf of the aggregator. -func CheckedUpdate(t *testing.T, agg export.Aggregator, number number.Number, descriptor *metric.Descriptor) { +func CheckedUpdate(t *testing.T, agg export.Aggregator, number number.Number, descriptor *sdkapi.Descriptor) { ctx := context.Background() // Note: Aggregator tests are written assuming that the SDK @@ -167,7 +166,7 @@ func CheckedUpdate(t *testing.T, agg export.Aggregator, number number.Number, de } } -func CheckedMerge(t *testing.T, aggInto, aggFrom export.Aggregator, descriptor *metric.Descriptor) { +func CheckedMerge(t *testing.T, aggInto, aggFrom export.Aggregator, descriptor *sdkapi.Descriptor) { if err := aggInto.Merge(aggFrom, descriptor); err != nil { t.Error("Unexpected Merge failure", err) } @@ -181,19 +180,19 @@ func (NoopAggregator) Aggregation() aggregation.Aggregation { return NoopAggregation{} } -func (NoopAggregator) Update(context.Context, number.Number, *metric.Descriptor) error { +func (NoopAggregator) Update(context.Context, number.Number, *sdkapi.Descriptor) error { return nil } -func (NoopAggregator) SynchronizedMove(export.Aggregator, *metric.Descriptor) error { +func (NoopAggregator) SynchronizedMove(export.Aggregator, *sdkapi.Descriptor) error { return nil } -func (NoopAggregator) Merge(export.Aggregator, *metric.Descriptor) error { +func (NoopAggregator) Merge(export.Aggregator, *sdkapi.Descriptor) error { return nil } -func SynchronizedMoveResetTest(t *testing.T, mkind sdkapi.InstrumentKind, nf func(*metric.Descriptor) export.Aggregator) { +func SynchronizedMoveResetTest(t *testing.T, mkind sdkapi.InstrumentKind, nf func(*sdkapi.Descriptor) export.Aggregator) { t.Run("reset on nil", func(t *testing.T) { // Ensures that SynchronizedMove(nil, descriptor) discards and // resets the aggregator. diff --git a/sdk/metric/aggregator/exact/exact.go b/sdk/metric/aggregator/exact/exact.go index c2c7adaf256..336cd878fd0 100644 --- a/sdk/metric/aggregator/exact/exact.go +++ b/sdk/metric/aggregator/exact/exact.go @@ -19,8 +19,8 @@ import ( "sync" "time" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" + "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/metric/aggregator" @@ -68,7 +68,7 @@ func (c *Aggregator) Points() ([]aggregation.Point, error) { // SynchronizedMove saves the current state to oa and resets the current state to // the empty set, taking a lock to prevent concurrent Update() calls. -func (c *Aggregator) SynchronizedMove(oa export.Aggregator, desc *metric.Descriptor) error { +func (c *Aggregator) SynchronizedMove(oa export.Aggregator, desc *sdkapi.Descriptor) error { o, _ := oa.(*Aggregator) if oa != nil && o == nil { @@ -89,7 +89,7 @@ func (c *Aggregator) SynchronizedMove(oa export.Aggregator, desc *metric.Descrip // Update adds the recorded measurement to the current data set. // Update takes a lock to prevent concurrent Update() and SynchronizedMove() // calls. -func (c *Aggregator) Update(_ context.Context, number number.Number, desc *metric.Descriptor) error { +func (c *Aggregator) Update(_ context.Context, number number.Number, desc *sdkapi.Descriptor) error { now := time.Now() c.lock.Lock() defer c.lock.Unlock() @@ -102,7 +102,7 @@ func (c *Aggregator) Update(_ context.Context, number number.Number, desc *metri } // Merge combines two data sets into one. -func (c *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error { +func (c *Aggregator) Merge(oa export.Aggregator, desc *sdkapi.Descriptor) error { o, _ := oa.(*Aggregator) if o == nil { return aggregator.NewInconsistentAggregatorError(c, oa) diff --git a/sdk/metric/aggregator/exact/exact_test.go b/sdk/metric/aggregator/exact/exact_test.go index adadd38a0b0..0ef1fdf9379 100644 --- a/sdk/metric/aggregator/exact/exact_test.go +++ b/sdk/metric/aggregator/exact/exact_test.go @@ -22,7 +22,6 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" @@ -38,7 +37,7 @@ func requireNotAfter(t *testing.T, t1, t2 time.Time) { require.False(t, t1.After(t2), "expected %v ≤ %v", t1, t2) } -func checkZero(t *testing.T, agg *Aggregator, desc *metric.Descriptor) { +func checkZero(t *testing.T, agg *Aggregator, desc *sdkapi.Descriptor) { count, err := agg.Count() require.NoError(t, err) require.Equal(t, uint64(0), count) @@ -312,7 +311,7 @@ func TestSynchronizedMoveReset(t *testing.T) { aggregatortest.SynchronizedMoveResetTest( t, sdkapi.HistogramInstrumentKind, - func(desc *metric.Descriptor) export.Aggregator { + func(desc *sdkapi.Descriptor) export.Aggregator { return &New(1)[0] }, ) diff --git a/sdk/metric/aggregator/histogram/histogram.go b/sdk/metric/aggregator/histogram/histogram.go index ea3ecdbb5b2..899c71cacd1 100644 --- a/sdk/metric/aggregator/histogram/histogram.go +++ b/sdk/metric/aggregator/histogram/histogram.go @@ -19,8 +19,8 @@ import ( "sort" "sync" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" + "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/metric/aggregator" @@ -110,7 +110,7 @@ var _ aggregation.Histogram = &Aggregator{} // Note that this aggregator maintains each value using independent // atomic operations, which introduces the possibility that // checkpoints are inconsistent. -func New(cnt int, desc *metric.Descriptor, opts ...Option) []Aggregator { +func New(cnt int, desc *sdkapi.Descriptor, opts ...Option) []Aggregator { var cfg config if desc.NumberKind() == number.Int64Kind { @@ -174,7 +174,7 @@ func (c *Aggregator) Histogram() (aggregation.Buckets, error) { // the empty set. Since no locks are taken, there is a chance that // the independent Sum, Count and Bucket Count are not consistent with each // other. -func (c *Aggregator) SynchronizedMove(oa export.Aggregator, desc *metric.Descriptor) error { +func (c *Aggregator) SynchronizedMove(oa export.Aggregator, desc *sdkapi.Descriptor) error { o, _ := oa.(*Aggregator) if oa != nil && o == nil { @@ -220,7 +220,7 @@ func (c *Aggregator) clearState() { } // Update adds the recorded measurement to the current data set. -func (c *Aggregator) Update(_ context.Context, number number.Number, desc *metric.Descriptor) error { +func (c *Aggregator) Update(_ context.Context, number number.Number, desc *sdkapi.Descriptor) error { kind := desc.NumberKind() asFloat := number.CoerceToFloat64(kind) @@ -254,7 +254,7 @@ func (c *Aggregator) Update(_ context.Context, number number.Number, desc *metri } // Merge combines two histograms that have the same buckets into a single one. -func (c *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error { +func (c *Aggregator) Merge(oa export.Aggregator, desc *sdkapi.Descriptor) error { o, _ := oa.(*Aggregator) if o == nil { return aggregator.NewInconsistentAggregatorError(c, oa) diff --git a/sdk/metric/aggregator/histogram/histogram_test.go b/sdk/metric/aggregator/histogram/histogram_test.go index 0b56cb5dd0c..a4c5c6da687 100644 --- a/sdk/metric/aggregator/histogram/histogram_test.go +++ b/sdk/metric/aggregator/histogram/histogram_test.go @@ -23,7 +23,6 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" @@ -64,17 +63,17 @@ var ( testBoundaries = []float64{500, 250, 750} ) -func new2(desc *metric.Descriptor, options ...histogram.Option) (_, _ *histogram.Aggregator) { +func new2(desc *sdkapi.Descriptor, options ...histogram.Option) (_, _ *histogram.Aggregator) { alloc := histogram.New(2, desc, options...) return &alloc[0], &alloc[1] } -func new4(desc *metric.Descriptor, options ...histogram.Option) (_, _, _, _ *histogram.Aggregator) { +func new4(desc *sdkapi.Descriptor, options ...histogram.Option) (_, _, _, _ *histogram.Aggregator) { alloc := histogram.New(4, desc, options...) return &alloc[0], &alloc[1], &alloc[2], &alloc[3] } -func checkZero(t *testing.T, agg *histogram.Aggregator, desc *metric.Descriptor) { +func checkZero(t *testing.T, agg *histogram.Aggregator, desc *sdkapi.Descriptor) { asum, err := agg.Sum() require.Equal(t, number.Number(0), asum, "Empty checkpoint sum = 0") require.NoError(t, err) @@ -241,7 +240,7 @@ func TestSynchronizedMoveReset(t *testing.T) { aggregatortest.SynchronizedMoveResetTest( t, sdkapi.HistogramInstrumentKind, - func(desc *metric.Descriptor) export.Aggregator { + func(desc *sdkapi.Descriptor) export.Aggregator { return &histogram.New(1, desc, histogram.WithExplicitBoundaries(testBoundaries))[0] }, ) diff --git a/sdk/metric/aggregator/lastvalue/lastvalue.go b/sdk/metric/aggregator/lastvalue/lastvalue.go index 3cc5f7055cf..71b117890cb 100644 --- a/sdk/metric/aggregator/lastvalue/lastvalue.go +++ b/sdk/metric/aggregator/lastvalue/lastvalue.go @@ -20,8 +20,8 @@ import ( "time" "unsafe" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" + "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/metric/aggregator" @@ -92,7 +92,7 @@ func (g *Aggregator) LastValue() (number.Number, time.Time, error) { } // SynchronizedMove atomically saves the current value. -func (g *Aggregator) SynchronizedMove(oa export.Aggregator, _ *metric.Descriptor) error { +func (g *Aggregator) SynchronizedMove(oa export.Aggregator, _ *sdkapi.Descriptor) error { if oa == nil { atomic.StorePointer(&g.value, unsafe.Pointer(unsetLastValue)) return nil @@ -106,7 +106,7 @@ func (g *Aggregator) SynchronizedMove(oa export.Aggregator, _ *metric.Descriptor } // Update atomically sets the current "last" value. -func (g *Aggregator) Update(_ context.Context, number number.Number, desc *metric.Descriptor) error { +func (g *Aggregator) Update(_ context.Context, number number.Number, desc *sdkapi.Descriptor) error { ngd := &lastValueData{ value: number, timestamp: time.Now(), @@ -117,7 +117,7 @@ func (g *Aggregator) Update(_ context.Context, number number.Number, desc *metri // Merge combines state from two aggregators. The most-recently set // value is chosen. -func (g *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error { +func (g *Aggregator) Merge(oa export.Aggregator, desc *sdkapi.Descriptor) error { o, _ := oa.(*Aggregator) if o == nil { return aggregator.NewInconsistentAggregatorError(g, oa) diff --git a/sdk/metric/aggregator/lastvalue/lastvalue_test.go b/sdk/metric/aggregator/lastvalue/lastvalue_test.go index 01166b5b609..8f1a771009c 100644 --- a/sdk/metric/aggregator/lastvalue/lastvalue_test.go +++ b/sdk/metric/aggregator/lastvalue/lastvalue_test.go @@ -25,7 +25,6 @@ import ( "github.com/stretchr/testify/require" ottest "go.opentelemetry.io/otel/internal/internaltest" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" @@ -140,7 +139,7 @@ func TestSynchronizedMoveReset(t *testing.T) { aggregatortest.SynchronizedMoveResetTest( t, sdkapi.GaugeObserverInstrumentKind, - func(desc *metric.Descriptor) export.Aggregator { + func(desc *sdkapi.Descriptor) export.Aggregator { return &New(1)[0] }, ) diff --git a/sdk/metric/aggregator/minmaxsumcount/mmsc.go b/sdk/metric/aggregator/minmaxsumcount/mmsc.go index e21fd75ab73..663cb4e0d3d 100644 --- a/sdk/metric/aggregator/minmaxsumcount/mmsc.go +++ b/sdk/metric/aggregator/minmaxsumcount/mmsc.go @@ -18,8 +18,8 @@ import ( "context" "sync" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" + "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/metric/aggregator" @@ -49,7 +49,7 @@ var _ aggregation.MinMaxSumCount = &Aggregator{} // count. // // This type uses a mutex for Update() and SynchronizedMove() concurrency. -func New(cnt int, desc *metric.Descriptor) []Aggregator { +func New(cnt int, desc *sdkapi.Descriptor) []Aggregator { kind := desc.NumberKind() aggs := make([]Aggregator, cnt) for i := range aggs { @@ -103,7 +103,7 @@ func (c *Aggregator) Max() (number.Number, error) { // SynchronizedMove saves the current state into oa and resets the current state to // the empty set. -func (c *Aggregator) SynchronizedMove(oa export.Aggregator, desc *metric.Descriptor) error { +func (c *Aggregator) SynchronizedMove(oa export.Aggregator, desc *sdkapi.Descriptor) error { o, _ := oa.(*Aggregator) if oa != nil && o == nil { @@ -129,7 +129,7 @@ func emptyState(kind number.Kind) state { } // Update adds the recorded measurement to the current data set. -func (c *Aggregator) Update(_ context.Context, number number.Number, desc *metric.Descriptor) error { +func (c *Aggregator) Update(_ context.Context, number number.Number, desc *sdkapi.Descriptor) error { kind := desc.NumberKind() c.lock.Lock() @@ -146,7 +146,7 @@ func (c *Aggregator) Update(_ context.Context, number number.Number, desc *metri } // Merge combines two data sets into one. -func (c *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error { +func (c *Aggregator) Merge(oa export.Aggregator, desc *sdkapi.Descriptor) error { o, _ := oa.(*Aggregator) if o == nil { return aggregator.NewInconsistentAggregatorError(c, oa) diff --git a/sdk/metric/aggregator/minmaxsumcount/mmsc_test.go b/sdk/metric/aggregator/minmaxsumcount/mmsc_test.go index 84535ceda13..b0dc7f8fb19 100644 --- a/sdk/metric/aggregator/minmaxsumcount/mmsc_test.go +++ b/sdk/metric/aggregator/minmaxsumcount/mmsc_test.go @@ -22,7 +22,6 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" @@ -79,17 +78,17 @@ func TestMinMaxSumCountPositiveAndNegative(t *testing.T) { }) } -func new2(desc *metric.Descriptor) (_, _ *Aggregator) { +func new2(desc *sdkapi.Descriptor) (_, _ *Aggregator) { alloc := New(2, desc) return &alloc[0], &alloc[1] } -func new4(desc *metric.Descriptor) (_, _, _, _ *Aggregator) { +func new4(desc *sdkapi.Descriptor) (_, _, _, _ *Aggregator) { alloc := New(4, desc) return &alloc[0], &alloc[1], &alloc[2], &alloc[3] } -func checkZero(t *testing.T, agg *Aggregator, desc *metric.Descriptor) { +func checkZero(t *testing.T, agg *Aggregator, desc *sdkapi.Descriptor) { kind := desc.NumberKind() sum, err := agg.Sum() @@ -242,7 +241,7 @@ func TestSynchronizedMoveReset(t *testing.T) { aggregatortest.SynchronizedMoveResetTest( t, sdkapi.HistogramInstrumentKind, - func(desc *metric.Descriptor) export.Aggregator { + func(desc *sdkapi.Descriptor) export.Aggregator { return &New(1, desc)[0] }, ) diff --git a/sdk/metric/aggregator/sum/sum.go b/sdk/metric/aggregator/sum/sum.go index fc96ddb4cba..26390a61015 100644 --- a/sdk/metric/aggregator/sum/sum.go +++ b/sdk/metric/aggregator/sum/sum.go @@ -17,8 +17,8 @@ package sum // import "go.opentelemetry.io/otel/sdk/metric/aggregator/sum" import ( "context" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" + "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/metric/aggregator" @@ -60,7 +60,7 @@ func (c *Aggregator) Sum() (number.Number, error) { // SynchronizedMove atomically saves the current value into oa and resets the // current sum to zero. -func (c *Aggregator) SynchronizedMove(oa export.Aggregator, _ *metric.Descriptor) error { +func (c *Aggregator) SynchronizedMove(oa export.Aggregator, _ *sdkapi.Descriptor) error { if oa == nil { c.value.SetRawAtomic(0) return nil @@ -74,13 +74,13 @@ func (c *Aggregator) SynchronizedMove(oa export.Aggregator, _ *metric.Descriptor } // Update atomically adds to the current value. -func (c *Aggregator) Update(_ context.Context, num number.Number, desc *metric.Descriptor) error { +func (c *Aggregator) Update(_ context.Context, num number.Number, desc *sdkapi.Descriptor) error { c.value.AddNumberAtomic(desc.NumberKind(), num) return nil } // Merge combines two counters by adding their sums. -func (c *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error { +func (c *Aggregator) Merge(oa export.Aggregator, desc *sdkapi.Descriptor) error { o, _ := oa.(*Aggregator) if o == nil { return aggregator.NewInconsistentAggregatorError(c, oa) @@ -89,7 +89,7 @@ func (c *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error return nil } -func (c *Aggregator) Subtract(opAgg, resAgg export.Aggregator, descriptor *metric.Descriptor) error { +func (c *Aggregator) Subtract(opAgg, resAgg export.Aggregator, descriptor *sdkapi.Descriptor) error { op, _ := opAgg.(*Aggregator) if op == nil { return aggregator.NewInconsistentAggregatorError(c, opAgg) diff --git a/sdk/metric/aggregator/sum/sum_test.go b/sdk/metric/aggregator/sum/sum_test.go index 50780656ccc..3387c83cc8d 100644 --- a/sdk/metric/aggregator/sum/sum_test.go +++ b/sdk/metric/aggregator/sum/sum_test.go @@ -22,7 +22,6 @@ import ( "github.com/stretchr/testify/require" ottest "go.opentelemetry.io/otel/internal/internaltest" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" @@ -56,7 +55,7 @@ func new4() (_, _, _, _ *Aggregator) { return &alloc[0], &alloc[1], &alloc[2], &alloc[3] } -func checkZero(t *testing.T, agg *Aggregator, desc *metric.Descriptor) { +func checkZero(t *testing.T, agg *Aggregator, desc *sdkapi.Descriptor) { kind := desc.NumberKind() sum, err := agg.Sum() @@ -148,7 +147,7 @@ func TestSynchronizedMoveReset(t *testing.T) { aggregatortest.SynchronizedMoveResetTest( t, sdkapi.CounterObserverInstrumentKind, - func(desc *metric.Descriptor) export.Aggregator { + func(desc *sdkapi.Descriptor) export.Aggregator { return &New(1)[0] }, ) diff --git a/sdk/metric/controller/basic/controller_test.go b/sdk/metric/controller/basic/controller_test.go index 4cca2cc2442..dd90e7c0b7c 100644 --- a/sdk/metric/controller/basic/controller_test.go +++ b/sdk/metric/controller/basic/controller_test.go @@ -26,6 +26,7 @@ import ( "go.opentelemetry.io/otel/attribute" ottest "go.opentelemetry.io/otel/internal/internaltest" "go.opentelemetry.io/otel/metric" + "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/instrumentation" @@ -296,7 +297,7 @@ func (b *blockingExporter) Export(ctx context.Context, res *resource.Resource, o } func (*blockingExporter) ExportKindFor( - *metric.Descriptor, + *sdkapi.Descriptor, aggregation.Kind, ) export.ExportKind { return export.CumulativeExportKind diff --git a/sdk/metric/correct_test.go b/sdk/metric/correct_test.go index c5a62247bac..773a99de0a5 100644 --- a/sdk/metric/correct_test.go +++ b/sdk/metric/correct_test.go @@ -26,6 +26,7 @@ import ( "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" + "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" metricsdk "go.opentelemetry.io/otel/sdk/metric" @@ -71,7 +72,7 @@ type testSelector struct { newAggCount int } -func (ts *testSelector) AggregatorFor(desc *metric.Descriptor, aggPtrs ...*export.Aggregator) { +func (ts *testSelector) AggregatorFor(desc *sdkapi.Descriptor, aggPtrs ...*export.Aggregator) { ts.newAggCount += len(aggPtrs) processortest.AggregatorSelector().AggregatorFor(desc, aggPtrs...) } diff --git a/sdk/metric/processor/basic/basic.go b/sdk/metric/processor/basic/basic.go index a8340b8ecbc..c01509faf04 100644 --- a/sdk/metric/processor/basic/basic.go +++ b/sdk/metric/processor/basic/basic.go @@ -21,7 +21,7 @@ import ( "time" "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric" + "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" ) @@ -40,13 +40,13 @@ type ( // data for the same instrument, and this code has // logic to combine data properly from multiple // accumulators. However, the use of - // *metric.Descriptor in the stateKey makes such + // *sdkapi.Descriptor in the stateKey makes such // combination impossible, because each accumulator // allocates its own instruments. This can be fixed // by using the instrument name and kind instead of // the descriptor pointer. See // https://github.com/open-telemetry/opentelemetry-go/issues/862. - descriptor *metric.Descriptor + descriptor *sdkapi.Descriptor distinct attribute.Distinct } diff --git a/sdk/metric/processor/basic/basic_test.go b/sdk/metric/processor/basic/basic_test.go index dec7dbbeba5..131d73b5c7d 100644 --- a/sdk/metric/processor/basic/basic_test.go +++ b/sdk/metric/processor/basic/basic_test.go @@ -110,7 +110,7 @@ func asNumber(nkind number.Kind, value int64) number.Number { return number.NewFloat64Number(float64(value)) } -func updateFor(t *testing.T, desc *metric.Descriptor, selector export.AggregatorSelector, value int64, labs ...attribute.KeyValue) export.Accumulation { +func updateFor(t *testing.T, desc *sdkapi.Descriptor, selector export.AggregatorSelector, value int64, labs ...attribute.KeyValue) export.Accumulation { ls := attribute.NewSet(labs...) var agg export.Aggregator selector.AggregatorFor(desc, &agg) @@ -265,7 +265,7 @@ func testProcessor( type bogusExporter struct{} -func (bogusExporter) ExportKindFor(*metric.Descriptor, aggregation.Kind) export.ExportKind { +func (bogusExporter) ExportKindFor(*sdkapi.Descriptor, aggregation.Kind) export.ExportKind { return 1000000 } diff --git a/sdk/metric/processor/processortest/test.go b/sdk/metric/processor/processortest/test.go index 05fc7fb9b6b..15488f3370e 100644 --- a/sdk/metric/processor/processortest/test.go +++ b/sdk/metric/processor/processortest/test.go @@ -22,8 +22,8 @@ import ( "time" "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" + "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/instrumentation" @@ -40,7 +40,7 @@ type ( // unique descriptor, distinct labels, and distinct resource // attributes. mapKey struct { - desc *metric.Descriptor + desc *sdkapi.Descriptor labels attribute.Distinct resource attribute.Distinct } @@ -181,7 +181,7 @@ func AggregatorSelector() export.AggregatorSelector { } // AggregatorFor implements export.AggregatorSelector. -func (testAggregatorSelector) AggregatorFor(desc *metric.Descriptor, aggPtrs ...*export.Aggregator) { +func (testAggregatorSelector) AggregatorFor(desc *sdkapi.Descriptor, aggPtrs ...*export.Aggregator) { switch { case strings.HasSuffix(desc.Name(), ".disabled"): diff --git a/sdk/metric/processor/reducer/doc.go b/sdk/metric/processor/reducer/doc.go index 18b00b8197f..cebdf0355e4 100644 --- a/sdk/metric/processor/reducer/doc.go +++ b/sdk/metric/processor/reducer/doc.go @@ -33,7 +33,7 @@ type someFilter struct{ // ... } -func (someFilter) LabelFilterFor(_ *metric.Descriptor) attribute.Filter { +func (someFilter) LabelFilterFor(_ *sdkapi.Descriptor) attribute.Filter { return func(label kv.KeyValue) bool { // return true to keep this label, false to drop this label // ... diff --git a/sdk/metric/processor/reducer/reducer.go b/sdk/metric/processor/reducer/reducer.go index 6b8f3cd6eb1..deb9edd34f1 100644 --- a/sdk/metric/processor/reducer/reducer.go +++ b/sdk/metric/processor/reducer/reducer.go @@ -16,7 +16,7 @@ package reducer // import "go.opentelemetry.io/otel/sdk/metric/processor/reducer import ( "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric" + "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" ) @@ -31,7 +31,7 @@ type ( // LabelFilterSelector is the interface used to configure a // specific Filter to an instrument. LabelFilterSelector interface { - LabelFilterFor(descriptor *metric.Descriptor) attribute.Filter + LabelFilterFor(descriptor *sdkapi.Descriptor) attribute.Filter } ) diff --git a/sdk/metric/processor/reducer/reducer_test.go b/sdk/metric/processor/reducer/reducer_test.go index 3eb9ce3a268..178e6188d97 100644 --- a/sdk/metric/processor/reducer/reducer_test.go +++ b/sdk/metric/processor/reducer/reducer_test.go @@ -22,6 +22,7 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" + "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/instrumentation" metricsdk "go.opentelemetry.io/otel/sdk/metric" @@ -47,7 +48,7 @@ var ( type testFilter struct{} -func (testFilter) LabelFilterFor(_ *metric.Descriptor) attribute.Filter { +func (testFilter) LabelFilterFor(_ *sdkapi.Descriptor) attribute.Filter { return func(label attribute.KeyValue) bool { return label.Key == "A" || label.Key == "C" } diff --git a/sdk/metric/sdk.go b/sdk/metric/sdk.go index d06596f918e..33b558f1155 100644 --- a/sdk/metric/sdk.go +++ b/sdk/metric/sdk.go @@ -26,6 +26,7 @@ import ( internal "go.opentelemetry.io/otel/internal/metric" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/number" + "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/metric/aggregator" ) @@ -72,7 +73,7 @@ type ( // mapkey uniquely describes a metric instrument in terms of // its InstrumentID and the encoded form of its labels. mapkey struct { - descriptor *metric.Descriptor + descriptor *sdkapi.Descriptor ordered attribute.Distinct } @@ -120,7 +121,7 @@ type ( instrument struct { meter *Accumulator - descriptor metric.Descriptor + descriptor sdkapi.Descriptor } asyncInstrument struct { @@ -147,7 +148,7 @@ var ( ErrUninitializedInstrument = fmt.Errorf("use of an uninitialized instrument") ) -func (inst *instrument) Descriptor() metric.Descriptor { +func (inst *instrument) Descriptor() sdkapi.Descriptor { return inst.descriptor } @@ -308,7 +309,7 @@ func NewAccumulator(processor export.Processor) *Accumulator { } // NewSyncInstrument implements metric.MetricImpl. -func (m *Accumulator) NewSyncInstrument(descriptor metric.Descriptor) (metric.SyncImpl, error) { +func (m *Accumulator) NewSyncInstrument(descriptor sdkapi.Descriptor) (metric.SyncImpl, error) { return &syncInstrument{ instrument: instrument{ descriptor: descriptor, @@ -318,7 +319,7 @@ func (m *Accumulator) NewSyncInstrument(descriptor metric.Descriptor) (metric.Sy } // NewAsyncInstrument implements metric.MetricImpl. -func (m *Accumulator) NewAsyncInstrument(descriptor metric.Descriptor, runner metric.AsyncRunner) (metric.AsyncImpl, error) { +func (m *Accumulator) NewAsyncInstrument(descriptor sdkapi.Descriptor, runner metric.AsyncRunner) (metric.AsyncImpl, error) { a := &asyncInstrument{ instrument: instrument{ descriptor: descriptor, diff --git a/sdk/metric/selector/simple/simple.go b/sdk/metric/selector/simple/simple.go index b2cd41bc99d..0f06827f05f 100644 --- a/sdk/metric/selector/simple/simple.go +++ b/sdk/metric/selector/simple/simple.go @@ -15,7 +15,6 @@ package simple // import "go.opentelemetry.io/otel/sdk/metric/selector/simple" import ( - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/sdkapi" export "go.opentelemetry.io/otel/sdk/export/metric" "go.opentelemetry.io/otel/sdk/metric/aggregator/exact" @@ -78,7 +77,7 @@ func lastValueAggs(aggPtrs []*export.Aggregator) { } } -func (selectorInexpensive) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) { +func (selectorInexpensive) AggregatorFor(descriptor *sdkapi.Descriptor, aggPtrs ...*export.Aggregator) { switch descriptor.InstrumentKind() { case sdkapi.GaugeObserverInstrumentKind: lastValueAggs(aggPtrs) @@ -92,7 +91,7 @@ func (selectorInexpensive) AggregatorFor(descriptor *metric.Descriptor, aggPtrs } } -func (selectorExact) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) { +func (selectorExact) AggregatorFor(descriptor *sdkapi.Descriptor, aggPtrs ...*export.Aggregator) { switch descriptor.InstrumentKind() { case sdkapi.GaugeObserverInstrumentKind: lastValueAggs(aggPtrs) @@ -106,7 +105,7 @@ func (selectorExact) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*ex } } -func (s selectorHistogram) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) { +func (s selectorHistogram) AggregatorFor(descriptor *sdkapi.Descriptor, aggPtrs ...*export.Aggregator) { switch descriptor.InstrumentKind() { case sdkapi.GaugeObserverInstrumentKind: lastValueAggs(aggPtrs) diff --git a/sdk/metric/selector/simple/simple_test.go b/sdk/metric/selector/simple/simple_test.go index 5ba02c074fc..12e629d0403 100644 --- a/sdk/metric/selector/simple/simple_test.go +++ b/sdk/metric/selector/simple/simple_test.go @@ -19,7 +19,6 @@ import ( "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/metrictest" "go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/sdkapi" @@ -41,7 +40,7 @@ var ( testGaugeObserverDesc = metrictest.NewDescriptor("gauge", sdkapi.GaugeObserverInstrumentKind, number.Int64Kind) ) -func oneAgg(sel export.AggregatorSelector, desc *metric.Descriptor) export.Aggregator { +func oneAgg(sel export.AggregatorSelector, desc *sdkapi.Descriptor) export.Aggregator { var agg export.Aggregator sel.AggregatorFor(desc, &agg) return agg diff --git a/sdk/metric/stress_test.go b/sdk/metric/stress_test.go index 09d89515d78..b005dba4242 100644 --- a/sdk/metric/stress_test.go +++ b/sdk/metric/stress_test.go @@ -71,7 +71,7 @@ type ( testKey struct { labels string - descriptor *metric.Descriptor + descriptor *sdkapi.Descriptor } testImpl struct { @@ -163,7 +163,7 @@ func (f *testFixture) startWorker(impl *Accumulator, meter metric.Meter, wg *syn ctx := context.Background() name := fmt.Sprint("test_", i) instrument := f.impl.newInstrument(meter, name) - var descriptor *metric.Descriptor + var descriptor *sdkapi.Descriptor if ii, ok := instrument.SyncImpl().(*syncInstrument); ok { descriptor = &ii.descriptor }