diff --git a/CHANGELOG.md b/CHANGELOG.md index 15c3ea40a..de0121fac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Move the `go.opentelemetry.io/otel/api/trace/tracetest` package into `go.opentelemetry.io/otel/oteltest`. (#1229) - OTLP Exporter supports OTLP v0.5.0. (#1230) - The Sampler is now called on local child spans. (#1233) +- The `Kind` type from the `go.opentelemetry.io/otel/api/metric` package was renamed to `InstrumentKind` to more specifically describe what it is and avoid semantic ambiguity. (#1240) +- The `MetricKind` method of the `Descriptor` type in the `go.opentelemetry.io/otel/api/metric` package was renamed to `Descriptor.InstrumentKind`. + This matches the returned type and fixes misuse of the term metric. (#1240) - Move test harness from the `go.opentelemetry.io/otel/api/apitest` package into `go.opentelemetry.io/otel/oteltest`. (#1241) - Rename `MergeItererator` to `MergeIterator` in the `go.opentelemetry.io/otel/label` package. (#1244) diff --git a/api/metric/api_test.go b/api/metric/api_test.go index 72a10073d..b5478b15f 100644 --- a/api/metric/api_test.go +++ b/api/metric/api_test.go @@ -32,7 +32,7 @@ import ( var Must = metric.Must -func checkSyncBatches(ctx context.Context, t *testing.T, labels []label.KeyValue, mock *mockTest.MeterImpl, nkind metric.NumberKind, mkind metric.Kind, instrument metric.InstrumentImpl, expected ...float64) { +func checkSyncBatches(ctx context.Context, t *testing.T, labels []label.KeyValue, mock *mockTest.MeterImpl, nkind metric.NumberKind, mkind metric.InstrumentKind, instrument metric.InstrumentImpl, expected ...float64) { t.Helper() batchesCount := len(mock.MeasurementBatches) @@ -131,7 +131,7 @@ func TestCounter(t *testing.T) { boundInstrument := c.Bind(labels...) boundInstrument.Add(ctx, -742) meter.RecordBatch(ctx, labels, c.Measurement(42)) - checkSyncBatches(ctx, t, labels, mockSDK, metric.Float64NumberKind, metric.CounterKind, c.SyncImpl(), + checkSyncBatches(ctx, t, labels, mockSDK, metric.Float64NumberKind, metric.CounterInstrumentKind, c.SyncImpl(), 1994.1, -742, 42, ) }) @@ -144,7 +144,7 @@ func TestCounter(t *testing.T) { boundInstrument := c.Bind(labels...) boundInstrument.Add(ctx, 4200) meter.RecordBatch(ctx, labels, c.Measurement(420000)) - checkSyncBatches(ctx, t, labels, mockSDK, metric.Int64NumberKind, metric.CounterKind, c.SyncImpl(), + checkSyncBatches(ctx, t, labels, mockSDK, metric.Int64NumberKind, metric.CounterInstrumentKind, c.SyncImpl(), 42, 4200, 420000, ) @@ -158,7 +158,7 @@ func TestCounter(t *testing.T) { boundInstrument := c.Bind(labels...) boundInstrument.Add(ctx, -100) meter.RecordBatch(ctx, labels, c.Measurement(42)) - checkSyncBatches(ctx, t, labels, mockSDK, metric.Int64NumberKind, metric.UpDownCounterKind, c.SyncImpl(), + checkSyncBatches(ctx, t, labels, mockSDK, metric.Int64NumberKind, metric.UpDownCounterInstrumentKind, c.SyncImpl(), 100, -100, 42, ) }) @@ -171,7 +171,7 @@ func TestCounter(t *testing.T) { boundInstrument := c.Bind(labels...) boundInstrument.Add(ctx, -76) meter.RecordBatch(ctx, labels, c.Measurement(-100.1)) - checkSyncBatches(ctx, t, labels, mockSDK, metric.Float64NumberKind, metric.UpDownCounterKind, c.SyncImpl(), + checkSyncBatches(ctx, t, labels, mockSDK, metric.Float64NumberKind, metric.UpDownCounterInstrumentKind, c.SyncImpl(), 100.1, -76, -100.1, ) }) @@ -187,7 +187,7 @@ func TestValueRecorder(t *testing.T) { boundInstrument := m.Bind(labels...) boundInstrument.Record(ctx, 0) meter.RecordBatch(ctx, labels, m.Measurement(-100.5)) - checkSyncBatches(ctx, t, labels, mockSDK, metric.Float64NumberKind, metric.ValueRecorderKind, m.SyncImpl(), + checkSyncBatches(ctx, t, labels, mockSDK, metric.Float64NumberKind, metric.ValueRecorderInstrumentKind, m.SyncImpl(), 42, 0, -100.5, ) }) @@ -200,7 +200,7 @@ func TestValueRecorder(t *testing.T) { boundInstrument := m.Bind(labels...) boundInstrument.Record(ctx, 80) meter.RecordBatch(ctx, labels, m.Measurement(0)) - checkSyncBatches(ctx, t, labels, mockSDK, metric.Int64NumberKind, metric.ValueRecorderKind, m.SyncImpl(), + checkSyncBatches(ctx, t, labels, mockSDK, metric.Int64NumberKind, metric.ValueRecorderInstrumentKind, m.SyncImpl(), 173, 80, 0, ) }) @@ -214,7 +214,7 @@ func TestObserverInstruments(t *testing.T) { result.Observe(42.1, labels...) }) mockSDK.RunAsyncInstruments() - checkObserverBatch(t, labels, mockSDK, metric.Float64NumberKind, metric.ValueObserverKind, o.AsyncImpl(), + checkObserverBatch(t, labels, mockSDK, metric.Float64NumberKind, metric.ValueObserverInstrumentKind, o.AsyncImpl(), 42.1, ) }) @@ -225,7 +225,7 @@ func TestObserverInstruments(t *testing.T) { result.Observe(-142, labels...) }) mockSDK.RunAsyncInstruments() - checkObserverBatch(t, labels, mockSDK, metric.Int64NumberKind, metric.ValueObserverKind, o.AsyncImpl(), + checkObserverBatch(t, labels, mockSDK, metric.Int64NumberKind, metric.ValueObserverInstrumentKind, o.AsyncImpl(), -142, ) }) @@ -236,7 +236,7 @@ func TestObserverInstruments(t *testing.T) { result.Observe(42.1, labels...) }) mockSDK.RunAsyncInstruments() - checkObserverBatch(t, labels, mockSDK, metric.Float64NumberKind, metric.SumObserverKind, o.AsyncImpl(), + checkObserverBatch(t, labels, mockSDK, metric.Float64NumberKind, metric.SumObserverInstrumentKind, o.AsyncImpl(), 42.1, ) }) @@ -247,7 +247,7 @@ func TestObserverInstruments(t *testing.T) { result.Observe(-142, labels...) }) mockSDK.RunAsyncInstruments() - checkObserverBatch(t, labels, mockSDK, metric.Int64NumberKind, metric.SumObserverKind, o.AsyncImpl(), + checkObserverBatch(t, labels, mockSDK, metric.Int64NumberKind, metric.SumObserverInstrumentKind, o.AsyncImpl(), -142, ) }) @@ -258,7 +258,7 @@ func TestObserverInstruments(t *testing.T) { result.Observe(42.1, labels...) }) mockSDK.RunAsyncInstruments() - checkObserverBatch(t, labels, mockSDK, metric.Float64NumberKind, metric.UpDownSumObserverKind, o.AsyncImpl(), + checkObserverBatch(t, labels, mockSDK, metric.Float64NumberKind, metric.UpDownSumObserverInstrumentKind, o.AsyncImpl(), 42.1, ) }) @@ -269,7 +269,7 @@ func TestObserverInstruments(t *testing.T) { result.Observe(-142, labels...) }) mockSDK.RunAsyncInstruments() - checkObserverBatch(t, labels, mockSDK, metric.Int64NumberKind, metric.UpDownSumObserverKind, o.AsyncImpl(), + checkObserverBatch(t, labels, mockSDK, metric.Int64NumberKind, metric.UpDownSumObserverInstrumentKind, o.AsyncImpl(), -142, ) }) @@ -320,7 +320,7 @@ func TestBatchObserverInstruments(t *testing.T) { require.Equal(t, 0, m2.Number.CompareNumber(metric.Float64NumberKind, mockTest.ResolveNumberByKind(t, metric.Float64NumberKind, 42))) } -func checkObserverBatch(t *testing.T, labels []label.KeyValue, mock *mockTest.MeterImpl, nkind metric.NumberKind, mkind metric.Kind, observer metric.AsyncImpl, expected float64) { +func checkObserverBatch(t *testing.T, labels []label.KeyValue, mock *mockTest.MeterImpl, nkind metric.NumberKind, mkind metric.InstrumentKind, observer metric.AsyncImpl, expected float64) { t.Helper() assert.Len(t, mock.MeasurementBatches, 1) if len(mock.MeasurementBatches) < 1 { @@ -337,7 +337,7 @@ func checkObserverBatch(t *testing.T, labels []label.KeyValue, mock *mockTest.Me return } measurement := got.Measurements[0] - require.Equal(t, mkind, measurement.Instrument.Descriptor().MetricKind()) + require.Equal(t, mkind, measurement.Instrument.Descriptor().InstrumentKind()) assert.Equal(t, o, measurement.Instrument.Implementation().(*mockTest.Async)) ft := mockTest.ResolveNumberByKind(t, nkind, expected) assert.Equal(t, 0, measurement.Number.CompareNumber(nkind, ft)) diff --git a/api/metric/descriptor.go b/api/metric/descriptor.go index 3af55e5c6..2066b17af 100644 --- a/api/metric/descriptor.go +++ b/api/metric/descriptor.go @@ -20,19 +20,19 @@ import "go.opentelemetry.io/otel/unit" // including its name, metric kind, number kind, and the configurable // options. type Descriptor struct { - name string - kind Kind - numberKind NumberKind - config InstrumentConfig + name string + instrumentKind InstrumentKind + numberKind NumberKind + config InstrumentConfig } // NewDescriptor returns a Descriptor with the given contents. -func NewDescriptor(name string, mkind Kind, nkind NumberKind, opts ...InstrumentOption) Descriptor { +func NewDescriptor(name string, ikind InstrumentKind, nkind NumberKind, opts ...InstrumentOption) Descriptor { return Descriptor{ - name: name, - kind: mkind, - numberKind: nkind, - config: NewInstrumentConfig(opts...), + name: name, + instrumentKind: ikind, + numberKind: nkind, + config: NewInstrumentConfig(opts...), } } @@ -41,9 +41,9 @@ func (d Descriptor) Name() string { return d.name } -// MetricKind returns the specific kind of instrument. -func (d Descriptor) MetricKind() Kind { - return d.kind +// InstrumentKind returns the specific kind of instrument. +func (d Descriptor) InstrumentKind() InstrumentKind { + return d.instrumentKind } // Description provides a human-readable description of the metric diff --git a/api/metric/instrumentkind.go b/api/metric/instrumentkind.go new file mode 100644 index 000000000..7bec8fdd5 --- /dev/null +++ b/api/metric/instrumentkind.go @@ -0,0 +1,80 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:generate stringer -type=InstrumentKind + +package metric + +// InstrumentKind describes the kind of instrument. +type InstrumentKind int8 + +const ( + // ValueRecorderInstrumentKind indicates a ValueRecorder instrument. + ValueRecorderInstrumentKind InstrumentKind = iota + // ValueObserverInstrumentKind indicates an ValueObserver instrument. + ValueObserverInstrumentKind + + // CounterInstrumentKind indicates a Counter instrument. + CounterInstrumentKind + // UpDownCounterInstrumentKind indicates a UpDownCounter instrument. + UpDownCounterInstrumentKind + + // SumObserverInstrumentKind indicates a SumObserver instrument. + SumObserverInstrumentKind + // UpDownSumObserverInstrumentKind indicates a UpDownSumObserver + // instrument. + UpDownSumObserverInstrumentKind +) + +// Synchronous returns whether this is a synchronous kind of instrument. +func (k InstrumentKind) Synchronous() bool { + switch k { + case CounterInstrumentKind, UpDownCounterInstrumentKind, ValueRecorderInstrumentKind: + return true + } + return false +} + +// Asynchronous returns whether this is an asynchronous kind of instrument. +func (k InstrumentKind) Asynchronous() bool { + return !k.Synchronous() +} + +// Adding returns whether this kind of instrument adds its inputs (as opposed to Grouping). +func (k InstrumentKind) Adding() bool { + switch k { + case CounterInstrumentKind, UpDownCounterInstrumentKind, SumObserverInstrumentKind, UpDownSumObserverInstrumentKind: + return true + } + return false +} + +// Grouping returns whether this kind of instrument groups its inputs (as opposed to Adding). +func (k InstrumentKind) Grouping() bool { + return !k.Adding() +} + +// Monotonic returns whether this kind of instrument exposes a non-decreasing sum. +func (k InstrumentKind) Monotonic() bool { + switch k { + case CounterInstrumentKind, SumObserverInstrumentKind: + return true + } + return false +} + +// PrecomputedSum returns whether this kind of instrument receives precomputed sums. +func (k InstrumentKind) PrecomputedSum() bool { + return k.Adding() && k.Asynchronous() +} diff --git a/api/metric/instrumentkind_string.go b/api/metric/instrumentkind_string.go new file mode 100644 index 000000000..2805e2250 --- /dev/null +++ b/api/metric/instrumentkind_string.go @@ -0,0 +1,28 @@ +// Code generated by "stringer -type=InstrumentKind"; DO NOT EDIT. + +package 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[ValueRecorderInstrumentKind-0] + _ = x[ValueObserverInstrumentKind-1] + _ = x[CounterInstrumentKind-2] + _ = x[UpDownCounterInstrumentKind-3] + _ = x[SumObserverInstrumentKind-4] + _ = x[UpDownSumObserverInstrumentKind-5] +} + +const _InstrumentKind_name = "ValueRecorderInstrumentKindValueObserverInstrumentKindCounterInstrumentKindUpDownCounterInstrumentKindSumObserverInstrumentKindUpDownSumObserverInstrumentKind" + +var _InstrumentKind_index = [...]uint8{0, 27, 54, 75, 102, 127, 158} + +func (i InstrumentKind) String() string { + if i < 0 || i >= InstrumentKind(len(_InstrumentKind_index)-1) { + return "InstrumentKind(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _InstrumentKind_name[_InstrumentKind_index[i]:_InstrumentKind_index[i+1]] +} diff --git a/api/metric/kind_test.go b/api/metric/instrumentkind_test.go similarity index 56% rename from api/metric/kind_test.go rename to api/metric/instrumentkind_test.go index 09542b464..2700c9201 100644 --- a/api/metric/kind_test.go +++ b/api/metric/instrumentkind_test.go @@ -23,49 +23,49 @@ import ( ) var ( - syncKinds = []metric.Kind{ - metric.ValueRecorderKind, - metric.CounterKind, - metric.UpDownCounterKind, + syncKinds = []metric.InstrumentKind{ + metric.ValueRecorderInstrumentKind, + metric.CounterInstrumentKind, + metric.UpDownCounterInstrumentKind, } - asyncKinds = []metric.Kind{ - metric.ValueObserverKind, - metric.SumObserverKind, - metric.UpDownSumObserverKind, + asyncKinds = []metric.InstrumentKind{ + metric.ValueObserverInstrumentKind, + metric.SumObserverInstrumentKind, + metric.UpDownSumObserverInstrumentKind, } - addingKinds = []metric.Kind{ - metric.CounterKind, - metric.UpDownCounterKind, - metric.SumObserverKind, - metric.UpDownSumObserverKind, + addingKinds = []metric.InstrumentKind{ + metric.CounterInstrumentKind, + metric.UpDownCounterInstrumentKind, + metric.SumObserverInstrumentKind, + metric.UpDownSumObserverInstrumentKind, } - groupingKinds = []metric.Kind{ - metric.ValueRecorderKind, - metric.ValueObserverKind, + groupingKinds = []metric.InstrumentKind{ + metric.ValueRecorderInstrumentKind, + metric.ValueObserverInstrumentKind, } - monotonicKinds = []metric.Kind{ - metric.CounterKind, - metric.SumObserverKind, + monotonicKinds = []metric.InstrumentKind{ + metric.CounterInstrumentKind, + metric.SumObserverInstrumentKind, } - nonMonotonicKinds = []metric.Kind{ - metric.UpDownCounterKind, - metric.UpDownSumObserverKind, - metric.ValueRecorderKind, - metric.ValueObserverKind, + nonMonotonicKinds = []metric.InstrumentKind{ + metric.UpDownCounterInstrumentKind, + metric.UpDownSumObserverInstrumentKind, + metric.ValueRecorderInstrumentKind, + metric.ValueObserverInstrumentKind, } - precomputedSumKinds = []metric.Kind{ - metric.SumObserverKind, - metric.UpDownSumObserverKind, + precomputedSumKinds = []metric.InstrumentKind{ + metric.SumObserverInstrumentKind, + metric.UpDownSumObserverInstrumentKind, } - nonPrecomputedSumKinds = []metric.Kind{ - metric.CounterKind, - metric.UpDownCounterKind, - metric.ValueRecorderKind, - metric.ValueObserverKind, + nonPrecomputedSumKinds = []metric.InstrumentKind{ + metric.CounterInstrumentKind, + metric.UpDownCounterInstrumentKind, + metric.ValueRecorderInstrumentKind, + metric.ValueObserverInstrumentKind, } ) diff --git a/api/metric/kind.go b/api/metric/kind.go deleted file mode 100644 index 9d4b453f3..000000000 --- a/api/metric/kind.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:generate stringer -type=Kind - -package metric - -// Kind describes the kind of instrument. -type Kind int8 - -const ( - // ValueRecorderKind indicates a ValueRecorder instrument. - ValueRecorderKind Kind = iota - // ValueObserverKind indicates an ValueObserver instrument. - ValueObserverKind - - // CounterKind indicates a Counter instrument. - CounterKind - // UpDownCounterKind indicates a UpDownCounter instrument. - UpDownCounterKind - - // SumObserverKind indicates a SumObserver instrument. - SumObserverKind - // UpDownSumObserverKind indicates a UpDownSumObserver instrument. - UpDownSumObserverKind -) - -// Synchronous returns whether this is a synchronous kind of instrument. -func (k Kind) Synchronous() bool { - switch k { - case CounterKind, UpDownCounterKind, ValueRecorderKind: - return true - } - return false -} - -// Asynchronous returns whether this is an asynchronous kind of instrument. -func (k Kind) Asynchronous() bool { - return !k.Synchronous() -} - -// Adding returns whether this kind of instrument adds its inputs (as opposed to Grouping). -func (k Kind) Adding() bool { - switch k { - case CounterKind, UpDownCounterKind, SumObserverKind, UpDownSumObserverKind: - return true - } - return false -} - -// Adding returns whether this kind of instrument groups its inputs (as opposed to Adding). -func (k Kind) Grouping() bool { - return !k.Adding() -} - -// Monotonic returns whether this kind of instrument exposes a non-decreasing sum. -func (k Kind) Monotonic() bool { - switch k { - case CounterKind, SumObserverKind: - return true - } - return false -} - -// Cumulative returns whether this kind of instrument receives precomputed sums. -func (k Kind) PrecomputedSum() bool { - return k.Adding() && k.Asynchronous() -} diff --git a/api/metric/kind_string.go b/api/metric/kind_string.go deleted file mode 100644 index eb1a0d503..000000000 --- a/api/metric/kind_string.go +++ /dev/null @@ -1,28 +0,0 @@ -// Code generated by "stringer -type=Kind"; DO NOT EDIT. - -package 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[ValueRecorderKind-0] - _ = x[ValueObserverKind-1] - _ = x[CounterKind-2] - _ = x[UpDownCounterKind-3] - _ = x[SumObserverKind-4] - _ = x[UpDownSumObserverKind-5] -} - -const _Kind_name = "ValueRecorderKindValueObserverKindCounterKindUpDownCounterKindSumObserverKindUpDownSumObserverKind" - -var _Kind_index = [...]uint8{0, 17, 34, 45, 62, 77, 98} - -func (i Kind) String() string { - if i < 0 || i >= Kind(len(_Kind_index)-1) { - return "Kind(" + strconv.FormatInt(int64(i), 10) + ")" - } - return _Kind_name[_Kind_index[i]:_Kind_index[i+1]] -} diff --git a/api/metric/meter.go b/api/metric/meter.go index d1749136f..7cff2732b 100644 --- a/api/metric/meter.go +++ b/api/metric/meter.go @@ -74,7 +74,7 @@ func (m Meter) NewBatchObserver(callback BatchObserverFunc) BatchObserver { // duplicate registration). func (m Meter) NewInt64Counter(name string, options ...InstrumentOption) (Int64Counter, error) { return wrapInt64CounterInstrument( - m.newSync(name, CounterKind, Int64NumberKind, options)) + m.newSync(name, CounterInstrumentKind, Int64NumberKind, options)) } // NewFloat64Counter creates a new floating point Counter with the @@ -83,7 +83,7 @@ func (m Meter) NewInt64Counter(name string, options ...InstrumentOption) (Int64C // duplicate registration). func (m Meter) NewFloat64Counter(name string, options ...InstrumentOption) (Float64Counter, error) { return wrapFloat64CounterInstrument( - m.newSync(name, CounterKind, Float64NumberKind, options)) + m.newSync(name, CounterInstrumentKind, Float64NumberKind, options)) } // NewInt64UpDownCounter creates a new integer UpDownCounter instrument with the @@ -92,7 +92,7 @@ func (m Meter) NewFloat64Counter(name string, options ...InstrumentOption) (Floa // duplicate registration). func (m Meter) NewInt64UpDownCounter(name string, options ...InstrumentOption) (Int64UpDownCounter, error) { return wrapInt64UpDownCounterInstrument( - m.newSync(name, UpDownCounterKind, Int64NumberKind, options)) + m.newSync(name, UpDownCounterInstrumentKind, Int64NumberKind, options)) } // NewFloat64UpDownCounter creates a new floating point UpDownCounter with the @@ -101,7 +101,7 @@ func (m Meter) NewInt64UpDownCounter(name string, options ...InstrumentOption) ( // duplicate registration). func (m Meter) NewFloat64UpDownCounter(name string, options ...InstrumentOption) (Float64UpDownCounter, error) { return wrapFloat64UpDownCounterInstrument( - m.newSync(name, UpDownCounterKind, Float64NumberKind, options)) + m.newSync(name, UpDownCounterInstrumentKind, Float64NumberKind, options)) } // NewInt64ValueRecorder creates a new integer ValueRecorder instrument with the @@ -110,7 +110,7 @@ func (m Meter) NewFloat64UpDownCounter(name string, options ...InstrumentOption) // duplicate registration). func (m Meter) NewInt64ValueRecorder(name string, opts ...InstrumentOption) (Int64ValueRecorder, error) { return wrapInt64ValueRecorderInstrument( - m.newSync(name, ValueRecorderKind, Int64NumberKind, opts)) + m.newSync(name, ValueRecorderInstrumentKind, Int64NumberKind, opts)) } // NewFloat64ValueRecorder creates a new floating point ValueRecorder with the @@ -119,7 +119,7 @@ func (m Meter) NewInt64ValueRecorder(name string, opts ...InstrumentOption) (Int // duplicate registration). func (m Meter) NewFloat64ValueRecorder(name string, opts ...InstrumentOption) (Float64ValueRecorder, error) { return wrapFloat64ValueRecorderInstrument( - m.newSync(name, ValueRecorderKind, Float64NumberKind, opts)) + m.newSync(name, ValueRecorderInstrumentKind, Float64NumberKind, opts)) } // NewInt64ValueObserver creates a new integer ValueObserver instrument @@ -131,7 +131,7 @@ func (m Meter) NewInt64ValueObserver(name string, callback Int64ObserverFunc, op return wrapInt64ValueObserverInstrument(NoopAsync{}, nil) } return wrapInt64ValueObserverInstrument( - m.newAsync(name, ValueObserverKind, Int64NumberKind, opts, + m.newAsync(name, ValueObserverInstrumentKind, Int64NumberKind, opts, newInt64AsyncRunner(callback))) } @@ -144,7 +144,7 @@ func (m Meter) NewFloat64ValueObserver(name string, callback Float64ObserverFunc return wrapFloat64ValueObserverInstrument(NoopAsync{}, nil) } return wrapFloat64ValueObserverInstrument( - m.newAsync(name, ValueObserverKind, Float64NumberKind, opts, + m.newAsync(name, ValueObserverInstrumentKind, Float64NumberKind, opts, newFloat64AsyncRunner(callback))) } @@ -157,7 +157,7 @@ func (m Meter) NewInt64SumObserver(name string, callback Int64ObserverFunc, opts return wrapInt64SumObserverInstrument(NoopAsync{}, nil) } return wrapInt64SumObserverInstrument( - m.newAsync(name, SumObserverKind, Int64NumberKind, opts, + m.newAsync(name, SumObserverInstrumentKind, Int64NumberKind, opts, newInt64AsyncRunner(callback))) } @@ -170,7 +170,7 @@ func (m Meter) NewFloat64SumObserver(name string, callback Float64ObserverFunc, return wrapFloat64SumObserverInstrument(NoopAsync{}, nil) } return wrapFloat64SumObserverInstrument( - m.newAsync(name, SumObserverKind, Float64NumberKind, opts, + m.newAsync(name, SumObserverInstrumentKind, Float64NumberKind, opts, newFloat64AsyncRunner(callback))) } @@ -183,7 +183,7 @@ func (m Meter) NewInt64UpDownSumObserver(name string, callback Int64ObserverFunc return wrapInt64UpDownSumObserverInstrument(NoopAsync{}, nil) } return wrapInt64UpDownSumObserverInstrument( - m.newAsync(name, UpDownSumObserverKind, Int64NumberKind, opts, + m.newAsync(name, UpDownSumObserverInstrumentKind, Int64NumberKind, opts, newInt64AsyncRunner(callback))) } @@ -196,7 +196,7 @@ func (m Meter) NewFloat64UpDownSumObserver(name string, callback Float64Observer return wrapFloat64UpDownSumObserverInstrument(NoopAsync{}, nil) } return wrapFloat64UpDownSumObserverInstrument( - m.newAsync(name, UpDownSumObserverKind, Float64NumberKind, opts, + m.newAsync(name, UpDownSumObserverInstrumentKind, Float64NumberKind, opts, newFloat64AsyncRunner(callback))) } @@ -209,7 +209,7 @@ func (b BatchObserver) NewInt64ValueObserver(name string, opts ...InstrumentOpti return wrapInt64ValueObserverInstrument(NoopAsync{}, nil) } return wrapInt64ValueObserverInstrument( - b.meter.newAsync(name, ValueObserverKind, Int64NumberKind, opts, b.runner)) + b.meter.newAsync(name, ValueObserverInstrumentKind, Int64NumberKind, opts, b.runner)) } // NewFloat64ValueObserver creates a new floating point ValueObserver with @@ -221,7 +221,7 @@ func (b BatchObserver) NewFloat64ValueObserver(name string, opts ...InstrumentOp return wrapFloat64ValueObserverInstrument(NoopAsync{}, nil) } return wrapFloat64ValueObserverInstrument( - b.meter.newAsync(name, ValueObserverKind, Float64NumberKind, opts, + b.meter.newAsync(name, ValueObserverInstrumentKind, Float64NumberKind, opts, b.runner)) } @@ -234,7 +234,7 @@ func (b BatchObserver) NewInt64SumObserver(name string, opts ...InstrumentOption return wrapInt64SumObserverInstrument(NoopAsync{}, nil) } return wrapInt64SumObserverInstrument( - b.meter.newAsync(name, SumObserverKind, Int64NumberKind, opts, b.runner)) + b.meter.newAsync(name, SumObserverInstrumentKind, Int64NumberKind, opts, b.runner)) } // NewFloat64SumObserver creates a new floating point SumObserver with @@ -246,7 +246,7 @@ func (b BatchObserver) NewFloat64SumObserver(name string, opts ...InstrumentOpti return wrapFloat64SumObserverInstrument(NoopAsync{}, nil) } return wrapFloat64SumObserverInstrument( - b.meter.newAsync(name, SumObserverKind, Float64NumberKind, opts, + b.meter.newAsync(name, SumObserverInstrumentKind, Float64NumberKind, opts, b.runner)) } @@ -259,7 +259,7 @@ func (b BatchObserver) NewInt64UpDownSumObserver(name string, opts ...Instrument return wrapInt64UpDownSumObserverInstrument(NoopAsync{}, nil) } return wrapInt64UpDownSumObserverInstrument( - b.meter.newAsync(name, UpDownSumObserverKind, Int64NumberKind, opts, b.runner)) + b.meter.newAsync(name, UpDownSumObserverInstrumentKind, Int64NumberKind, opts, b.runner)) } // NewFloat64UpDownSumObserver creates a new floating point UpDownSumObserver with @@ -271,7 +271,7 @@ func (b BatchObserver) NewFloat64UpDownSumObserver(name string, opts ...Instrume return wrapFloat64UpDownSumObserverInstrument(NoopAsync{}, nil) } return wrapFloat64UpDownSumObserverInstrument( - b.meter.newAsync(name, UpDownSumObserverKind, Float64NumberKind, opts, + b.meter.newAsync(name, UpDownSumObserverInstrumentKind, Float64NumberKind, opts, b.runner)) } @@ -283,7 +283,7 @@ func (m Meter) MeterImpl() MeterImpl { // newAsync constructs one new asynchronous instrument. func (m Meter) newAsync( name string, - mkind Kind, + mkind InstrumentKind, nkind NumberKind, opts []InstrumentOption, runner AsyncRunner, @@ -303,7 +303,7 @@ func (m Meter) newAsync( // newSync constructs one new synchronous instrument. func (m Meter) newSync( name string, - metricKind Kind, + metricKind InstrumentKind, numberKind NumberKind, opts []InstrumentOption, ) ( diff --git a/api/metric/registry/registry.go b/api/metric/registry/registry.go index ed9eccca3..fbbc7280e 100644 --- a/api/metric/registry/registry.go +++ b/api/metric/registry/registry.go @@ -95,14 +95,14 @@ func NewMetricKindMismatchError(desc metric.Descriptor) error { desc.InstrumentationName(), desc.InstrumentationVersion(), desc.NumberKind(), - desc.MetricKind(), + desc.InstrumentKind(), ErrMetricKindMismatch) } // Compatible determines whether two metric.Descriptors are considered // the same for the purpose of uniqueness checking. func Compatible(candidate, existing metric.Descriptor) bool { - return candidate.MetricKind() == existing.MetricKind() && + return candidate.InstrumentKind() == existing.InstrumentKind() && candidate.NumberKind() == existing.NumberKind() } diff --git a/exporters/otlp/internal/transform/metric_test.go b/exporters/otlp/internal/transform/metric_test.go index 4c8efb3a9..4f06a2932 100644 --- a/exporters/otlp/internal/transform/metric_test.go +++ b/exporters/otlp/internal/transform/metric_test.go @@ -117,7 +117,7 @@ func TestMinMaxSumCountValue(t *testing.T) { } func TestMinMaxSumCountDatapoints(t *testing.T) { - desc := metric.NewDescriptor("", metric.ValueRecorderKind, metric.Int64NumberKind) + desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, metric.Int64NumberKind) labels := label.NewSet() mmsc, ckpt := metrictest.Unslice2(minmaxsumcount.New(2, &desc)) @@ -156,7 +156,7 @@ func TestMinMaxSumCountPropagatesErrors(t *testing.T) { } func TestSumIntDataPoints(t *testing.T) { - desc := metric.NewDescriptor("", metric.ValueRecorderKind, metric.Int64NumberKind) + desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, metric.Int64NumberKind) labels := label.NewSet() s, ckpt := metrictest.Unslice2(sumAgg.New(2)) assert.NoError(t, s.Update(context.Background(), metric.Number(1), &desc)) @@ -181,7 +181,7 @@ func TestSumIntDataPoints(t *testing.T) { } func TestSumFloatDataPoints(t *testing.T) { - desc := metric.NewDescriptor("", metric.ValueRecorderKind, metric.Float64NumberKind) + desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, metric.Float64NumberKind) labels := label.NewSet() s, ckpt := metrictest.Unslice2(sumAgg.New(2)) assert.NoError(t, s.Update(context.Background(), metric.NewFloat64Number(1), &desc)) @@ -207,7 +207,7 @@ func TestSumFloatDataPoints(t *testing.T) { } func TestLastValueIntDataPoints(t *testing.T) { - desc := metric.NewDescriptor("", metric.ValueRecorderKind, metric.Int64NumberKind) + desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, metric.Int64NumberKind) labels := label.NewSet() s, ckpt := metrictest.Unslice2(lvAgg.New(2)) assert.NoError(t, s.Update(context.Background(), metric.Number(100), &desc)) @@ -233,7 +233,7 @@ func TestLastValueIntDataPoints(t *testing.T) { } func TestSumErrUnknownValueType(t *testing.T) { - desc := metric.NewDescriptor("", metric.ValueRecorderKind, metric.NumberKind(-1)) + desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, metric.NumberKind(-1)) labels := label.NewSet() s := &sumAgg.New(1)[0] record := export.NewRecord(&desc, &labels, nil, s, intervalStart, intervalEnd) @@ -318,7 +318,7 @@ var _ aggregation.MinMaxSumCount = &testErrMinMaxSumCount{} func TestRecordAggregatorIncompatibleErrors(t *testing.T) { makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) { - desc := metric.NewDescriptor("things", metric.CounterKind, metric.Int64NumberKind) + desc := metric.NewDescriptor("things", metric.CounterInstrumentKind, metric.Int64NumberKind) labels := label.NewSet() res := resource.New() test := &testAgg{ @@ -355,7 +355,7 @@ func TestRecordAggregatorIncompatibleErrors(t *testing.T) { func TestRecordAggregatorUnexpectedErrors(t *testing.T) { makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) { - desc := metric.NewDescriptor("things", metric.CounterKind, metric.Int64NumberKind) + desc := metric.NewDescriptor("things", metric.CounterInstrumentKind, metric.Int64NumberKind) labels := label.NewSet() res := resource.New() return Record(export.NewRecord(&desc, &labels, res, agg, intervalStart, intervalEnd)) diff --git a/exporters/otlp/otlp_integration_test.go b/exporters/otlp/otlp_integration_test.go index 423c1e2e8..dfb62528a 100644 --- a/exporters/otlp/otlp_integration_test.go +++ b/exporters/otlp/otlp_integration_test.go @@ -130,22 +130,22 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption) labels := []label.KeyValue{label.Bool("test", true)} type data struct { - iKind metric.Kind + iKind metric.InstrumentKind nKind metricapi.NumberKind val int64 } instruments := map[string]data{ - "test-int64-counter": {metric.CounterKind, metricapi.Int64NumberKind, 1}, - "test-float64-counter": {metric.CounterKind, metricapi.Float64NumberKind, 1}, - "test-int64-valuerecorder": {metric.ValueRecorderKind, metricapi.Int64NumberKind, 2}, - "test-float64-valuerecorder": {metric.ValueRecorderKind, metricapi.Float64NumberKind, 2}, - "test-int64-valueobserver": {metric.ValueObserverKind, metricapi.Int64NumberKind, 3}, - "test-float64-valueobserver": {metric.ValueObserverKind, metricapi.Float64NumberKind, 3}, + "test-int64-counter": {metric.CounterInstrumentKind, metricapi.Int64NumberKind, 1}, + "test-float64-counter": {metric.CounterInstrumentKind, metricapi.Float64NumberKind, 1}, + "test-int64-valuerecorder": {metric.ValueRecorderInstrumentKind, metricapi.Int64NumberKind, 2}, + "test-float64-valuerecorder": {metric.ValueRecorderInstrumentKind, metricapi.Float64NumberKind, 2}, + "test-int64-valueobserver": {metric.ValueObserverInstrumentKind, metricapi.Int64NumberKind, 3}, + "test-float64-valueobserver": {metric.ValueObserverInstrumentKind, metricapi.Float64NumberKind, 3}, } for name, data := range instruments { data := data switch data.iKind { - case metric.CounterKind: + case metric.CounterInstrumentKind: switch data.nKind { case metricapi.Int64NumberKind: metricapi.Must(meter).NewInt64Counter(name).Add(ctx, data.val, labels...) @@ -154,7 +154,7 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption) default: assert.Failf(t, "unsupported number testing kind", data.nKind.String()) } - case metric.ValueRecorderKind: + case metric.ValueRecorderInstrumentKind: switch data.nKind { case metricapi.Int64NumberKind: metricapi.Must(meter).NewInt64ValueRecorder(name).Record(ctx, data.val, labels...) @@ -163,7 +163,7 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption) default: assert.Failf(t, "unsupported number testing kind", data.nKind.String()) } - case metric.ValueObserverKind: + case metric.ValueObserverInstrumentKind: switch data.nKind { case metricapi.Int64NumberKind: metricapi.Must(meter).NewInt64ValueObserver(name, @@ -245,7 +245,7 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption) seen[m.Name] = struct{}{} switch data.iKind { - case metric.CounterKind: + case metric.CounterInstrumentKind: switch data.nKind { case metricapi.Int64NumberKind: if dp := m.GetIntSum().DataPoints; assert.Len(t, dp, 1) { @@ -258,7 +258,7 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption) default: assert.Failf(t, "invalid number kind", data.nKind.String()) } - case metric.ValueObserverKind: + case metric.ValueObserverInstrumentKind: switch data.nKind { case metricapi.Int64NumberKind: if dp := m.GetIntGauge().DataPoints; assert.Len(t, dp, 1) { @@ -271,7 +271,7 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption) default: assert.Failf(t, "invalid number kind", data.nKind.String()) } - case metric.ValueRecorderKind: + case metric.ValueRecorderInstrumentKind: switch data.nKind { case metricapi.Int64NumberKind: assert.NotNil(t, m.GetIntHistogram()) diff --git a/exporters/otlp/otlp_metric_test.go b/exporters/otlp/otlp_metric_test.go index 7ee044385..c5d61cf2e 100644 --- a/exporters/otlp/otlp_metric_test.go +++ b/exporters/otlp/otlp_metric_test.go @@ -93,7 +93,7 @@ func (m *checkpointSet) ForEach(_ metricsdk.ExportKindSelector, fn func(metricsd type record struct { name string - mKind metric.Kind + iKind metric.InstrumentKind nKind metric.NumberKind resource *resource.Resource opts []metric.InstrumentOption @@ -162,7 +162,7 @@ func TestNoGroupingExport(t *testing.T) { []record{ { "int64-count", - metric.CounterKind, + metric.CounterInstrumentKind, metric.Int64NumberKind, nil, nil, @@ -170,7 +170,7 @@ func TestNoGroupingExport(t *testing.T) { }, { "int64-count", - metric.CounterKind, + metric.CounterInstrumentKind, metric.Int64NumberKind, nil, nil, @@ -217,7 +217,7 @@ func TestNoGroupingExport(t *testing.T) { func TestValuerecorderMetricGroupingExport(t *testing.T) { r := record{ "valuerecorder", - metric.ValueRecorderKind, + metric.ValueRecorderInstrumentKind, metric.Int64NumberKind, nil, nil, @@ -286,7 +286,7 @@ func TestValuerecorderMetricGroupingExport(t *testing.T) { func TestCountInt64MetricGroupingExport(t *testing.T) { r := record{ "int64-count", - metric.CounterKind, + metric.CounterInstrumentKind, metric.Int64NumberKind, nil, nil, @@ -335,7 +335,7 @@ func TestCountInt64MetricGroupingExport(t *testing.T) { func TestCountFloat64MetricGroupingExport(t *testing.T) { r := record{ "float64-count", - metric.CounterKind, + metric.CounterInstrumentKind, metric.Float64NumberKind, nil, nil, @@ -405,7 +405,7 @@ func TestResourceMetricGroupingExport(t *testing.T) { []record{ { "int64-count", - metric.CounterKind, + metric.CounterInstrumentKind, metric.Int64NumberKind, testInstA, nil, @@ -413,7 +413,7 @@ func TestResourceMetricGroupingExport(t *testing.T) { }, { "int64-count", - metric.CounterKind, + metric.CounterInstrumentKind, metric.Int64NumberKind, testInstA, nil, @@ -421,7 +421,7 @@ func TestResourceMetricGroupingExport(t *testing.T) { }, { "int64-count", - metric.CounterKind, + metric.CounterInstrumentKind, metric.Int64NumberKind, testInstA, nil, @@ -429,7 +429,7 @@ func TestResourceMetricGroupingExport(t *testing.T) { }, { "int64-count", - metric.CounterKind, + metric.CounterInstrumentKind, metric.Int64NumberKind, testInstB, nil, @@ -522,7 +522,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { []record{ { "int64-count", - metric.CounterKind, + metric.CounterInstrumentKind, metric.Int64NumberKind, testInstA, countingLib1, @@ -530,7 +530,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { }, { "int64-count", - metric.CounterKind, + metric.CounterInstrumentKind, metric.Int64NumberKind, testInstA, countingLib2, @@ -538,7 +538,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { }, { "int64-count", - metric.CounterKind, + metric.CounterInstrumentKind, metric.Int64NumberKind, testInstA, countingLib1, @@ -546,7 +546,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { }, { "int64-count", - metric.CounterKind, + metric.CounterInstrumentKind, metric.Int64NumberKind, testInstA, countingLib1, @@ -554,7 +554,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { }, { "int64-count", - metric.CounterKind, + metric.CounterInstrumentKind, metric.Int64NumberKind, testInstA, summingLib, @@ -562,7 +562,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) { }, { "int64-count", - metric.CounterKind, + metric.CounterInstrumentKind, metric.Int64NumberKind, testInstB, countingLib1, @@ -713,12 +713,12 @@ func runMetricExportTest(t *testing.T, exp *Exporter, rs []record, expected []me recs := map[label.Distinct][]metricsdk.Record{} resources := map[label.Distinct]*resource.Resource{} for _, r := range rs { - desc := metric.NewDescriptor(r.name, r.mKind, r.nKind, r.opts...) + desc := metric.NewDescriptor(r.name, r.iKind, r.nKind, r.opts...) labs := label.NewSet(r.labels...) var agg, ckpt metricsdk.Aggregator - switch r.mKind { - case metric.CounterKind: + switch r.iKind { + case metric.CounterInstrumentKind: agg, ckpt = metrictest.Unslice2(sum.New(2)) default: agg, ckpt = metrictest.Unslice2(histogram.New(2, &desc, testHistogramBoundaries)) diff --git a/exporters/stdout/metric_test.go b/exporters/stdout/metric_test.go index 1a6e11000..f8d21aa37 100644 --- a/exporters/stdout/metric_test.go +++ b/exporters/stdout/metric_test.go @@ -99,7 +99,7 @@ func TestStdoutTimestamp(t *testing.T) { checkpointSet := metrictest.NewCheckpointSet(testResource) ctx := context.Background() - desc := metric.NewDescriptor("test.name", metric.ValueObserverKind, metric.Int64NumberKind) + desc := metric.NewDescriptor("test.name", metric.ValueObserverInstrumentKind, metric.Int64NumberKind) lvagg, ckpt := metrictest.Unslice2(lastvalue.New(2)) @@ -138,7 +138,7 @@ func TestStdoutCounterFormat(t *testing.T) { checkpointSet := metrictest.NewCheckpointSet(testResource) - desc := metric.NewDescriptor("test.name", metric.CounterKind, metric.Int64NumberKind) + desc := metric.NewDescriptor("test.name", metric.CounterInstrumentKind, metric.Int64NumberKind) cagg, ckpt := metrictest.Unslice2(sum.New(2)) @@ -157,7 +157,7 @@ func TestStdoutLastValueFormat(t *testing.T) { checkpointSet := metrictest.NewCheckpointSet(testResource) - desc := metric.NewDescriptor("test.name", metric.ValueObserverKind, metric.Float64NumberKind) + desc := metric.NewDescriptor("test.name", metric.ValueObserverInstrumentKind, metric.Float64NumberKind) lvagg, ckpt := metrictest.Unslice2(lastvalue.New(2)) aggregatortest.CheckedUpdate(fix.t, lvagg, metric.NewFloat64Number(123.456), &desc) @@ -175,7 +175,7 @@ func TestStdoutMinMaxSumCount(t *testing.T) { checkpointSet := metrictest.NewCheckpointSet(testResource) - desc := metric.NewDescriptor("test.name", metric.ValueRecorderKind, metric.Float64NumberKind) + desc := metric.NewDescriptor("test.name", metric.ValueRecorderInstrumentKind, metric.Float64NumberKind) magg, ckpt := metrictest.Unslice2(minmaxsumcount.New(2, &desc)) @@ -195,7 +195,7 @@ func TestStdoutValueRecorderFormat(t *testing.T) { checkpointSet := metrictest.NewCheckpointSet(testResource) - desc := metric.NewDescriptor("test.name", metric.ValueRecorderKind, metric.Float64NumberKind) + desc := metric.NewDescriptor("test.name", metric.ValueRecorderInstrumentKind, metric.Float64NumberKind) aagg, ckpt := metrictest.Unslice2(array.New(2)) for i := 0; i < 1000; i++ { @@ -234,7 +234,7 @@ func TestStdoutValueRecorderFormat(t *testing.T) { } func TestStdoutNoData(t *testing.T) { - desc := metric.NewDescriptor("test.name", metric.ValueRecorderKind, metric.Float64NumberKind) + desc := metric.NewDescriptor("test.name", metric.ValueRecorderInstrumentKind, metric.Float64NumberKind) runTwoAggs := func(agg, ckpt export.Aggregator) { t.Run(fmt.Sprintf("%T", agg), func(t *testing.T) { @@ -263,7 +263,7 @@ func TestStdoutLastValueNotSet(t *testing.T) { checkpointSet := metrictest.NewCheckpointSet(testResource) - desc := metric.NewDescriptor("test.name", metric.ValueObserverKind, metric.Float64NumberKind) + desc := metric.NewDescriptor("test.name", metric.ValueObserverInstrumentKind, metric.Float64NumberKind) lvagg, ckpt := metrictest.Unslice2(lastvalue.New(2)) require.NoError(t, lvagg.SynchronizedMove(ckpt, &desc)) @@ -314,7 +314,7 @@ func TestStdoutResource(t *testing.T) { checkpointSet := metrictest.NewCheckpointSet(tc.res) - desc := metric.NewDescriptor("test.name", metric.ValueObserverKind, metric.Float64NumberKind) + desc := metric.NewDescriptor("test.name", metric.ValueObserverInstrumentKind, metric.Float64NumberKind) lvagg, ckpt := metrictest.Unslice2(lastvalue.New(2)) aggregatortest.CheckedUpdate(fix.t, lvagg, metric.NewFloat64Number(123.456), &desc) diff --git a/sdk/export/metric/exportkind_test.go b/sdk/export/metric/exportkind_test.go index 36b368e82..22f8aacb8 100644 --- a/sdk/export/metric/exportkind_test.go +++ b/sdk/export/metric/exportkind_test.go @@ -37,16 +37,16 @@ func TestExportKindIncludes(t *testing.T) { require.False(t, DeltaExporter.Includes(PassThroughExporter|CumulativeExporter)) } -var deltaMemoryKinds = []metric.Kind{ - metric.SumObserverKind, - metric.UpDownSumObserverKind, +var deltaMemoryKinds = []metric.InstrumentKind{ + metric.SumObserverInstrumentKind, + metric.UpDownSumObserverInstrumentKind, } -var cumulativeMemoryKinds = []metric.Kind{ - metric.ValueRecorderKind, - metric.ValueObserverKind, - metric.CounterKind, - metric.UpDownCounterKind, +var cumulativeMemoryKinds = []metric.InstrumentKind{ + metric.ValueRecorderInstrumentKind, + metric.ValueObserverInstrumentKind, + metric.CounterInstrumentKind, + metric.UpDownCounterInstrumentKind, } func TestExportKindMemoryRequired(t *testing.T) { diff --git a/sdk/export/metric/metric.go b/sdk/export/metric/metric.go index d47283b14..78a026b95 100644 --- a/sdk/export/metric/metric.go +++ b/sdk/export/metric/metric.go @@ -385,14 +385,14 @@ func (kind ExportKind) ExportKindFor(_ *metric.Descriptor, _ aggregation.Kind) E // MemoryRequired returns whether an exporter of this kind requires // memory to export correctly. -func (kind ExportKind) MemoryRequired(mkind metric.Kind) bool { +func (kind ExportKind) MemoryRequired(mkind metric.InstrumentKind) bool { switch mkind { - case metric.ValueRecorderKind, metric.ValueObserverKind, - metric.CounterKind, metric.UpDownCounterKind: + case metric.ValueRecorderInstrumentKind, metric.ValueObserverInstrumentKind, + metric.CounterInstrumentKind, metric.UpDownCounterInstrumentKind: // Delta-oriented instruments: return kind.Includes(CumulativeExporter) - case metric.SumObserverKind, metric.UpDownSumObserverKind: + case metric.SumObserverInstrumentKind, metric.UpDownSumObserverInstrumentKind: // Cumulative-oriented instruments: return kind.Includes(DeltaExporter) } diff --git a/sdk/metric/aggregator/aggregator.go b/sdk/metric/aggregator/aggregator.go index f0d30ba5a..c27b9a6a6 100644 --- a/sdk/metric/aggregator/aggregator.go +++ b/sdk/metric/aggregator/aggregator.go @@ -41,8 +41,8 @@ func RangeTest(number metric.Number, descriptor *metric.Descriptor) error { return aggregation.ErrNaNInput } - switch descriptor.MetricKind() { - case metric.CounterKind, metric.SumObserverKind: + switch descriptor.InstrumentKind() { + case metric.CounterInstrumentKind, metric.SumObserverInstrumentKind: if number.IsNegative(numberKind) { return aggregation.ErrNegativeInput } diff --git a/sdk/metric/aggregator/aggregator_test.go b/sdk/metric/aggregator/aggregator_test.go index 11f43bfc4..cf6f30738 100644 --- a/sdk/metric/aggregator/aggregator_test.go +++ b/sdk/metric/aggregator/aggregator_test.go @@ -74,7 +74,7 @@ func TestRangeTest(t *testing.T) { t.Run(nkind.String(), func(t *testing.T) { desc := metric.NewDescriptor( "name", - metric.CounterKind, + metric.CounterInstrumentKind, nkind, ) testRangeNegative(t, &desc) @@ -85,10 +85,10 @@ func TestRangeTest(t *testing.T) { func TestNaNTest(t *testing.T) { for _, nkind := range []metric.NumberKind{metric.Float64NumberKind, metric.Int64NumberKind} { t.Run(nkind.String(), func(t *testing.T) { - for _, mkind := range []metric.Kind{ - metric.CounterKind, - metric.ValueRecorderKind, - metric.ValueObserverKind, + for _, mkind := range []metric.InstrumentKind{ + metric.CounterInstrumentKind, + metric.ValueRecorderInstrumentKind, + metric.ValueObserverInstrumentKind, } { desc := metric.NewDescriptor( "name", diff --git a/sdk/metric/aggregator/aggregatortest/test.go b/sdk/metric/aggregator/aggregatortest/test.go index 3d3a17b2d..2624515df 100644 --- a/sdk/metric/aggregator/aggregatortest/test.go +++ b/sdk/metric/aggregator/aggregatortest/test.go @@ -53,7 +53,7 @@ func newProfiles() []Profile { } } -func NewAggregatorTest(mkind metric.Kind, nkind metric.NumberKind) *metric.Descriptor { +func NewAggregatorTest(mkind metric.InstrumentKind, nkind metric.NumberKind) *metric.Descriptor { desc := metric.NewDescriptor("test.name", mkind, nkind) return &desc } diff --git a/sdk/metric/aggregator/array/array_test.go b/sdk/metric/aggregator/array/array_test.go index b35d8da3f..6ea143a58 100644 --- a/sdk/metric/aggregator/array/array_test.go +++ b/sdk/metric/aggregator/array/array_test.go @@ -62,7 +62,7 @@ func new4() (_, _, _, _ *Aggregator) { } func (ut *updateTest) run(t *testing.T, profile aggregatortest.Profile) { - descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderKind, profile.NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) agg, ckpt := new2() all := aggregatortest.NewNumbers(profile.NumberKind) @@ -129,7 +129,7 @@ type mergeTest struct { } func (mt *mergeTest) run(t *testing.T, profile aggregatortest.Profile) { - descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderKind, profile.NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) agg1, agg2, ckpt1, ckpt2 := new4() all := aggregatortest.NewNumbers(profile.NumberKind) @@ -225,7 +225,7 @@ func TestArrayErrors(t *testing.T) { require.Error(t, err) require.Equal(t, err, aggregation.ErrNoData) - descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderKind, profile.NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) aggregatortest.CheckedUpdate(t, agg, metric.Number(0), descriptor) @@ -253,7 +253,7 @@ func TestArrayErrors(t *testing.T) { } func TestArrayFloat64(t *testing.T) { - descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderKind, metric.Float64NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, metric.Float64NumberKind) fpsf := func(sign int) []float64 { // Check behavior of a bunch of odd floating diff --git a/sdk/metric/aggregator/ddsketch/ddsketch_test.go b/sdk/metric/aggregator/ddsketch/ddsketch_test.go index 03a9e5add..48696977b 100644 --- a/sdk/metric/aggregator/ddsketch/ddsketch_test.go +++ b/sdk/metric/aggregator/ddsketch/ddsketch_test.go @@ -66,7 +66,7 @@ func checkZero(t *testing.T, agg *Aggregator, desc *metric.Descriptor) { } func (ut *updateTest) run(t *testing.T, profile aggregatortest.Profile) { - descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderKind, profile.NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) agg, ckpt := new2(descriptor) all := aggregatortest.NewNumbers(profile.NumberKind) @@ -127,7 +127,7 @@ type mergeTest struct { } func (mt *mergeTest) run(t *testing.T, profile aggregatortest.Profile) { - descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderKind, profile.NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) agg1, agg2, ckpt1, ckpt2 := new4(descriptor) diff --git a/sdk/metric/aggregator/histogram/benchmark_test.go b/sdk/metric/aggregator/histogram/benchmark_test.go index 3f9bda1e5..c5292924b 100644 --- a/sdk/metric/aggregator/histogram/benchmark_test.go +++ b/sdk/metric/aggregator/histogram/benchmark_test.go @@ -37,7 +37,7 @@ func benchmarkHistogramSearchFloat64(b *testing.B, size int) { for i := range values { values[i] = rand.Float64() * inputRange } - desc := aggregatortest.NewAggregatorTest(metric.ValueRecorderKind, metric.Float64NumberKind) + desc := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, metric.Float64NumberKind) agg := &histogram.New(1, desc, boundaries)[0] ctx := context.Background() @@ -88,7 +88,7 @@ func benchmarkHistogramSearchInt64(b *testing.B, size int) { for i := range values { values[i] = int64(rand.Float64() * inputRange) } - desc := aggregatortest.NewAggregatorTest(metric.ValueRecorderKind, metric.Int64NumberKind) + desc := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, metric.Int64NumberKind) agg := &histogram.New(1, desc, boundaries)[0] ctx := context.Background() diff --git a/sdk/metric/aggregator/histogram/histogram_test.go b/sdk/metric/aggregator/histogram/histogram_test.go index 0ea25ad97..783fadbfa 100644 --- a/sdk/metric/aggregator/histogram/histogram_test.go +++ b/sdk/metric/aggregator/histogram/histogram_test.go @@ -109,7 +109,7 @@ func TestHistogramPositiveAndNegative(t *testing.T) { // Validates count, sum and buckets for a given profile and policy func testHistogram(t *testing.T, profile aggregatortest.Profile, policy policy) { - descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderKind, profile.NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) agg, ckpt := new2(descriptor) @@ -154,7 +154,7 @@ func testHistogram(t *testing.T, profile aggregatortest.Profile, policy policy) func TestHistogramInitial(t *testing.T) { aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { - descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderKind, profile.NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) agg := &histogram.New(1, descriptor, boundaries)[0] buckets, err := agg.Histogram() @@ -167,7 +167,7 @@ func TestHistogramInitial(t *testing.T) { func TestHistogramMerge(t *testing.T) { aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { - descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderKind, profile.NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) agg1, agg2, ckpt1, ckpt2 := new4(descriptor) @@ -219,7 +219,7 @@ func TestHistogramMerge(t *testing.T) { func TestHistogramNotSet(t *testing.T) { aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { - descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderKind, profile.NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) agg, ckpt := new2(descriptor) diff --git a/sdk/metric/aggregator/lastvalue/lastvalue_test.go b/sdk/metric/aggregator/lastvalue/lastvalue_test.go index ebe8054b4..8888e80bd 100644 --- a/sdk/metric/aggregator/lastvalue/lastvalue_test.go +++ b/sdk/metric/aggregator/lastvalue/lastvalue_test.go @@ -71,7 +71,7 @@ func TestLastValueUpdate(t *testing.T) { aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { agg, ckpt := new2() - record := aggregatortest.NewAggregatorTest(metric.ValueObserverKind, profile.NumberKind) + record := aggregatortest.NewAggregatorTest(metric.ValueObserverInstrumentKind, profile.NumberKind) var last metric.Number for i := 0; i < count; i++ { @@ -93,7 +93,7 @@ func TestLastValueMerge(t *testing.T) { aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { agg1, agg2, ckpt1, ckpt2 := new4() - descriptor := aggregatortest.NewAggregatorTest(metric.ValueObserverKind, profile.NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.ValueObserverInstrumentKind, profile.NumberKind) first1 := profile.Random(+1) first2 := profile.Random(+1) @@ -124,7 +124,7 @@ func TestLastValueMerge(t *testing.T) { } func TestLastValueNotSet(t *testing.T) { - descriptor := aggregatortest.NewAggregatorTest(metric.ValueObserverKind, metric.Int64NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.ValueObserverInstrumentKind, metric.Int64NumberKind) g, ckpt := new2() require.NoError(t, g.SynchronizedMove(ckpt, descriptor)) diff --git a/sdk/metric/aggregator/minmaxsumcount/mmsc_test.go b/sdk/metric/aggregator/minmaxsumcount/mmsc_test.go index b27ff7498..6baa8ea60 100644 --- a/sdk/metric/aggregator/minmaxsumcount/mmsc_test.go +++ b/sdk/metric/aggregator/minmaxsumcount/mmsc_test.go @@ -108,7 +108,7 @@ func checkZero(t *testing.T, agg *Aggregator, desc *metric.Descriptor) { // Validates min, max, sum and count for a given profile and policy func minMaxSumCount(t *testing.T, profile aggregatortest.Profile, policy policy) { - descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderKind, profile.NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) agg, ckpt := new2(descriptor) @@ -156,7 +156,7 @@ func minMaxSumCount(t *testing.T, profile aggregatortest.Profile, policy policy) func TestMinMaxSumCountMerge(t *testing.T) { aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { - descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderKind, profile.NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) agg1, agg2, ckpt1, ckpt2 := new4(descriptor) @@ -214,7 +214,7 @@ func TestMinMaxSumCountMerge(t *testing.T) { func TestMaxSumCountNotSet(t *testing.T) { aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { - descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderKind, profile.NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) alloc := New(2, descriptor) agg, ckpt := &alloc[0], &alloc[1] diff --git a/sdk/metric/aggregator/sum/sum_test.go b/sdk/metric/aggregator/sum/sum_test.go index f38f8bd8a..04ae2a13d 100644 --- a/sdk/metric/aggregator/sum/sum_test.go +++ b/sdk/metric/aggregator/sum/sum_test.go @@ -65,7 +65,7 @@ func TestCounterSum(t *testing.T) { aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { agg, ckpt := new2() - descriptor := aggregatortest.NewAggregatorTest(metric.CounterKind, profile.NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.CounterInstrumentKind, profile.NumberKind) sum := metric.Number(0) for i := 0; i < count; i++ { @@ -89,7 +89,7 @@ func TestValueRecorderSum(t *testing.T) { aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { agg, ckpt := new2() - descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderKind, profile.NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) sum := metric.Number(0) @@ -115,7 +115,7 @@ func TestCounterMerge(t *testing.T) { aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { agg1, agg2, ckpt1, ckpt2 := new4() - descriptor := aggregatortest.NewAggregatorTest(metric.CounterKind, profile.NumberKind) + descriptor := aggregatortest.NewAggregatorTest(metric.CounterInstrumentKind, profile.NumberKind) sum := metric.Number(0) for i := 0; i < count; i++ { diff --git a/sdk/metric/histogram_stress_test.go b/sdk/metric/histogram_stress_test.go index 1356e37a3..aff6346fa 100644 --- a/sdk/metric/histogram_stress_test.go +++ b/sdk/metric/histogram_stress_test.go @@ -27,7 +27,7 @@ import ( ) func TestStressInt64Histogram(t *testing.T) { - desc := metric.NewDescriptor("some_metric", metric.ValueRecorderKind, metric.Int64NumberKind) + desc := metric.NewDescriptor("some_metric", metric.ValueRecorderInstrumentKind, metric.Int64NumberKind) alloc := histogram.New(2, &desc, []float64{25, 50, 75}) h, ckpt := &alloc[0], &alloc[1] diff --git a/sdk/metric/minmaxsumcount_stress_test.go b/sdk/metric/minmaxsumcount_stress_test.go index ee8bf6140..203775655 100644 --- a/sdk/metric/minmaxsumcount_stress_test.go +++ b/sdk/metric/minmaxsumcount_stress_test.go @@ -25,7 +25,7 @@ import ( ) func TestStressInt64MinMaxSumCount(t *testing.T) { - desc := metric.NewDescriptor("some_metric", metric.ValueRecorderKind, metric.Int64NumberKind) + desc := metric.NewDescriptor("some_metric", metric.ValueRecorderInstrumentKind, metric.Int64NumberKind) alloc := minmaxsumcount.New(2, &desc) mmsc, ckpt := &alloc[0], &alloc[1] diff --git a/sdk/metric/processor/basic/basic.go b/sdk/metric/processor/basic/basic.go index 6816e3c20..3adde7ce8 100644 --- a/sdk/metric/processor/basic/basic.go +++ b/sdk/metric/processor/basic/basic.go @@ -160,7 +160,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.MetricKind()) + stateful := b.ExportKindFor(desc, agg.Aggregation().Kind()).MemoryRequired(desc.InstrumentKind()) newValue := &stateValue{ labels: accum.Labels(), @@ -170,7 +170,7 @@ func (b *Processor) Process(accum export.Accumulation) error { current: agg, } if stateful { - if desc.MetricKind().PrecomputedSum() { + if desc.InstrumentKind().PrecomputedSum() { // If we know we need to compute deltas, allocate two aggregators. b.AggregatorFor(desc, &newValue.cumulative, &newValue.delta) } else { @@ -207,7 +207,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(MetricKind). + // ExportKind.MemoryRequired(InstrumentKind). // // Case (b) occurs when the variable `sameCollection` is true, // indicating that the stateKey for Accumulation has already @@ -272,7 +272,7 @@ func (b *Processor) FinishCollection() error { defer func() { b.finishedCollection++ }() for key, value := range b.values { - mkind := key.descriptor.MetricKind() + mkind := key.descriptor.InstrumentKind() stale := value.updated != b.finishedCollection stateless := !value.stateful @@ -325,7 +325,7 @@ func (b *state) ForEach(exporter export.ExportKindSelector, f func(export.Record return ErrInconsistentState } for key, value := range b.values { - mkind := key.descriptor.MetricKind() + mkind := key.descriptor.InstrumentKind() var agg aggregation.Aggregation var start time.Time diff --git a/sdk/metric/processor/basic/basic_test.go b/sdk/metric/processor/basic/basic_test.go index 406cdbaf7..d56035b71 100644 --- a/sdk/metric/processor/basic/basic_test.go +++ b/sdk/metric/processor/basic/basic_test.go @@ -40,7 +40,7 @@ func TestProcessor(t *testing.T) { kind export.ExportKind } type instrumentCase struct { - kind metric.Kind + kind metric.InstrumentKind } type numberCase struct { kind metric.NumberKind @@ -56,12 +56,12 @@ func TestProcessor(t *testing.T) { } { t.Run(tc.kind.String(), func(t *testing.T) { for _, ic := range []instrumentCase{ - {kind: metric.CounterKind}, - {kind: metric.UpDownCounterKind}, - {kind: metric.ValueRecorderKind}, - {kind: metric.SumObserverKind}, - {kind: metric.UpDownSumObserverKind}, - {kind: metric.ValueObserverKind}, + {kind: metric.CounterInstrumentKind}, + {kind: metric.UpDownCounterInstrumentKind}, + {kind: metric.ValueRecorderInstrumentKind}, + {kind: metric.SumObserverInstrumentKind}, + {kind: metric.UpDownSumObserverInstrumentKind}, + {kind: metric.ValueObserverInstrumentKind}, } { t.Run(ic.kind.String(), func(t *testing.T) { for _, nc := range []numberCase{ @@ -114,7 +114,7 @@ func updateFor(t *testing.T, desc *metric.Descriptor, selector export.Aggregator func testProcessor( t *testing.T, ekind export.ExportKind, - mkind metric.Kind, + mkind metric.InstrumentKind, nkind metric.NumberKind, akind aggregation.Kind, ) { @@ -295,7 +295,7 @@ func TestBasicInconsistent(t *testing.T) { // Test no start b = basic.New(processorTest.AggregatorSelector(), export.PassThroughExporter) - desc := metric.NewDescriptor("inst", metric.CounterKind, metric.Int64NumberKind) + desc := metric.NewDescriptor("inst", metric.CounterInstrumentKind, metric.Int64NumberKind) accum := export.NewAccumulation(&desc, label.EmptySet(), resource.Empty(), metrictest.NoopAggregator{}) require.Equal(t, basic.ErrInconsistentState, b.Process(accum)) @@ -318,7 +318,7 @@ func TestBasicTimestamps(t *testing.T) { b := basic.New(processorTest.AggregatorSelector(), export.PassThroughExporter) afterNew := time.Now() - desc := metric.NewDescriptor("inst", metric.CounterKind, metric.Int64NumberKind) + desc := metric.NewDescriptor("inst", metric.CounterInstrumentKind, metric.Int64NumberKind) accum := export.NewAccumulation(&desc, label.EmptySet(), resource.Empty(), metrictest.NoopAggregator{}) b.StartCollection() @@ -364,7 +364,7 @@ func TestStatefulNoMemoryCumulative(t *testing.T) { res := resource.New(label.String("R", "V")) ekind := export.CumulativeExporter - desc := metric.NewDescriptor("inst.sum", metric.CounterKind, metric.Int64NumberKind) + desc := metric.NewDescriptor("inst.sum", metric.CounterInstrumentKind, metric.Int64NumberKind) selector := processorTest.AggregatorSelector() processor := basic.New(selector, ekind, basic.WithMemory(false)) @@ -398,7 +398,7 @@ func TestStatefulNoMemoryDelta(t *testing.T) { res := resource.New(label.String("R", "V")) ekind := export.DeltaExporter - desc := metric.NewDescriptor("inst.sum", metric.SumObserverKind, metric.Int64NumberKind) + desc := metric.NewDescriptor("inst.sum", metric.SumObserverInstrumentKind, metric.Int64NumberKind) selector := processorTest.AggregatorSelector() processor := basic.New(selector, ekind, basic.WithMemory(false)) @@ -436,7 +436,7 @@ func TestMultiObserverSum(t *testing.T) { } { res := resource.New(label.String("R", "V")) - desc := metric.NewDescriptor("observe.sum", metric.SumObserverKind, metric.Int64NumberKind) + desc := metric.NewDescriptor("observe.sum", metric.SumObserverInstrumentKind, metric.Int64NumberKind) selector := processorTest.AggregatorSelector() processor := basic.New(selector, ekind, basic.WithMemory(false)) diff --git a/sdk/metric/selector/simple/simple.go b/sdk/metric/selector/simple/simple.go index e5633ef48..850e64920 100644 --- a/sdk/metric/selector/simple/simple.go +++ b/sdk/metric/selector/simple/simple.go @@ -95,10 +95,10 @@ func lastValueAggs(aggPtrs []*export.Aggregator) { } func (selectorInexpensive) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) { - switch descriptor.MetricKind() { - case metric.ValueObserverKind: + switch descriptor.InstrumentKind() { + case metric.ValueObserverInstrumentKind: lastValueAggs(aggPtrs) - case metric.ValueRecorderKind: + case metric.ValueRecorderInstrumentKind: aggs := minmaxsumcount.New(len(aggPtrs), descriptor) for i := range aggPtrs { *aggPtrs[i] = &aggs[i] @@ -109,10 +109,10 @@ func (selectorInexpensive) AggregatorFor(descriptor *metric.Descriptor, aggPtrs } func (s selectorSketch) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) { - switch descriptor.MetricKind() { - case metric.ValueObserverKind: + switch descriptor.InstrumentKind() { + case metric.ValueObserverInstrumentKind: lastValueAggs(aggPtrs) - case metric.ValueRecorderKind: + case metric.ValueRecorderInstrumentKind: aggs := ddsketch.New(len(aggPtrs), descriptor, s.config) for i := range aggPtrs { *aggPtrs[i] = &aggs[i] @@ -123,10 +123,10 @@ func (s selectorSketch) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ... } func (selectorExact) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) { - switch descriptor.MetricKind() { - case metric.ValueObserverKind: + switch descriptor.InstrumentKind() { + case metric.ValueObserverInstrumentKind: lastValueAggs(aggPtrs) - case metric.ValueRecorderKind: + case metric.ValueRecorderInstrumentKind: aggs := array.New(len(aggPtrs)) for i := range aggPtrs { *aggPtrs[i] = &aggs[i] @@ -137,10 +137,10 @@ func (selectorExact) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*ex } func (s selectorHistogram) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) { - switch descriptor.MetricKind() { - case metric.ValueObserverKind: + switch descriptor.InstrumentKind() { + case metric.ValueObserverInstrumentKind: lastValueAggs(aggPtrs) - case metric.ValueRecorderKind: + case metric.ValueRecorderInstrumentKind: aggs := histogram.New(len(aggPtrs), descriptor, s.boundaries) for i := range aggPtrs { *aggPtrs[i] = &aggs[i] diff --git a/sdk/metric/selector/simple/simple_test.go b/sdk/metric/selector/simple/simple_test.go index ac3cbd0e6..3dfb67e3e 100644 --- a/sdk/metric/selector/simple/simple_test.go +++ b/sdk/metric/selector/simple/simple_test.go @@ -31,12 +31,12 @@ import ( ) var ( - testCounterDesc = metric.NewDescriptor("counter", metric.CounterKind, metric.Int64NumberKind) - testUpDownCounterDesc = metric.NewDescriptor("updowncounter", metric.UpDownCounterKind, metric.Int64NumberKind) - testSumObserverDesc = metric.NewDescriptor("sumobserver", metric.SumObserverKind, metric.Int64NumberKind) - testUpDownSumObserverDesc = metric.NewDescriptor("updownsumobserver", metric.UpDownSumObserverKind, metric.Int64NumberKind) - testValueRecorderDesc = metric.NewDescriptor("valuerecorder", metric.ValueRecorderKind, metric.Int64NumberKind) - testValueObserverDesc = metric.NewDescriptor("valueobserver", metric.ValueObserverKind, metric.Int64NumberKind) + testCounterDesc = metric.NewDescriptor("counter", metric.CounterInstrumentKind, metric.Int64NumberKind) + testUpDownCounterDesc = metric.NewDescriptor("updowncounter", metric.UpDownCounterInstrumentKind, metric.Int64NumberKind) + testSumObserverDesc = metric.NewDescriptor("sumobserver", metric.SumObserverInstrumentKind, metric.Int64NumberKind) + testUpDownSumObserverDesc = metric.NewDescriptor("updownsumobserver", metric.UpDownSumObserverInstrumentKind, metric.Int64NumberKind) + testValueRecorderDesc = metric.NewDescriptor("valuerecorder", metric.ValueRecorderInstrumentKind, metric.Int64NumberKind) + testValueObserverDesc = metric.NewDescriptor("valueobserver", metric.ValueObserverInstrumentKind, metric.Int64NumberKind) ) func oneAgg(sel export.AggregatorSelector, desc *metric.Descriptor) export.Aggregator { diff --git a/sdk/metric/stress_test.go b/sdk/metric/stress_test.go index e6a1fae7b..ec928645a 100644 --- a/sdk/metric/stress_test.go +++ b/sdk/metric/stress_test.go @@ -264,14 +264,14 @@ func (f *testFixture) Process(accumulation export.Accumulation) error { actual, _ := f.received.LoadOrStore(key, f.impl.newStore()) agg := accumulation.Aggregator() - switch accumulation.Descriptor().MetricKind() { - case metric.CounterKind: + switch accumulation.Descriptor().InstrumentKind() { + case metric.CounterInstrumentKind: sum, err := agg.(aggregation.Sum).Sum() if err != nil { f.T.Fatal("Sum error: ", err) } f.impl.storeCollect(actual, sum, time.Time{}) - case metric.ValueRecorderKind: + case metric.ValueRecorderInstrumentKind: lv, ts, err := agg.(aggregation.LastValue).LastValue() if err != nil && err != aggregation.ErrNoData { f.T.Fatal("Last value error: ", err)