mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-04-17 11:46:27 +02:00
Move metric code to a separate package (#1321)
* Move metrics code to metric package * Update changelog
This commit is contained in:
parent
386331a472
commit
75d4911c95
@ -31,7 +31,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
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)
|
||||
- Move the `go.opentelemetry.io/otel/api/metric` and `go.opentelemetry.io/otel/api/metric/metrictest` packages into `go.opentelemetry.io/otel` as part of #964. (#1252)
|
||||
- Move the `go.opentelemetry.io/otel/api/metric/metrictest` package into `go.opentelemetry.io/oteltest` as part of #964. (#1252)
|
||||
- Move the `go.opentelemetry.io/otel/api/metric` package into `go.opentelemetry.io/otel/metric` as part of #1303. (#1321)
|
||||
- Move the `go.opentelemetry.io/otel/api/metric/registry` package into `go.opentelemetry.io/otel/metric/registry as a part of #1303. (#1316)
|
||||
- Move the `Number` type (together with related functions) from `go.opentelemetry.io/otel/api/metric` package into `go.opentelemetry.io/otel/metric/number` as a part of #1303. (#1316)
|
||||
- The function signature of the Span `AddEvent` method in `go.opentelemetry.io/otel` is updated to no longer take an unused context and instead take a required name and a variable number of `EventOption`s. (#1254)
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"go.opentelemetry.io/otel/exporters/stdout"
|
||||
"go.opentelemetry.io/otel/global"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/propagators"
|
||||
"go.opentelemetry.io/otel/sdk/metric/controller/push"
|
||||
"go.opentelemetry.io/otel/sdk/metric/processor/basic"
|
||||
@ -68,14 +69,14 @@ func main() {
|
||||
|
||||
commonLabels := []label.KeyValue{lemonsKey.Int(10), label.String("A", "1"), label.String("B", "2"), label.String("C", "3")}
|
||||
|
||||
oneMetricCB := func(_ context.Context, result otel.Float64ObserverResult) {
|
||||
oneMetricCB := func(_ context.Context, result metric.Float64ObserverResult) {
|
||||
result.Observe(1, commonLabels...)
|
||||
}
|
||||
_ = otel.Must(meter).NewFloat64ValueObserver("ex.com.one", oneMetricCB,
|
||||
otel.WithDescription("A ValueObserver set to 1.0"),
|
||||
_ = metric.Must(meter).NewFloat64ValueObserver("ex.com.one", oneMetricCB,
|
||||
metric.WithDescription("A ValueObserver set to 1.0"),
|
||||
)
|
||||
|
||||
valuerecorderTwo := otel.Must(meter).NewFloat64ValueRecorder("ex.com.two")
|
||||
valuerecorderTwo := metric.Must(meter).NewFloat64ValueRecorder("ex.com.two")
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = otel.ContextWithBaggageValues(ctx, fooKey.String("foo1"), barKey.String("bar1"))
|
||||
|
@ -25,10 +25,10 @@ import (
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/exporters/otlp"
|
||||
"go.opentelemetry.io/otel/global"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/propagators"
|
||||
"go.opentelemetry.io/otel/sdk/metric/controller/push"
|
||||
"go.opentelemetry.io/otel/sdk/metric/processor/basic"
|
||||
@ -111,10 +111,10 @@ func main() {
|
||||
}
|
||||
|
||||
// Recorder metric example
|
||||
valuerecorder := otel.Must(meter).
|
||||
valuerecorder := metric.Must(meter).
|
||||
NewFloat64Counter(
|
||||
"an_important_metric",
|
||||
otel.WithDescription("Measures the cumulative epicness of the app"),
|
||||
metric.WithDescription("Measures the cumulative epicness of the app"),
|
||||
).Bind(commonLabels...)
|
||||
defer valuerecorder.Unbind()
|
||||
|
||||
|
@ -22,10 +22,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/exporters/metric/prometheus"
|
||||
"go.opentelemetry.io/otel/global"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -52,19 +52,19 @@ func main() {
|
||||
observerLock := new(sync.RWMutex)
|
||||
observerValueToReport := new(float64)
|
||||
observerLabelsToReport := new([]label.KeyValue)
|
||||
cb := func(_ context.Context, result otel.Float64ObserverResult) {
|
||||
cb := func(_ context.Context, result metric.Float64ObserverResult) {
|
||||
(*observerLock).RLock()
|
||||
value := *observerValueToReport
|
||||
labels := *observerLabelsToReport
|
||||
(*observerLock).RUnlock()
|
||||
result.Observe(value, labels...)
|
||||
}
|
||||
_ = otel.Must(meter).NewFloat64ValueObserver("ex.com.one", cb,
|
||||
otel.WithDescription("A ValueObserver set to 1.0"),
|
||||
_ = metric.Must(meter).NewFloat64ValueObserver("ex.com.one", cb,
|
||||
metric.WithDescription("A ValueObserver set to 1.0"),
|
||||
)
|
||||
|
||||
valuerecorder := otel.Must(meter).NewFloat64ValueRecorder("ex.com.two")
|
||||
counter := otel.Must(meter).NewFloat64Counter("ex.com.three")
|
||||
valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("ex.com.two")
|
||||
counter := metric.Must(meter).NewFloat64Counter("ex.com.three")
|
||||
|
||||
commonLabels := []label.KeyValue{lemonsKey.Int(10), label.String("A", "1"), label.String("B", "2"), label.String("C", "3")}
|
||||
notSoCommonLabels := []label.KeyValue{lemonsKey.Int(13)}
|
||||
|
@ -22,9 +22,9 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/exporters/metric/prometheus"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/sdk/metric/controller/pull"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
)
|
||||
@ -59,13 +59,13 @@ func ExampleNewExportPipeline() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Use two instruments
|
||||
counter := otel.Must(meter).NewInt64Counter(
|
||||
counter := metric.Must(meter).NewInt64Counter(
|
||||
"a.counter",
|
||||
otel.WithDescription("Counts things"),
|
||||
metric.WithDescription("Counts things"),
|
||||
)
|
||||
recorder := otel.Must(meter).NewInt64ValueRecorder(
|
||||
recorder := metric.Must(meter).NewInt64ValueRecorder(
|
||||
"a.valuerecorder",
|
||||
otel.WithDescription("Records values"),
|
||||
metric.WithDescription("Records values"),
|
||||
)
|
||||
|
||||
counter.Add(ctx, 100, label.String("key", "value"))
|
||||
|
@ -23,9 +23,9 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/global"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
@ -156,7 +156,7 @@ func (e *Exporter) SetController(config Config, options ...pull.Option) {
|
||||
}
|
||||
|
||||
// MeterProvider returns the MeterProvider of this exporter.
|
||||
func (e *Exporter) MeterProvider() otel.MeterProvider {
|
||||
func (e *Exporter) MeterProvider() metric.MeterProvider {
|
||||
return e.controller.MeterProvider()
|
||||
}
|
||||
|
||||
@ -167,7 +167,7 @@ func (e *Exporter) Controller() *pull.Controller {
|
||||
return e.controller
|
||||
}
|
||||
|
||||
func (e *Exporter) ExportKindFor(desc *otel.Descriptor, kind aggregation.Kind) export.ExportKind {
|
||||
func (e *Exporter) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) export.ExportKind {
|
||||
// NOTE: Summary values should use Delta aggregation, then be
|
||||
// combined into a sliding window, see the TODO below.
|
||||
// NOTE: Prometheus also supports a "GaugeDelta" exposition format,
|
||||
|
@ -26,9 +26,9 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/exporters/metric/prometheus"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/sdk/metric/controller/pull"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
)
|
||||
@ -48,9 +48,9 @@ func TestPrometheusExporter(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
meter := exporter.MeterProvider().Meter("test")
|
||||
upDownCounter := otel.Must(meter).NewFloat64UpDownCounter("updowncounter")
|
||||
counter := otel.Must(meter).NewFloat64Counter("counter")
|
||||
valuerecorder := otel.Must(meter).NewFloat64ValueRecorder("valuerecorder")
|
||||
upDownCounter := metric.Must(meter).NewFloat64UpDownCounter("updowncounter")
|
||||
counter := metric.Must(meter).NewFloat64Counter("counter")
|
||||
valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("valuerecorder")
|
||||
|
||||
labels := []label.KeyValue{
|
||||
label.Key("A").String("B"),
|
||||
@ -65,7 +65,7 @@ func TestPrometheusExporter(t *testing.T) {
|
||||
|
||||
expected = append(expected, `counter{A="B",C="D",R="V"} 15.3`)
|
||||
|
||||
_ = otel.Must(meter).NewInt64ValueObserver("intobserver", func(_ context.Context, result otel.Int64ObserverResult) {
|
||||
_ = metric.Must(meter).NewInt64ValueObserver("intobserver", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||
result.Observe(1, labels...)
|
||||
})
|
||||
|
||||
@ -138,9 +138,9 @@ func TestPrometheusStatefulness(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
counter := otel.Must(meter).NewInt64Counter(
|
||||
counter := metric.Must(meter).NewInt64Counter(
|
||||
"a.counter",
|
||||
otel.WithDescription("Counts things"),
|
||||
metric.WithDescription("Counts things"),
|
||||
)
|
||||
|
||||
counter.Add(ctx, 100, label.String("key", "value"))
|
||||
|
@ -26,9 +26,8 @@ import (
|
||||
|
||||
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
|
||||
metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
@ -102,17 +101,17 @@ func TestStringKeyValues(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMinMaxSumCountValue(t *testing.T) {
|
||||
mmsc, ckpt := metrictest.Unslice2(minmaxsumcount.New(2, &otel.Descriptor{}))
|
||||
mmsc, ckpt := metrictest.Unslice2(minmaxsumcount.New(2, &metric.Descriptor{}))
|
||||
|
||||
assert.NoError(t, mmsc.Update(context.Background(), 1, &otel.Descriptor{}))
|
||||
assert.NoError(t, mmsc.Update(context.Background(), 10, &otel.Descriptor{}))
|
||||
assert.NoError(t, mmsc.Update(context.Background(), 1, &metric.Descriptor{}))
|
||||
assert.NoError(t, mmsc.Update(context.Background(), 10, &metric.Descriptor{}))
|
||||
|
||||
// Prior to checkpointing ErrNoData should be returned.
|
||||
_, _, _, _, err := minMaxSumCountValues(ckpt.(aggregation.MinMaxSumCount))
|
||||
assert.EqualError(t, err, aggregation.ErrNoData.Error())
|
||||
|
||||
// Checkpoint to set non-zero values
|
||||
require.NoError(t, mmsc.SynchronizedMove(ckpt, &otel.Descriptor{}))
|
||||
require.NoError(t, mmsc.SynchronizedMove(ckpt, &metric.Descriptor{}))
|
||||
min, max, sum, count, err := minMaxSumCountValues(ckpt.(aggregation.MinMaxSumCount))
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, min, number.NewInt64Number(1))
|
||||
@ -123,7 +122,7 @@ func TestMinMaxSumCountValue(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMinMaxSumCountDatapoints(t *testing.T) {
|
||||
desc := otel.NewDescriptor("", otel.ValueRecorderInstrumentKind, number.Int64Kind)
|
||||
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind)
|
||||
labels := label.NewSet()
|
||||
mmsc, ckpt := metrictest.Unslice2(minmaxsumcount.New(2, &desc))
|
||||
|
||||
@ -155,14 +154,14 @@ 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, &otel.Descriptor{})[0]
|
||||
mmsc := &minmaxsumcount.New(1, &metric.Descriptor{})[0]
|
||||
_, _, _, _, err := minMaxSumCountValues(mmsc)
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, aggregation.ErrNoData, err)
|
||||
}
|
||||
|
||||
func TestSumIntDataPoints(t *testing.T) {
|
||||
desc := otel.NewDescriptor("", otel.ValueRecorderInstrumentKind, number.Int64Kind)
|
||||
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind)
|
||||
labels := label.NewSet()
|
||||
s, ckpt := metrictest.Unslice2(sumAgg.New(2))
|
||||
assert.NoError(t, s.Update(context.Background(), number.Number(1), &desc))
|
||||
@ -190,7 +189,7 @@ func TestSumIntDataPoints(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSumFloatDataPoints(t *testing.T) {
|
||||
desc := otel.NewDescriptor("", otel.ValueRecorderInstrumentKind, number.Float64Kind)
|
||||
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Float64Kind)
|
||||
labels := label.NewSet()
|
||||
s, ckpt := metrictest.Unslice2(sumAgg.New(2))
|
||||
assert.NoError(t, s.Update(context.Background(), number.NewFloat64Number(1), &desc))
|
||||
@ -219,7 +218,7 @@ func TestSumFloatDataPoints(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLastValueIntDataPoints(t *testing.T) {
|
||||
desc := otel.NewDescriptor("", otel.ValueRecorderInstrumentKind, number.Int64Kind)
|
||||
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind)
|
||||
labels := label.NewSet()
|
||||
s, ckpt := metrictest.Unslice2(lvAgg.New(2))
|
||||
assert.NoError(t, s.Update(context.Background(), number.Number(100), &desc))
|
||||
@ -245,7 +244,7 @@ func TestLastValueIntDataPoints(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSumErrUnknownValueType(t *testing.T) {
|
||||
desc := otel.NewDescriptor("", otel.ValueRecorderInstrumentKind, number.Kind(-1))
|
||||
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Kind(-1))
|
||||
labels := label.NewSet()
|
||||
s := &sumAgg.New(1)[0]
|
||||
record := export.NewRecord(&desc, &labels, nil, s, intervalStart, intervalEnd)
|
||||
@ -274,13 +273,13 @@ func (t *testAgg) Aggregation() aggregation.Aggregation {
|
||||
|
||||
// None of these three are used:
|
||||
|
||||
func (t *testAgg) Update(ctx context.Context, number number.Number, descriptor *otel.Descriptor) error {
|
||||
func (t *testAgg) Update(ctx context.Context, number number.Number, descriptor *metric.Descriptor) error {
|
||||
return nil
|
||||
}
|
||||
func (t *testAgg) SynchronizedMove(destination export.Aggregator, descriptor *otel.Descriptor) error {
|
||||
func (t *testAgg) SynchronizedMove(destination export.Aggregator, descriptor *metric.Descriptor) error {
|
||||
return nil
|
||||
}
|
||||
func (t *testAgg) Merge(aggregator export.Aggregator, descriptor *otel.Descriptor) error {
|
||||
func (t *testAgg) Merge(aggregator export.Aggregator, descriptor *metric.Descriptor) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -330,7 +329,7 @@ var _ aggregation.MinMaxSumCount = &testErrMinMaxSumCount{}
|
||||
|
||||
func TestRecordAggregatorIncompatibleErrors(t *testing.T) {
|
||||
makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) {
|
||||
desc := otel.NewDescriptor("things", otel.CounterInstrumentKind, number.Int64Kind)
|
||||
desc := metric.NewDescriptor("things", metric.CounterInstrumentKind, number.Int64Kind)
|
||||
labels := label.NewSet()
|
||||
res := resource.Empty()
|
||||
test := &testAgg{
|
||||
@ -367,7 +366,7 @@ func TestRecordAggregatorIncompatibleErrors(t *testing.T) {
|
||||
|
||||
func TestRecordAggregatorUnexpectedErrors(t *testing.T) {
|
||||
makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) {
|
||||
desc := otel.NewDescriptor("things", otel.CounterInstrumentKind, number.Int64Kind)
|
||||
desc := metric.NewDescriptor("things", metric.CounterInstrumentKind, number.Int64Kind)
|
||||
labels := label.NewSet()
|
||||
res := resource.Empty()
|
||||
return Record(export.CumulativeExportKindSelector(), export.NewRecord(&desc, &labels, res, agg, intervalStart, intervalEnd))
|
||||
|
@ -27,11 +27,10 @@ import (
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/metadata"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
colmetricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/collector/metrics/v1"
|
||||
coltracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/collector/trace/v1"
|
||||
|
||||
"go.opentelemetry.io/otel/exporters/otlp/internal/transform"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
tracesdk "go.opentelemetry.io/otel/sdk/export/trace"
|
||||
@ -289,7 +288,7 @@ func (e *Exporter) Export(parent context.Context, cps metricsdk.CheckpointSet) e
|
||||
|
||||
// ExportKindFor reports back to the OpenTelemetry SDK sending this Exporter
|
||||
// metric telemetry that it needs to be provided in a cumulative format.
|
||||
func (e *Exporter) ExportKindFor(desc *otel.Descriptor, kind aggregation.Kind) metricsdk.ExportKind {
|
||||
func (e *Exporter) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) metricsdk.ExportKind {
|
||||
return e.c.exportKindSelector.ExportKindFor(desc, kind)
|
||||
}
|
||||
|
||||
|
@ -25,11 +25,10 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel/exporters/otlp"
|
||||
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/exporters/otlp"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
exporttrace "go.opentelemetry.io/otel/sdk/export/trace"
|
||||
@ -130,52 +129,52 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
|
||||
labels := []label.KeyValue{label.Bool("test", true)}
|
||||
|
||||
type data struct {
|
||||
iKind otel.InstrumentKind
|
||||
iKind metric.InstrumentKind
|
||||
nKind number.Kind
|
||||
val int64
|
||||
}
|
||||
instruments := map[string]data{
|
||||
"test-int64-counter": {otel.CounterInstrumentKind, number.Int64Kind, 1},
|
||||
"test-float64-counter": {otel.CounterInstrumentKind, number.Float64Kind, 1},
|
||||
"test-int64-valuerecorder": {otel.ValueRecorderInstrumentKind, number.Int64Kind, 2},
|
||||
"test-float64-valuerecorder": {otel.ValueRecorderInstrumentKind, number.Float64Kind, 2},
|
||||
"test-int64-valueobserver": {otel.ValueObserverInstrumentKind, number.Int64Kind, 3},
|
||||
"test-float64-valueobserver": {otel.ValueObserverInstrumentKind, number.Float64Kind, 3},
|
||||
"test-int64-counter": {metric.CounterInstrumentKind, number.Int64Kind, 1},
|
||||
"test-float64-counter": {metric.CounterInstrumentKind, number.Float64Kind, 1},
|
||||
"test-int64-valuerecorder": {metric.ValueRecorderInstrumentKind, number.Int64Kind, 2},
|
||||
"test-float64-valuerecorder": {metric.ValueRecorderInstrumentKind, number.Float64Kind, 2},
|
||||
"test-int64-valueobserver": {metric.ValueObserverInstrumentKind, number.Int64Kind, 3},
|
||||
"test-float64-valueobserver": {metric.ValueObserverInstrumentKind, number.Float64Kind, 3},
|
||||
}
|
||||
for name, data := range instruments {
|
||||
data := data
|
||||
switch data.iKind {
|
||||
case otel.CounterInstrumentKind:
|
||||
case metric.CounterInstrumentKind:
|
||||
switch data.nKind {
|
||||
case number.Int64Kind:
|
||||
otel.Must(meter).NewInt64Counter(name).Add(ctx, data.val, labels...)
|
||||
metric.Must(meter).NewInt64Counter(name).Add(ctx, data.val, labels...)
|
||||
case number.Float64Kind:
|
||||
otel.Must(meter).NewFloat64Counter(name).Add(ctx, float64(data.val), labels...)
|
||||
metric.Must(meter).NewFloat64Counter(name).Add(ctx, float64(data.val), labels...)
|
||||
default:
|
||||
assert.Failf(t, "unsupported number testing kind", data.nKind.String())
|
||||
}
|
||||
case otel.ValueRecorderInstrumentKind:
|
||||
case metric.ValueRecorderInstrumentKind:
|
||||
switch data.nKind {
|
||||
case number.Int64Kind:
|
||||
otel.Must(meter).NewInt64ValueRecorder(name).Record(ctx, data.val, labels...)
|
||||
metric.Must(meter).NewInt64ValueRecorder(name).Record(ctx, data.val, labels...)
|
||||
case number.Float64Kind:
|
||||
otel.Must(meter).NewFloat64ValueRecorder(name).Record(ctx, float64(data.val), labels...)
|
||||
metric.Must(meter).NewFloat64ValueRecorder(name).Record(ctx, float64(data.val), labels...)
|
||||
default:
|
||||
assert.Failf(t, "unsupported number testing kind", data.nKind.String())
|
||||
}
|
||||
case otel.ValueObserverInstrumentKind:
|
||||
case metric.ValueObserverInstrumentKind:
|
||||
switch data.nKind {
|
||||
case number.Int64Kind:
|
||||
otel.Must(meter).NewInt64ValueObserver(name,
|
||||
func(_ context.Context, result otel.Int64ObserverResult) {
|
||||
metric.Must(meter).NewInt64ValueObserver(name,
|
||||
func(_ context.Context, result metric.Int64ObserverResult) {
|
||||
result.Observe(data.val, labels...)
|
||||
},
|
||||
)
|
||||
case number.Float64Kind:
|
||||
callback := func(v float64) otel.Float64ObserverFunc {
|
||||
return otel.Float64ObserverFunc(func(_ context.Context, result otel.Float64ObserverResult) { result.Observe(v, labels...) })
|
||||
callback := func(v float64) metric.Float64ObserverFunc {
|
||||
return metric.Float64ObserverFunc(func(_ context.Context, result metric.Float64ObserverResult) { result.Observe(v, labels...) })
|
||||
}(float64(data.val))
|
||||
otel.Must(meter).NewFloat64ValueObserver(name, callback)
|
||||
metric.Must(meter).NewFloat64ValueObserver(name, callback)
|
||||
default:
|
||||
assert.Failf(t, "unsupported number testing kind", data.nKind.String())
|
||||
}
|
||||
@ -245,7 +244,7 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
|
||||
seen[m.Name] = struct{}{}
|
||||
|
||||
switch data.iKind {
|
||||
case otel.CounterInstrumentKind:
|
||||
case metric.CounterInstrumentKind:
|
||||
switch data.nKind {
|
||||
case number.Int64Kind:
|
||||
if dp := m.GetIntSum().DataPoints; assert.Len(t, dp, 1) {
|
||||
@ -258,7 +257,7 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
|
||||
default:
|
||||
assert.Failf(t, "invalid number kind", data.nKind.String())
|
||||
}
|
||||
case otel.ValueObserverInstrumentKind:
|
||||
case metric.ValueObserverInstrumentKind:
|
||||
switch data.nKind {
|
||||
case number.Int64Kind:
|
||||
if dp := m.GetIntGauge().DataPoints; assert.Len(t, dp, 1) {
|
||||
@ -271,7 +270,7 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
|
||||
default:
|
||||
assert.Failf(t, "invalid number kind", data.nKind.String())
|
||||
}
|
||||
case otel.ValueRecorderInstrumentKind:
|
||||
case metric.ValueRecorderInstrumentKind:
|
||||
switch data.nKind {
|
||||
case number.Int64Kind:
|
||||
assert.NotNil(t, m.GetIntHistogram())
|
||||
|
@ -27,9 +27,8 @@ import (
|
||||
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
|
||||
metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1"
|
||||
resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
@ -94,10 +93,10 @@ func (m *checkpointSet) ForEach(_ metricsdk.ExportKindSelector, fn func(metricsd
|
||||
|
||||
type record struct {
|
||||
name string
|
||||
iKind otel.InstrumentKind
|
||||
iKind metric.InstrumentKind
|
||||
nKind number.Kind
|
||||
resource *resource.Resource
|
||||
opts []otel.InstrumentOption
|
||||
opts []metric.InstrumentOption
|
||||
labels []label.KeyValue
|
||||
}
|
||||
|
||||
@ -164,7 +163,7 @@ func TestNoGroupingExport(t *testing.T) {
|
||||
[]record{
|
||||
{
|
||||
"int64-count",
|
||||
otel.CounterInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
number.Int64Kind,
|
||||
nil,
|
||||
nil,
|
||||
@ -172,7 +171,7 @@ func TestNoGroupingExport(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"int64-count",
|
||||
otel.CounterInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
number.Int64Kind,
|
||||
nil,
|
||||
nil,
|
||||
@ -219,7 +218,7 @@ func TestNoGroupingExport(t *testing.T) {
|
||||
func TestValuerecorderMetricGroupingExport(t *testing.T) {
|
||||
r := record{
|
||||
"valuerecorder",
|
||||
otel.ValueRecorderInstrumentKind,
|
||||
metric.ValueRecorderInstrumentKind,
|
||||
number.Int64Kind,
|
||||
nil,
|
||||
nil,
|
||||
@ -288,7 +287,7 @@ func TestValuerecorderMetricGroupingExport(t *testing.T) {
|
||||
func TestCountInt64MetricGroupingExport(t *testing.T) {
|
||||
r := record{
|
||||
"int64-count",
|
||||
otel.CounterInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
number.Int64Kind,
|
||||
nil,
|
||||
nil,
|
||||
@ -338,7 +337,7 @@ func TestCountInt64MetricGroupingExport(t *testing.T) {
|
||||
func TestCountFloat64MetricGroupingExport(t *testing.T) {
|
||||
r := record{
|
||||
"float64-count",
|
||||
otel.CounterInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
number.Float64Kind,
|
||||
nil,
|
||||
nil,
|
||||
@ -410,7 +409,7 @@ func TestResourceMetricGroupingExport(t *testing.T) {
|
||||
[]record{
|
||||
{
|
||||
"int64-count",
|
||||
otel.CounterInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
number.Int64Kind,
|
||||
testInstA,
|
||||
nil,
|
||||
@ -418,7 +417,7 @@ func TestResourceMetricGroupingExport(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"int64-count",
|
||||
otel.CounterInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
number.Int64Kind,
|
||||
testInstA,
|
||||
nil,
|
||||
@ -426,7 +425,7 @@ func TestResourceMetricGroupingExport(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"int64-count",
|
||||
otel.CounterInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
number.Int64Kind,
|
||||
testInstA,
|
||||
nil,
|
||||
@ -434,7 +433,7 @@ func TestResourceMetricGroupingExport(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"int64-count",
|
||||
otel.CounterInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
number.Int64Kind,
|
||||
testInstB,
|
||||
nil,
|
||||
@ -511,16 +510,16 @@ func TestResourceMetricGroupingExport(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResourceInstLibMetricGroupingExport(t *testing.T) {
|
||||
countingLib1 := []otel.InstrumentOption{
|
||||
otel.WithInstrumentationName("counting-lib"),
|
||||
otel.WithInstrumentationVersion("v1"),
|
||||
countingLib1 := []metric.InstrumentOption{
|
||||
metric.WithInstrumentationName("counting-lib"),
|
||||
metric.WithInstrumentationVersion("v1"),
|
||||
}
|
||||
countingLib2 := []otel.InstrumentOption{
|
||||
otel.WithInstrumentationName("counting-lib"),
|
||||
otel.WithInstrumentationVersion("v2"),
|
||||
countingLib2 := []metric.InstrumentOption{
|
||||
metric.WithInstrumentationName("counting-lib"),
|
||||
metric.WithInstrumentationVersion("v2"),
|
||||
}
|
||||
summingLib := []otel.InstrumentOption{
|
||||
otel.WithInstrumentationName("summing-lib"),
|
||||
summingLib := []metric.InstrumentOption{
|
||||
metric.WithInstrumentationName("summing-lib"),
|
||||
}
|
||||
runMetricExportTests(
|
||||
t,
|
||||
@ -528,7 +527,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
|
||||
[]record{
|
||||
{
|
||||
"int64-count",
|
||||
otel.CounterInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
number.Int64Kind,
|
||||
testInstA,
|
||||
countingLib1,
|
||||
@ -536,7 +535,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"int64-count",
|
||||
otel.CounterInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
number.Int64Kind,
|
||||
testInstA,
|
||||
countingLib2,
|
||||
@ -544,7 +543,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"int64-count",
|
||||
otel.CounterInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
number.Int64Kind,
|
||||
testInstA,
|
||||
countingLib1,
|
||||
@ -552,7 +551,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"int64-count",
|
||||
otel.CounterInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
number.Int64Kind,
|
||||
testInstA,
|
||||
countingLib1,
|
||||
@ -560,7 +559,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"int64-count",
|
||||
otel.CounterInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
number.Int64Kind,
|
||||
testInstA,
|
||||
summingLib,
|
||||
@ -568,7 +567,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"int64-count",
|
||||
otel.CounterInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
number.Int64Kind,
|
||||
testInstB,
|
||||
countingLib1,
|
||||
@ -704,16 +703,16 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
|
||||
func TestStatelessExportKind(t *testing.T) {
|
||||
type testcase struct {
|
||||
name string
|
||||
instrumentKind otel.InstrumentKind
|
||||
instrumentKind metric.InstrumentKind
|
||||
aggTemporality metricpb.AggregationTemporality
|
||||
monotonic bool
|
||||
}
|
||||
|
||||
for _, k := range []testcase{
|
||||
{"counter", otel.CounterInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, true},
|
||||
{"updowncounter", otel.UpDownCounterInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, false},
|
||||
{"sumobserver", otel.SumObserverInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE, true},
|
||||
{"updownsumobserver", otel.UpDownSumObserverInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE, false},
|
||||
{"counter", metric.CounterInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, true},
|
||||
{"updowncounter", metric.UpDownCounterInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, false},
|
||||
{"sumobserver", metric.SumObserverInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE, true},
|
||||
{"updownsumobserver", metric.UpDownSumObserverInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE, false},
|
||||
} {
|
||||
t.Run(k.name, func(t *testing.T) {
|
||||
runMetricExportTests(
|
||||
@ -786,7 +785,7 @@ func runMetricExportTest(t *testing.T, exp *Exporter, rs []record, expected []me
|
||||
for _, r := range rs {
|
||||
lcopy := make([]label.KeyValue, len(r.labels))
|
||||
copy(lcopy, r.labels)
|
||||
desc := otel.NewDescriptor(r.name, r.iKind, r.nKind, r.opts...)
|
||||
desc := metric.NewDescriptor(r.name, r.iKind, r.nKind, r.opts...)
|
||||
labs := label.NewSet(lcopy...)
|
||||
|
||||
var agg, ckpt metricsdk.Aggregator
|
||||
|
@ -18,10 +18,10 @@ import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/exporters/stdout"
|
||||
"go.opentelemetry.io/otel/global"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
@ -38,11 +38,11 @@ var (
|
||||
|
||||
meter = global.MeterProvider().Meter(
|
||||
instrumentationName,
|
||||
otel.WithInstrumentationVersion(instrumentationVersion),
|
||||
metric.WithInstrumentationVersion(instrumentationVersion),
|
||||
)
|
||||
|
||||
loopCounter = otel.Must(meter).NewInt64Counter("function.loops")
|
||||
paramValue = otel.Must(meter).NewInt64ValueRecorder("function.param")
|
||||
loopCounter = metric.Must(meter).NewInt64Counter("function.loops")
|
||||
paramValue = metric.Must(meter).NewInt64ValueRecorder("function.param")
|
||||
|
||||
nameKey = label.Key("function.name")
|
||||
)
|
||||
|
@ -21,8 +21,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
exportmetric "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
)
|
||||
@ -52,7 +52,7 @@ type quantile struct {
|
||||
Value interface{} `json:"Value"`
|
||||
}
|
||||
|
||||
func (e *metricExporter) ExportKindFor(desc *otel.Descriptor, kind aggregation.Kind) exportmetric.ExportKind {
|
||||
func (e *metricExporter) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) exportmetric.ExportKind {
|
||||
return exportmetric.StatelessExportKindSelector().ExportKindFor(desc, kind)
|
||||
}
|
||||
|
||||
|
@ -26,9 +26,9 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/exporters/stdout"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
@ -100,7 +100,7 @@ func TestStdoutTimestamp(t *testing.T) {
|
||||
checkpointSet := metrictest.NewCheckpointSet(testResource)
|
||||
|
||||
ctx := context.Background()
|
||||
desc := otel.NewDescriptor("test.name", otel.ValueObserverInstrumentKind, number.Int64Kind)
|
||||
desc := metric.NewDescriptor("test.name", metric.ValueObserverInstrumentKind, number.Int64Kind)
|
||||
|
||||
lvagg, ckpt := metrictest.Unslice2(lastvalue.New(2))
|
||||
|
||||
@ -139,7 +139,7 @@ func TestStdoutCounterFormat(t *testing.T) {
|
||||
|
||||
checkpointSet := metrictest.NewCheckpointSet(testResource)
|
||||
|
||||
desc := otel.NewDescriptor("test.name", otel.CounterInstrumentKind, number.Int64Kind)
|
||||
desc := metric.NewDescriptor("test.name", metric.CounterInstrumentKind, number.Int64Kind)
|
||||
|
||||
cagg, ckpt := metrictest.Unslice2(sum.New(2))
|
||||
|
||||
@ -158,7 +158,7 @@ func TestStdoutLastValueFormat(t *testing.T) {
|
||||
|
||||
checkpointSet := metrictest.NewCheckpointSet(testResource)
|
||||
|
||||
desc := otel.NewDescriptor("test.name", otel.ValueObserverInstrumentKind, number.Float64Kind)
|
||||
desc := metric.NewDescriptor("test.name", metric.ValueObserverInstrumentKind, number.Float64Kind)
|
||||
lvagg, ckpt := metrictest.Unslice2(lastvalue.New(2))
|
||||
|
||||
aggregatortest.CheckedUpdate(fix.t, lvagg, number.NewFloat64Number(123.456), &desc)
|
||||
@ -176,7 +176,7 @@ func TestStdoutMinMaxSumCount(t *testing.T) {
|
||||
|
||||
checkpointSet := metrictest.NewCheckpointSet(testResource)
|
||||
|
||||
desc := otel.NewDescriptor("test.name", otel.ValueRecorderInstrumentKind, number.Float64Kind)
|
||||
desc := metric.NewDescriptor("test.name", metric.ValueRecorderInstrumentKind, number.Float64Kind)
|
||||
|
||||
magg, ckpt := metrictest.Unslice2(minmaxsumcount.New(2, &desc))
|
||||
|
||||
@ -196,7 +196,7 @@ func TestStdoutValueRecorderFormat(t *testing.T) {
|
||||
|
||||
checkpointSet := metrictest.NewCheckpointSet(testResource)
|
||||
|
||||
desc := otel.NewDescriptor("test.name", otel.ValueRecorderInstrumentKind, number.Float64Kind)
|
||||
desc := metric.NewDescriptor("test.name", metric.ValueRecorderInstrumentKind, number.Float64Kind)
|
||||
aagg, ckpt := metrictest.Unslice2(array.New(2))
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
@ -235,7 +235,7 @@ func TestStdoutValueRecorderFormat(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStdoutNoData(t *testing.T) {
|
||||
desc := otel.NewDescriptor("test.name", otel.ValueRecorderInstrumentKind, number.Float64Kind)
|
||||
desc := metric.NewDescriptor("test.name", metric.ValueRecorderInstrumentKind, number.Float64Kind)
|
||||
|
||||
runTwoAggs := func(agg, ckpt export.Aggregator) {
|
||||
t.Run(fmt.Sprintf("%T", agg), func(t *testing.T) {
|
||||
@ -264,7 +264,7 @@ func TestStdoutLastValueNotSet(t *testing.T) {
|
||||
|
||||
checkpointSet := metrictest.NewCheckpointSet(testResource)
|
||||
|
||||
desc := otel.NewDescriptor("test.name", otel.ValueObserverInstrumentKind, number.Float64Kind)
|
||||
desc := metric.NewDescriptor("test.name", metric.ValueObserverInstrumentKind, number.Float64Kind)
|
||||
|
||||
lvagg, ckpt := metrictest.Unslice2(lastvalue.New(2))
|
||||
require.NoError(t, lvagg.SynchronizedMove(ckpt, &desc))
|
||||
@ -315,7 +315,7 @@ func TestStdoutResource(t *testing.T) {
|
||||
|
||||
checkpointSet := metrictest.NewCheckpointSet(tc.res)
|
||||
|
||||
desc := otel.NewDescriptor("test.name", otel.ValueObserverInstrumentKind, number.Float64Kind)
|
||||
desc := metric.NewDescriptor("test.name", metric.ValueObserverInstrumentKind, number.Float64Kind)
|
||||
lvagg, ckpt := metrictest.Unslice2(lastvalue.New(2))
|
||||
|
||||
aggregatortest.CheckedUpdate(fix.t, lvagg, number.NewFloat64Number(123.456), &desc)
|
||||
|
@ -20,8 +20,8 @@ import (
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
"go.opentelemetry.io/otel/metric/registry"
|
||||
)
|
||||
@ -52,7 +52,7 @@ type meterKey struct {
|
||||
}
|
||||
|
||||
type meterProvider struct {
|
||||
delegate otel.MeterProvider
|
||||
delegate metric.MeterProvider
|
||||
|
||||
// lock protects `delegate` and `meters`.
|
||||
lock sync.Mutex
|
||||
@ -63,7 +63,7 @@ type meterProvider struct {
|
||||
}
|
||||
|
||||
type meterImpl struct {
|
||||
delegate unsafe.Pointer // (*otel.MeterImpl)
|
||||
delegate unsafe.Pointer // (*metric.MeterImpl)
|
||||
|
||||
lock sync.Mutex
|
||||
syncInsts []*syncImpl
|
||||
@ -71,42 +71,42 @@ type meterImpl struct {
|
||||
}
|
||||
|
||||
type meterEntry struct {
|
||||
unique otel.MeterImpl
|
||||
unique metric.MeterImpl
|
||||
impl meterImpl
|
||||
}
|
||||
|
||||
type instrument struct {
|
||||
descriptor otel.Descriptor
|
||||
descriptor metric.Descriptor
|
||||
}
|
||||
|
||||
type syncImpl struct {
|
||||
delegate unsafe.Pointer // (*otel.SyncImpl)
|
||||
delegate unsafe.Pointer // (*metric.SyncImpl)
|
||||
|
||||
instrument
|
||||
}
|
||||
|
||||
type asyncImpl struct {
|
||||
delegate unsafe.Pointer // (*otel.AsyncImpl)
|
||||
delegate unsafe.Pointer // (*metric.AsyncImpl)
|
||||
|
||||
instrument
|
||||
|
||||
runner otel.AsyncRunner
|
||||
runner metric.AsyncRunner
|
||||
}
|
||||
|
||||
// SyncImpler is implemented by all of the sync metric
|
||||
// instruments.
|
||||
type SyncImpler interface {
|
||||
SyncImpl() otel.SyncImpl
|
||||
SyncImpl() metric.SyncImpl
|
||||
}
|
||||
|
||||
// AsyncImpler is implemented by all of the async
|
||||
// metric instruments.
|
||||
type AsyncImpler interface {
|
||||
AsyncImpl() otel.AsyncImpl
|
||||
AsyncImpl() metric.AsyncImpl
|
||||
}
|
||||
|
||||
type syncHandle struct {
|
||||
delegate unsafe.Pointer // (*otel.HandleImpl)
|
||||
delegate unsafe.Pointer // (*metric.BoundInstrumentImpl)
|
||||
|
||||
inst *syncImpl
|
||||
labels []label.KeyValue
|
||||
@ -114,13 +114,13 @@ type syncHandle struct {
|
||||
initialize sync.Once
|
||||
}
|
||||
|
||||
var _ otel.MeterProvider = &meterProvider{}
|
||||
var _ otel.MeterImpl = &meterImpl{}
|
||||
var _ otel.InstrumentImpl = &syncImpl{}
|
||||
var _ otel.BoundSyncImpl = &syncHandle{}
|
||||
var _ otel.AsyncImpl = &asyncImpl{}
|
||||
var _ metric.MeterProvider = &meterProvider{}
|
||||
var _ metric.MeterImpl = &meterImpl{}
|
||||
var _ metric.InstrumentImpl = &syncImpl{}
|
||||
var _ metric.BoundSyncImpl = &syncHandle{}
|
||||
var _ metric.AsyncImpl = &asyncImpl{}
|
||||
|
||||
func (inst *instrument) Descriptor() otel.Descriptor {
|
||||
func (inst *instrument) Descriptor() metric.Descriptor {
|
||||
return inst.descriptor
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ func newMeterProvider() *meterProvider {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *meterProvider) setDelegate(provider otel.MeterProvider) {
|
||||
func (p *meterProvider) setDelegate(provider metric.MeterProvider) {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
@ -143,7 +143,7 @@ func (p *meterProvider) setDelegate(provider otel.MeterProvider) {
|
||||
p.meters = nil
|
||||
}
|
||||
|
||||
func (p *meterProvider) Meter(instrumentationName string, opts ...otel.MeterOption) otel.Meter {
|
||||
func (p *meterProvider) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
@ -153,7 +153,7 @@ func (p *meterProvider) Meter(instrumentationName string, opts ...otel.MeterOpti
|
||||
|
||||
key := meterKey{
|
||||
Name: instrumentationName,
|
||||
Version: otel.NewMeterConfig(opts...).InstrumentationVersion,
|
||||
Version: metric.NewMeterConfig(opts...).InstrumentationVersion,
|
||||
}
|
||||
entry, ok := p.meters[key]
|
||||
if !ok {
|
||||
@ -162,17 +162,17 @@ func (p *meterProvider) Meter(instrumentationName string, opts ...otel.MeterOpti
|
||||
p.meters[key] = entry
|
||||
|
||||
}
|
||||
return otel.WrapMeterImpl(entry.unique, key.Name, otel.WithInstrumentationVersion(key.Version))
|
||||
return metric.WrapMeterImpl(entry.unique, key.Name, metric.WithInstrumentationVersion(key.Version))
|
||||
}
|
||||
|
||||
// Meter interface and delegation
|
||||
|
||||
func (m *meterImpl) setDelegate(name, version string, provider otel.MeterProvider) {
|
||||
func (m *meterImpl) setDelegate(name, version string, provider metric.MeterProvider) {
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
|
||||
d := new(otel.MeterImpl)
|
||||
*d = provider.Meter(name, otel.WithInstrumentationVersion(version)).MeterImpl()
|
||||
d := new(metric.MeterImpl)
|
||||
*d = provider.Meter(name, metric.WithInstrumentationVersion(version)).MeterImpl()
|
||||
m.delegate = unsafe.Pointer(d)
|
||||
|
||||
for _, inst := range m.syncInsts {
|
||||
@ -185,11 +185,11 @@ func (m *meterImpl) setDelegate(name, version string, provider otel.MeterProvide
|
||||
m.asyncInsts = nil
|
||||
}
|
||||
|
||||
func (m *meterImpl) NewSyncInstrument(desc otel.Descriptor) (otel.SyncImpl, error) {
|
||||
func (m *meterImpl) NewSyncInstrument(desc metric.Descriptor) (metric.SyncImpl, error) {
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
|
||||
if meterPtr := (*otel.MeterImpl)(atomic.LoadPointer(&m.delegate)); meterPtr != nil {
|
||||
if meterPtr := (*metric.MeterImpl)(atomic.LoadPointer(&m.delegate)); meterPtr != nil {
|
||||
return (*meterPtr).NewSyncInstrument(desc)
|
||||
}
|
||||
|
||||
@ -204,8 +204,8 @@ func (m *meterImpl) NewSyncInstrument(desc otel.Descriptor) (otel.SyncImpl, erro
|
||||
|
||||
// Synchronous delegation
|
||||
|
||||
func (inst *syncImpl) setDelegate(d otel.MeterImpl) {
|
||||
implPtr := new(otel.SyncImpl)
|
||||
func (inst *syncImpl) setDelegate(d metric.MeterImpl) {
|
||||
implPtr := new(metric.SyncImpl)
|
||||
|
||||
var err error
|
||||
*implPtr, err = d.NewSyncInstrument(inst.descriptor)
|
||||
@ -222,14 +222,14 @@ func (inst *syncImpl) setDelegate(d otel.MeterImpl) {
|
||||
}
|
||||
|
||||
func (inst *syncImpl) Implementation() interface{} {
|
||||
if implPtr := (*otel.SyncImpl)(atomic.LoadPointer(&inst.delegate)); implPtr != nil {
|
||||
if implPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); implPtr != nil {
|
||||
return (*implPtr).Implementation()
|
||||
}
|
||||
return inst
|
||||
}
|
||||
|
||||
func (inst *syncImpl) Bind(labels []label.KeyValue) otel.BoundSyncImpl {
|
||||
if implPtr := (*otel.SyncImpl)(atomic.LoadPointer(&inst.delegate)); implPtr != nil {
|
||||
func (inst *syncImpl) Bind(labels []label.KeyValue) metric.BoundSyncImpl {
|
||||
if implPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); implPtr != nil {
|
||||
return (*implPtr).Bind(labels)
|
||||
}
|
||||
return &syncHandle{
|
||||
@ -241,7 +241,7 @@ func (inst *syncImpl) Bind(labels []label.KeyValue) otel.BoundSyncImpl {
|
||||
func (bound *syncHandle) Unbind() {
|
||||
bound.initialize.Do(func() {})
|
||||
|
||||
implPtr := (*otel.BoundSyncImpl)(atomic.LoadPointer(&bound.delegate))
|
||||
implPtr := (*metric.BoundSyncImpl)(atomic.LoadPointer(&bound.delegate))
|
||||
|
||||
if implPtr == nil {
|
||||
return
|
||||
@ -253,14 +253,14 @@ func (bound *syncHandle) Unbind() {
|
||||
// Async delegation
|
||||
|
||||
func (m *meterImpl) NewAsyncInstrument(
|
||||
desc otel.Descriptor,
|
||||
runner otel.AsyncRunner,
|
||||
) (otel.AsyncImpl, error) {
|
||||
desc metric.Descriptor,
|
||||
runner metric.AsyncRunner,
|
||||
) (metric.AsyncImpl, error) {
|
||||
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
|
||||
if meterPtr := (*otel.MeterImpl)(atomic.LoadPointer(&m.delegate)); meterPtr != nil {
|
||||
if meterPtr := (*metric.MeterImpl)(atomic.LoadPointer(&m.delegate)); meterPtr != nil {
|
||||
return (*meterPtr).NewAsyncInstrument(desc, runner)
|
||||
}
|
||||
|
||||
@ -275,14 +275,14 @@ func (m *meterImpl) NewAsyncInstrument(
|
||||
}
|
||||
|
||||
func (obs *asyncImpl) Implementation() interface{} {
|
||||
if implPtr := (*otel.AsyncImpl)(atomic.LoadPointer(&obs.delegate)); implPtr != nil {
|
||||
if implPtr := (*metric.AsyncImpl)(atomic.LoadPointer(&obs.delegate)); implPtr != nil {
|
||||
return (*implPtr).Implementation()
|
||||
}
|
||||
return obs
|
||||
}
|
||||
|
||||
func (obs *asyncImpl) setDelegate(d otel.MeterImpl) {
|
||||
implPtr := new(otel.AsyncImpl)
|
||||
func (obs *asyncImpl) setDelegate(d metric.MeterImpl) {
|
||||
implPtr := new(metric.AsyncImpl)
|
||||
|
||||
var err error
|
||||
*implPtr, err = d.NewAsyncInstrument(obs.descriptor, obs.runner)
|
||||
@ -300,14 +300,14 @@ func (obs *asyncImpl) setDelegate(d otel.MeterImpl) {
|
||||
|
||||
// Metric updates
|
||||
|
||||
func (m *meterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, measurements ...otel.Measurement) {
|
||||
if delegatePtr := (*otel.MeterImpl)(atomic.LoadPointer(&m.delegate)); delegatePtr != nil {
|
||||
func (m *meterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, measurements ...metric.Measurement) {
|
||||
if delegatePtr := (*metric.MeterImpl)(atomic.LoadPointer(&m.delegate)); delegatePtr != nil {
|
||||
(*delegatePtr).RecordBatch(ctx, labels, measurements...)
|
||||
}
|
||||
}
|
||||
|
||||
func (inst *syncImpl) RecordOne(ctx context.Context, number number.Number, labels []label.KeyValue) {
|
||||
if instPtr := (*otel.SyncImpl)(atomic.LoadPointer(&inst.delegate)); instPtr != nil {
|
||||
if instPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); instPtr != nil {
|
||||
(*instPtr).RecordOne(ctx, number, labels)
|
||||
}
|
||||
}
|
||||
@ -315,18 +315,18 @@ func (inst *syncImpl) RecordOne(ctx context.Context, number number.Number, label
|
||||
// Bound instrument initialization
|
||||
|
||||
func (bound *syncHandle) RecordOne(ctx context.Context, number number.Number) {
|
||||
instPtr := (*otel.SyncImpl)(atomic.LoadPointer(&bound.inst.delegate))
|
||||
instPtr := (*metric.SyncImpl)(atomic.LoadPointer(&bound.inst.delegate))
|
||||
if instPtr == nil {
|
||||
return
|
||||
}
|
||||
var implPtr *otel.BoundSyncImpl
|
||||
var implPtr *metric.BoundSyncImpl
|
||||
bound.initialize.Do(func() {
|
||||
implPtr = new(otel.BoundSyncImpl)
|
||||
implPtr = new(metric.BoundSyncImpl)
|
||||
*implPtr = (*instPtr).Bind(bound.labels)
|
||||
atomic.StorePointer(&bound.delegate, unsafe.Pointer(implPtr))
|
||||
})
|
||||
if implPtr == nil {
|
||||
implPtr = (*otel.BoundSyncImpl)(atomic.LoadPointer(&bound.delegate))
|
||||
implPtr = (*metric.BoundSyncImpl)(atomic.LoadPointer(&bound.delegate))
|
||||
}
|
||||
// This may still be nil if instrument was created and bound
|
||||
// without a delegate, then the instrument was set to have a
|
||||
|
@ -21,15 +21,15 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/global"
|
||||
"go.opentelemetry.io/otel/global/internal"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
"go.opentelemetry.io/otel/oteltest"
|
||||
)
|
||||
|
||||
var Must = otel.Must
|
||||
var Must = metric.Must
|
||||
|
||||
var asInt = number.NewInt64Number
|
||||
var asFloat = number.NewFloat64Number
|
||||
@ -38,7 +38,7 @@ func TestDirect(t *testing.T) {
|
||||
internal.ResetForTest()
|
||||
|
||||
ctx := context.Background()
|
||||
meter1 := global.Meter("test1", otel.WithInstrumentationVersion("semver:v1.0.0"))
|
||||
meter1 := global.Meter("test1", metric.WithInstrumentationVersion("semver:v1.0.0"))
|
||||
meter2 := global.Meter("test2")
|
||||
labels1 := []label.KeyValue{label.String("A", "B")}
|
||||
labels2 := []label.KeyValue{label.String("C", "D")}
|
||||
@ -52,12 +52,12 @@ func TestDirect(t *testing.T) {
|
||||
valuerecorder.Record(ctx, 1, labels1...)
|
||||
valuerecorder.Record(ctx, 2, labels1...)
|
||||
|
||||
_ = Must(meter1).NewFloat64ValueObserver("test.valueobserver.float", func(_ context.Context, result otel.Float64ObserverResult) {
|
||||
_ = Must(meter1).NewFloat64ValueObserver("test.valueobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
|
||||
result.Observe(1., labels1...)
|
||||
result.Observe(2., labels2...)
|
||||
})
|
||||
|
||||
_ = Must(meter1).NewInt64ValueObserver("test.valueobserver.int", func(_ context.Context, result otel.Int64ObserverResult) {
|
||||
_ = Must(meter1).NewInt64ValueObserver("test.valueobserver.int", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||
result.Observe(1, labels1...)
|
||||
result.Observe(2, labels2...)
|
||||
})
|
||||
@ -214,19 +214,19 @@ func TestUnbindThenRecordOne(t *testing.T) {
|
||||
}
|
||||
|
||||
type meterProviderWithConstructorError struct {
|
||||
otel.MeterProvider
|
||||
metric.MeterProvider
|
||||
}
|
||||
|
||||
type meterWithConstructorError struct {
|
||||
otel.MeterImpl
|
||||
metric.MeterImpl
|
||||
}
|
||||
|
||||
func (m *meterProviderWithConstructorError) Meter(iName string, opts ...otel.MeterOption) otel.Meter {
|
||||
return otel.WrapMeterImpl(&meterWithConstructorError{m.MeterProvider.Meter(iName, opts...).MeterImpl()}, iName, opts...)
|
||||
func (m *meterProviderWithConstructorError) Meter(iName string, opts ...metric.MeterOption) metric.Meter {
|
||||
return metric.WrapMeterImpl(&meterWithConstructorError{m.MeterProvider.Meter(iName, opts...).MeterImpl()}, iName, opts...)
|
||||
}
|
||||
|
||||
func (m *meterWithConstructorError) NewSyncInstrument(_ otel.Descriptor) (otel.SyncImpl, error) {
|
||||
return otel.NoopSync{}, errors.New("constructor error")
|
||||
func (m *meterWithConstructorError) NewSyncInstrument(_ metric.Descriptor) (metric.SyncImpl, error) {
|
||||
return metric.NoopSync{}, errors.New("constructor error")
|
||||
}
|
||||
|
||||
func TestErrorInDeferredConstructor(t *testing.T) {
|
||||
@ -270,7 +270,7 @@ func TestImplementationIndirection(t *testing.T) {
|
||||
// Async: no SDK yet
|
||||
valueobserver := Must(meter1).NewFloat64ValueObserver(
|
||||
"interface.valueobserver",
|
||||
func(_ context.Context, result otel.Float64ObserverResult) {},
|
||||
func(_ context.Context, result metric.Float64ObserverResult) {},
|
||||
)
|
||||
|
||||
ival = valueobserver.AsyncImpl().Implementation()
|
||||
|
@ -21,48 +21,48 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/registry"
|
||||
)
|
||||
|
||||
type (
|
||||
newFunc func(name, libraryName string) (otel.InstrumentImpl, error)
|
||||
newFunc func(name, libraryName string) (metric.InstrumentImpl, error)
|
||||
)
|
||||
|
||||
var (
|
||||
allNew = map[string]newFunc{
|
||||
"counter.int64": func(name, libraryName string) (otel.InstrumentImpl, error) {
|
||||
"counter.int64": func(name, libraryName string) (metric.InstrumentImpl, error) {
|
||||
return unwrap(MeterProvider().Meter(libraryName).NewInt64Counter(name))
|
||||
},
|
||||
"counter.float64": func(name, libraryName string) (otel.InstrumentImpl, error) {
|
||||
"counter.float64": func(name, libraryName string) (metric.InstrumentImpl, error) {
|
||||
return unwrap(MeterProvider().Meter(libraryName).NewFloat64Counter(name))
|
||||
},
|
||||
"valuerecorder.int64": func(name, libraryName string) (otel.InstrumentImpl, error) {
|
||||
"valuerecorder.int64": func(name, libraryName string) (metric.InstrumentImpl, error) {
|
||||
return unwrap(MeterProvider().Meter(libraryName).NewInt64ValueRecorder(name))
|
||||
},
|
||||
"valuerecorder.float64": func(name, libraryName string) (otel.InstrumentImpl, error) {
|
||||
"valuerecorder.float64": func(name, libraryName string) (metric.InstrumentImpl, error) {
|
||||
return unwrap(MeterProvider().Meter(libraryName).NewFloat64ValueRecorder(name))
|
||||
},
|
||||
"valueobserver.int64": func(name, libraryName string) (otel.InstrumentImpl, error) {
|
||||
return unwrap(MeterProvider().Meter(libraryName).NewInt64ValueObserver(name, func(context.Context, otel.Int64ObserverResult) {}))
|
||||
"valueobserver.int64": func(name, libraryName string) (metric.InstrumentImpl, error) {
|
||||
return unwrap(MeterProvider().Meter(libraryName).NewInt64ValueObserver(name, func(context.Context, metric.Int64ObserverResult) {}))
|
||||
},
|
||||
"valueobserver.float64": func(name, libraryName string) (otel.InstrumentImpl, error) {
|
||||
return unwrap(MeterProvider().Meter(libraryName).NewFloat64ValueObserver(name, func(context.Context, otel.Float64ObserverResult) {}))
|
||||
"valueobserver.float64": func(name, libraryName string) (metric.InstrumentImpl, error) {
|
||||
return unwrap(MeterProvider().Meter(libraryName).NewFloat64ValueObserver(name, func(context.Context, metric.Float64ObserverResult) {}))
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func unwrap(impl interface{}, err error) (otel.InstrumentImpl, error) {
|
||||
func unwrap(impl interface{}, err error) (metric.InstrumentImpl, error) {
|
||||
if impl == nil {
|
||||
return nil, err
|
||||
}
|
||||
if s, ok := impl.(interface {
|
||||
SyncImpl() otel.SyncImpl
|
||||
SyncImpl() metric.SyncImpl
|
||||
}); ok {
|
||||
return s.SyncImpl(), err
|
||||
}
|
||||
if a, ok := impl.(interface {
|
||||
AsyncImpl() otel.AsyncImpl
|
||||
AsyncImpl() metric.AsyncImpl
|
||||
}); ok {
|
||||
return a.AsyncImpl(), err
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import (
|
||||
"sync/atomic"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
@ -28,7 +29,7 @@ type (
|
||||
}
|
||||
|
||||
meterProviderHolder struct {
|
||||
mp otel.MeterProvider
|
||||
mp metric.MeterProvider
|
||||
}
|
||||
|
||||
propagatorsHolder struct {
|
||||
@ -69,12 +70,12 @@ func SetTracerProvider(tp trace.TracerProvider) {
|
||||
}
|
||||
|
||||
// MeterProvider is the internal implementation for global.MeterProvider.
|
||||
func MeterProvider() otel.MeterProvider {
|
||||
func MeterProvider() metric.MeterProvider {
|
||||
return globalMeter.Load().(meterProviderHolder).mp
|
||||
}
|
||||
|
||||
// SetMeterProvider is the internal implementation for global.SetMeterProvider.
|
||||
func SetMeterProvider(mp otel.MeterProvider) {
|
||||
func SetMeterProvider(mp metric.MeterProvider) {
|
||||
delegateMeterOnce.Do(func() {
|
||||
current := MeterProvider()
|
||||
|
||||
|
@ -15,8 +15,8 @@
|
||||
package global // import "go.opentelemetry.io/otel/global"
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/global/internal"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
)
|
||||
|
||||
// Meter creates an implementation of the Meter interface from the global
|
||||
@ -27,7 +27,7 @@ import (
|
||||
// will be used instead.
|
||||
//
|
||||
// This is short for MeterProvider().Meter(name)
|
||||
func Meter(instrumentationName string, opts ...otel.MeterOption) otel.Meter {
|
||||
func Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter {
|
||||
return MeterProvider().Meter(instrumentationName, opts...)
|
||||
}
|
||||
|
||||
@ -39,11 +39,11 @@ func Meter(instrumentationName string, opts ...otel.MeterOption) otel.Meter {
|
||||
// meter := global.MeterProvider().Meter("example.com/foo")
|
||||
// or
|
||||
// meter := global.Meter("example.com/foo")
|
||||
func MeterProvider() otel.MeterProvider {
|
||||
func MeterProvider() metric.MeterProvider {
|
||||
return internal.MeterProvider()
|
||||
}
|
||||
|
||||
// SetMeterProvider registers `mp` as the global meter provider.
|
||||
func SetMeterProvider(mp otel.MeterProvider) {
|
||||
func SetMeterProvider(mp metric.MeterProvider) {
|
||||
internal.SetMeterProvider(mp)
|
||||
}
|
||||
|
@ -17,21 +17,21 @@ package global_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/global"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
)
|
||||
|
||||
type testMeterProvider struct{}
|
||||
|
||||
var _ otel.MeterProvider = &testMeterProvider{}
|
||||
var _ metric.MeterProvider = &testMeterProvider{}
|
||||
|
||||
func (*testMeterProvider) Meter(_ string, _ ...otel.MeterOption) otel.Meter {
|
||||
return otel.Meter{}
|
||||
func (*testMeterProvider) Meter(_ string, _ ...metric.MeterOption) metric.Meter {
|
||||
return metric.Meter{}
|
||||
}
|
||||
|
||||
func TestMultipleGlobalMeterProvider(t *testing.T) {
|
||||
p1 := testMeterProvider{}
|
||||
p2 := otel.NoopMeterProvider{}
|
||||
p2 := metric.NoopMeterProvider{}
|
||||
global.SetMeterProvider(&p1)
|
||||
global.SetMeterProvider(&p2)
|
||||
|
||||
|
@ -20,9 +20,9 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
api "go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/global"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
)
|
||||
|
||||
var ErrInvalidAsyncRunner = errors.New("unknown async runner type")
|
||||
@ -32,7 +32,7 @@ var ErrInvalidAsyncRunner = errors.New("unknown async runner type")
|
||||
// the SDK to provide support for running observer callbacks.
|
||||
type AsyncCollector interface {
|
||||
// CollectAsync passes a batch of observations to the MeterImpl.
|
||||
CollectAsync(labels []label.KeyValue, observation ...api.Observation)
|
||||
CollectAsync(labels []label.KeyValue, observation ...metric.Observation)
|
||||
}
|
||||
|
||||
// AsyncInstrumentState manages an ordered set of asynchronous
|
||||
@ -60,18 +60,18 @@ type AsyncInstrumentState struct {
|
||||
|
||||
// instruments maintains the set of instruments in the order
|
||||
// they were registered.
|
||||
instruments []api.AsyncImpl
|
||||
instruments []metric.AsyncImpl
|
||||
}
|
||||
|
||||
// asyncRunnerPair is a map entry for Observer callback runners.
|
||||
type asyncRunnerPair struct {
|
||||
// runner is used as a map key here. The API ensures
|
||||
// that all callbacks are pointers for this reason.
|
||||
runner api.AsyncRunner
|
||||
runner metric.AsyncRunner
|
||||
|
||||
// inst refers to a non-nil instrument when `runner` is a
|
||||
// AsyncSingleRunner.
|
||||
inst api.AsyncImpl
|
||||
inst metric.AsyncImpl
|
||||
}
|
||||
|
||||
// NewAsyncInstrumentState returns a new *AsyncInstrumentState, for
|
||||
@ -86,7 +86,7 @@ func NewAsyncInstrumentState() *AsyncInstrumentState {
|
||||
// Instruments returns the asynchronous instruments managed by this
|
||||
// object, the set that should be checkpointed after observers are
|
||||
// run.
|
||||
func (a *AsyncInstrumentState) Instruments() []api.AsyncImpl {
|
||||
func (a *AsyncInstrumentState) Instruments() []metric.AsyncImpl {
|
||||
a.lock.Lock()
|
||||
defer a.lock.Unlock()
|
||||
return a.instruments
|
||||
@ -96,7 +96,7 @@ func (a *AsyncInstrumentState) Instruments() []api.AsyncImpl {
|
||||
// object. This should be called during NewAsyncInstrument() and
|
||||
// assumes that errors (e.g., duplicate registration) have already
|
||||
// been checked.
|
||||
func (a *AsyncInstrumentState) Register(inst api.AsyncImpl, runner api.AsyncRunner) {
|
||||
func (a *AsyncInstrumentState) Register(inst metric.AsyncImpl, runner metric.AsyncRunner) {
|
||||
a.lock.Lock()
|
||||
defer a.lock.Unlock()
|
||||
|
||||
@ -110,7 +110,7 @@ func (a *AsyncInstrumentState) Register(inst api.AsyncImpl, runner api.AsyncRunn
|
||||
rp := asyncRunnerPair{
|
||||
runner: runner,
|
||||
}
|
||||
if _, ok := runner.(api.AsyncSingleRunner); ok {
|
||||
if _, ok := runner.(metric.AsyncSingleRunner); ok {
|
||||
rp.inst = inst
|
||||
}
|
||||
|
||||
@ -131,12 +131,12 @@ func (a *AsyncInstrumentState) Run(ctx context.Context, collector AsyncCollector
|
||||
// other implementations are possible because the
|
||||
// interface has un-exported methods.
|
||||
|
||||
if singleRunner, ok := rp.runner.(api.AsyncSingleRunner); ok {
|
||||
if singleRunner, ok := rp.runner.(metric.AsyncSingleRunner); ok {
|
||||
singleRunner.Run(ctx, rp.inst, collector.CollectAsync)
|
||||
continue
|
||||
}
|
||||
|
||||
if multiRunner, ok := rp.runner.(api.AsyncBatchRunner); ok {
|
||||
if multiRunner, ok := rp.runner.(metric.AsyncBatchRunner); ok {
|
||||
multiRunner.Run(ctx, collector.CollectAsync)
|
||||
continue
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otel
|
||||
package metric
|
||||
|
||||
import (
|
||||
"os"
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otel // import "go.opentelemetry.io/otel"
|
||||
package metric // import "go.opentelemetry.io/otel/metric"
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/otel/unit"
|
@ -1,6 +1,6 @@
|
||||
// Code generated by "stringer -type=InstrumentKind"; DO NOT EDIT.
|
||||
|
||||
package otel
|
||||
package metric
|
||||
|
||||
import "strconv"
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otel // import "go.opentelemetry.io/otel"
|
||||
package metric // import "go.opentelemetry.io/otel/metric"
|
||||
|
||||
import (
|
||||
"context"
|
@ -14,7 +14,7 @@
|
||||
|
||||
//go:generate stringer -type=InstrumentKind
|
||||
|
||||
package otel // import "go.opentelemetry.io/otel"
|
||||
package metric // import "go.opentelemetry.io/otel/metric"
|
||||
|
||||
import (
|
||||
"context"
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otel // import "go.opentelemetry.io/otel"
|
||||
package metric // import "go.opentelemetry.io/otel/metric"
|
||||
|
||||
import (
|
||||
"context"
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otel // import "go.opentelemetry.io/otel"
|
||||
package metric // import "go.opentelemetry.io/otel/metric"
|
||||
|
||||
import (
|
||||
"context"
|
@ -12,15 +12,15 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otel_test
|
||||
package metric_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
"go.opentelemetry.io/otel/oteltest"
|
||||
"go.opentelemetry.io/otel/unit"
|
||||
@ -30,52 +30,52 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var Must = otel.Must
|
||||
var Must = metric.Must
|
||||
|
||||
var (
|
||||
syncKinds = []otel.InstrumentKind{
|
||||
otel.ValueRecorderInstrumentKind,
|
||||
otel.CounterInstrumentKind,
|
||||
otel.UpDownCounterInstrumentKind,
|
||||
syncKinds = []metric.InstrumentKind{
|
||||
metric.ValueRecorderInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
metric.UpDownCounterInstrumentKind,
|
||||
}
|
||||
asyncKinds = []otel.InstrumentKind{
|
||||
otel.ValueObserverInstrumentKind,
|
||||
otel.SumObserverInstrumentKind,
|
||||
otel.UpDownSumObserverInstrumentKind,
|
||||
asyncKinds = []metric.InstrumentKind{
|
||||
metric.ValueObserverInstrumentKind,
|
||||
metric.SumObserverInstrumentKind,
|
||||
metric.UpDownSumObserverInstrumentKind,
|
||||
}
|
||||
addingKinds = []otel.InstrumentKind{
|
||||
otel.CounterInstrumentKind,
|
||||
otel.UpDownCounterInstrumentKind,
|
||||
otel.SumObserverInstrumentKind,
|
||||
otel.UpDownSumObserverInstrumentKind,
|
||||
addingKinds = []metric.InstrumentKind{
|
||||
metric.CounterInstrumentKind,
|
||||
metric.UpDownCounterInstrumentKind,
|
||||
metric.SumObserverInstrumentKind,
|
||||
metric.UpDownSumObserverInstrumentKind,
|
||||
}
|
||||
groupingKinds = []otel.InstrumentKind{
|
||||
otel.ValueRecorderInstrumentKind,
|
||||
otel.ValueObserverInstrumentKind,
|
||||
groupingKinds = []metric.InstrumentKind{
|
||||
metric.ValueRecorderInstrumentKind,
|
||||
metric.ValueObserverInstrumentKind,
|
||||
}
|
||||
|
||||
monotonicKinds = []otel.InstrumentKind{
|
||||
otel.CounterInstrumentKind,
|
||||
otel.SumObserverInstrumentKind,
|
||||
monotonicKinds = []metric.InstrumentKind{
|
||||
metric.CounterInstrumentKind,
|
||||
metric.SumObserverInstrumentKind,
|
||||
}
|
||||
|
||||
nonMonotonicKinds = []otel.InstrumentKind{
|
||||
otel.UpDownCounterInstrumentKind,
|
||||
otel.UpDownSumObserverInstrumentKind,
|
||||
otel.ValueRecorderInstrumentKind,
|
||||
otel.ValueObserverInstrumentKind,
|
||||
nonMonotonicKinds = []metric.InstrumentKind{
|
||||
metric.UpDownCounterInstrumentKind,
|
||||
metric.UpDownSumObserverInstrumentKind,
|
||||
metric.ValueRecorderInstrumentKind,
|
||||
metric.ValueObserverInstrumentKind,
|
||||
}
|
||||
|
||||
precomputedSumKinds = []otel.InstrumentKind{
|
||||
otel.SumObserverInstrumentKind,
|
||||
otel.UpDownSumObserverInstrumentKind,
|
||||
precomputedSumKinds = []metric.InstrumentKind{
|
||||
metric.SumObserverInstrumentKind,
|
||||
metric.UpDownSumObserverInstrumentKind,
|
||||
}
|
||||
|
||||
nonPrecomputedSumKinds = []otel.InstrumentKind{
|
||||
otel.CounterInstrumentKind,
|
||||
otel.UpDownCounterInstrumentKind,
|
||||
otel.ValueRecorderInstrumentKind,
|
||||
otel.ValueObserverInstrumentKind,
|
||||
nonPrecomputedSumKinds = []metric.InstrumentKind{
|
||||
metric.CounterInstrumentKind,
|
||||
metric.UpDownCounterInstrumentKind,
|
||||
metric.ValueRecorderInstrumentKind,
|
||||
metric.ValueObserverInstrumentKind,
|
||||
}
|
||||
)
|
||||
|
||||
@ -119,7 +119,7 @@ func TestPrecomputedSum(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func checkSyncBatches(ctx context.Context, t *testing.T, labels []label.KeyValue, mock *oteltest.MeterImpl, nkind number.Kind, mkind otel.InstrumentKind, instrument otel.InstrumentImpl, expected ...float64) {
|
||||
func checkSyncBatches(ctx context.Context, t *testing.T, labels []label.KeyValue, mock *oteltest.MeterImpl, nkind number.Kind, mkind metric.InstrumentKind, instrument metric.InstrumentImpl, expected ...float64) {
|
||||
t.Helper()
|
||||
|
||||
batchesCount := len(mock.MeasurementBatches)
|
||||
@ -149,7 +149,7 @@ func checkSyncBatches(ctx context.Context, t *testing.T, labels []label.KeyValue
|
||||
func TestOptions(t *testing.T) {
|
||||
type testcase struct {
|
||||
name string
|
||||
opts []otel.InstrumentOption
|
||||
opts []metric.InstrumentOption
|
||||
desc string
|
||||
unit unit.Unit
|
||||
}
|
||||
@ -162,34 +162,34 @@ func TestOptions(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "description",
|
||||
opts: []otel.InstrumentOption{
|
||||
otel.WithDescription("stuff"),
|
||||
opts: []metric.InstrumentOption{
|
||||
metric.WithDescription("stuff"),
|
||||
},
|
||||
desc: "stuff",
|
||||
unit: "",
|
||||
},
|
||||
{
|
||||
name: "description override",
|
||||
opts: []otel.InstrumentOption{
|
||||
otel.WithDescription("stuff"),
|
||||
otel.WithDescription("things"),
|
||||
opts: []metric.InstrumentOption{
|
||||
metric.WithDescription("stuff"),
|
||||
metric.WithDescription("things"),
|
||||
},
|
||||
desc: "things",
|
||||
unit: "",
|
||||
},
|
||||
{
|
||||
name: "unit",
|
||||
opts: []otel.InstrumentOption{
|
||||
otel.WithUnit("s"),
|
||||
opts: []metric.InstrumentOption{
|
||||
metric.WithUnit("s"),
|
||||
},
|
||||
desc: "",
|
||||
unit: "s",
|
||||
},
|
||||
{
|
||||
name: "unit override",
|
||||
opts: []otel.InstrumentOption{
|
||||
otel.WithUnit("s"),
|
||||
otel.WithUnit("h"),
|
||||
opts: []metric.InstrumentOption{
|
||||
metric.WithUnit("s"),
|
||||
metric.WithUnit("h"),
|
||||
},
|
||||
desc: "",
|
||||
unit: "h",
|
||||
@ -197,7 +197,7 @@ func TestOptions(t *testing.T) {
|
||||
}
|
||||
for idx, tt := range testcases {
|
||||
t.Logf("Testing counter case %s (%d)", tt.name, idx)
|
||||
if diff := cmp.Diff(otel.NewInstrumentConfig(tt.opts...), otel.InstrumentConfig{
|
||||
if diff := cmp.Diff(metric.NewInstrumentConfig(tt.opts...), metric.InstrumentConfig{
|
||||
Description: tt.desc,
|
||||
Unit: tt.unit,
|
||||
}); diff != "" {
|
||||
@ -218,7 +218,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, number.Float64Kind, otel.CounterInstrumentKind, c.SyncImpl(),
|
||||
checkSyncBatches(ctx, t, labels, mockSDK, number.Float64Kind, metric.CounterInstrumentKind, c.SyncImpl(),
|
||||
1994.1, -742, 42,
|
||||
)
|
||||
})
|
||||
@ -231,7 +231,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, number.Int64Kind, otel.CounterInstrumentKind, c.SyncImpl(),
|
||||
checkSyncBatches(ctx, t, labels, mockSDK, number.Int64Kind, metric.CounterInstrumentKind, c.SyncImpl(),
|
||||
42, 4200, 420000,
|
||||
)
|
||||
|
||||
@ -245,7 +245,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, number.Int64Kind, otel.UpDownCounterInstrumentKind, c.SyncImpl(),
|
||||
checkSyncBatches(ctx, t, labels, mockSDK, number.Int64Kind, metric.UpDownCounterInstrumentKind, c.SyncImpl(),
|
||||
100, -100, 42,
|
||||
)
|
||||
})
|
||||
@ -258,7 +258,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, number.Float64Kind, otel.UpDownCounterInstrumentKind, c.SyncImpl(),
|
||||
checkSyncBatches(ctx, t, labels, mockSDK, number.Float64Kind, metric.UpDownCounterInstrumentKind, c.SyncImpl(),
|
||||
100.1, -76, -100.1,
|
||||
)
|
||||
})
|
||||
@ -274,7 +274,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, number.Float64Kind, otel.ValueRecorderInstrumentKind, m.SyncImpl(),
|
||||
checkSyncBatches(ctx, t, labels, mockSDK, number.Float64Kind, metric.ValueRecorderInstrumentKind, m.SyncImpl(),
|
||||
42, 0, -100.5,
|
||||
)
|
||||
})
|
||||
@ -287,7 +287,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, number.Int64Kind, otel.ValueRecorderInstrumentKind, m.SyncImpl(),
|
||||
checkSyncBatches(ctx, t, labels, mockSDK, number.Int64Kind, metric.ValueRecorderInstrumentKind, m.SyncImpl(),
|
||||
173, 80, 0,
|
||||
)
|
||||
})
|
||||
@ -297,66 +297,66 @@ func TestObserverInstruments(t *testing.T) {
|
||||
t.Run("float valueobserver", func(t *testing.T) {
|
||||
labels := []label.KeyValue{label.String("O", "P")}
|
||||
mockSDK, meter := oteltest.NewMeter()
|
||||
o := Must(meter).NewFloat64ValueObserver("test.valueobserver.float", func(_ context.Context, result otel.Float64ObserverResult) {
|
||||
o := Must(meter).NewFloat64ValueObserver("test.valueobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
|
||||
result.Observe(42.1, labels...)
|
||||
})
|
||||
mockSDK.RunAsyncInstruments()
|
||||
checkObserverBatch(t, labels, mockSDK, number.Float64Kind, otel.ValueObserverInstrumentKind, o.AsyncImpl(),
|
||||
checkObserverBatch(t, labels, mockSDK, number.Float64Kind, metric.ValueObserverInstrumentKind, o.AsyncImpl(),
|
||||
42.1,
|
||||
)
|
||||
})
|
||||
t.Run("int valueobserver", func(t *testing.T) {
|
||||
labels := []label.KeyValue{}
|
||||
mockSDK, meter := oteltest.NewMeter()
|
||||
o := Must(meter).NewInt64ValueObserver("test.observer.int", func(_ context.Context, result otel.Int64ObserverResult) {
|
||||
o := Must(meter).NewInt64ValueObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||
result.Observe(-142, labels...)
|
||||
})
|
||||
mockSDK.RunAsyncInstruments()
|
||||
checkObserverBatch(t, labels, mockSDK, number.Int64Kind, otel.ValueObserverInstrumentKind, o.AsyncImpl(),
|
||||
checkObserverBatch(t, labels, mockSDK, number.Int64Kind, metric.ValueObserverInstrumentKind, o.AsyncImpl(),
|
||||
-142,
|
||||
)
|
||||
})
|
||||
t.Run("float sumobserver", func(t *testing.T) {
|
||||
labels := []label.KeyValue{label.String("O", "P")}
|
||||
mockSDK, meter := oteltest.NewMeter()
|
||||
o := Must(meter).NewFloat64SumObserver("test.sumobserver.float", func(_ context.Context, result otel.Float64ObserverResult) {
|
||||
o := Must(meter).NewFloat64SumObserver("test.sumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
|
||||
result.Observe(42.1, labels...)
|
||||
})
|
||||
mockSDK.RunAsyncInstruments()
|
||||
checkObserverBatch(t, labels, mockSDK, number.Float64Kind, otel.SumObserverInstrumentKind, o.AsyncImpl(),
|
||||
checkObserverBatch(t, labels, mockSDK, number.Float64Kind, metric.SumObserverInstrumentKind, o.AsyncImpl(),
|
||||
42.1,
|
||||
)
|
||||
})
|
||||
t.Run("int sumobserver", func(t *testing.T) {
|
||||
labels := []label.KeyValue{}
|
||||
mockSDK, meter := oteltest.NewMeter()
|
||||
o := Must(meter).NewInt64SumObserver("test.observer.int", func(_ context.Context, result otel.Int64ObserverResult) {
|
||||
o := Must(meter).NewInt64SumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||
result.Observe(-142, labels...)
|
||||
})
|
||||
mockSDK.RunAsyncInstruments()
|
||||
checkObserverBatch(t, labels, mockSDK, number.Int64Kind, otel.SumObserverInstrumentKind, o.AsyncImpl(),
|
||||
checkObserverBatch(t, labels, mockSDK, number.Int64Kind, metric.SumObserverInstrumentKind, o.AsyncImpl(),
|
||||
-142,
|
||||
)
|
||||
})
|
||||
t.Run("float updownsumobserver", func(t *testing.T) {
|
||||
labels := []label.KeyValue{label.String("O", "P")}
|
||||
mockSDK, meter := oteltest.NewMeter()
|
||||
o := Must(meter).NewFloat64UpDownSumObserver("test.updownsumobserver.float", func(_ context.Context, result otel.Float64ObserverResult) {
|
||||
o := Must(meter).NewFloat64UpDownSumObserver("test.updownsumobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
|
||||
result.Observe(42.1, labels...)
|
||||
})
|
||||
mockSDK.RunAsyncInstruments()
|
||||
checkObserverBatch(t, labels, mockSDK, number.Float64Kind, otel.UpDownSumObserverInstrumentKind, o.AsyncImpl(),
|
||||
checkObserverBatch(t, labels, mockSDK, number.Float64Kind, metric.UpDownSumObserverInstrumentKind, o.AsyncImpl(),
|
||||
42.1,
|
||||
)
|
||||
})
|
||||
t.Run("int updownsumobserver", func(t *testing.T) {
|
||||
labels := []label.KeyValue{}
|
||||
mockSDK, meter := oteltest.NewMeter()
|
||||
o := Must(meter).NewInt64UpDownSumObserver("test.observer.int", func(_ context.Context, result otel.Int64ObserverResult) {
|
||||
o := Must(meter).NewInt64UpDownSumObserver("test.observer.int", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||
result.Observe(-142, labels...)
|
||||
})
|
||||
mockSDK.RunAsyncInstruments()
|
||||
checkObserverBatch(t, labels, mockSDK, number.Int64Kind, otel.UpDownSumObserverInstrumentKind, o.AsyncImpl(),
|
||||
checkObserverBatch(t, labels, mockSDK, number.Int64Kind, metric.UpDownSumObserverInstrumentKind, o.AsyncImpl(),
|
||||
-142,
|
||||
)
|
||||
})
|
||||
@ -365,8 +365,8 @@ func TestObserverInstruments(t *testing.T) {
|
||||
func TestBatchObserverInstruments(t *testing.T) {
|
||||
mockSDK, meter := oteltest.NewMeter()
|
||||
|
||||
var obs1 otel.Int64ValueObserver
|
||||
var obs2 otel.Float64ValueObserver
|
||||
var obs1 metric.Int64ValueObserver
|
||||
var obs2 metric.Float64ValueObserver
|
||||
|
||||
labels := []label.KeyValue{
|
||||
label.String("A", "B"),
|
||||
@ -374,7 +374,7 @@ func TestBatchObserverInstruments(t *testing.T) {
|
||||
}
|
||||
|
||||
cb := Must(meter).NewBatchObserver(
|
||||
func(_ context.Context, result otel.BatchObserverResult) {
|
||||
func(_ context.Context, result metric.BatchObserverResult) {
|
||||
result.Observe(labels,
|
||||
obs1.Observation(42),
|
||||
obs2.Observation(42.0),
|
||||
@ -407,7 +407,7 @@ func TestBatchObserverInstruments(t *testing.T) {
|
||||
require.Equal(t, 0, m2.Number.CompareNumber(number.Float64Kind, oteltest.ResolveNumberByKind(t, number.Float64Kind, 42)))
|
||||
}
|
||||
|
||||
func checkObserverBatch(t *testing.T, labels []label.KeyValue, mock *oteltest.MeterImpl, nkind number.Kind, mkind otel.InstrumentKind, observer otel.AsyncImpl, expected float64) {
|
||||
func checkObserverBatch(t *testing.T, labels []label.KeyValue, mock *oteltest.MeterImpl, nkind number.Kind, mkind metric.InstrumentKind, observer metric.AsyncImpl, expected float64) {
|
||||
t.Helper()
|
||||
assert.Len(t, mock.MeasurementBatches, 1)
|
||||
if len(mock.MeasurementBatches) < 1 {
|
||||
@ -433,29 +433,29 @@ func checkObserverBatch(t *testing.T, labels []label.KeyValue, mock *oteltest.Me
|
||||
type testWrappedMeter struct {
|
||||
}
|
||||
|
||||
var _ otel.MeterImpl = testWrappedMeter{}
|
||||
var _ metric.MeterImpl = testWrappedMeter{}
|
||||
|
||||
func (testWrappedMeter) RecordBatch(context.Context, []label.KeyValue, ...otel.Measurement) {
|
||||
func (testWrappedMeter) RecordBatch(context.Context, []label.KeyValue, ...metric.Measurement) {
|
||||
}
|
||||
|
||||
func (testWrappedMeter) NewSyncInstrument(_ otel.Descriptor) (otel.SyncImpl, error) {
|
||||
func (testWrappedMeter) NewSyncInstrument(_ metric.Descriptor) (metric.SyncImpl, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (testWrappedMeter) NewAsyncInstrument(_ otel.Descriptor, _ otel.AsyncRunner) (otel.AsyncImpl, error) {
|
||||
func (testWrappedMeter) NewAsyncInstrument(_ metric.Descriptor, _ metric.AsyncRunner) (metric.AsyncImpl, error) {
|
||||
return nil, errors.New("Test wrap error")
|
||||
}
|
||||
|
||||
func TestWrappedInstrumentError(t *testing.T) {
|
||||
impl := &testWrappedMeter{}
|
||||
meter := otel.WrapMeterImpl(impl, "test")
|
||||
meter := metric.WrapMeterImpl(impl, "test")
|
||||
|
||||
valuerecorder, err := meter.NewInt64ValueRecorder("test.valuerecorder")
|
||||
|
||||
require.Equal(t, err, otel.ErrSDKReturnedNilImpl)
|
||||
require.Equal(t, err, metric.ErrSDKReturnedNilImpl)
|
||||
require.NotNil(t, valuerecorder.SyncImpl())
|
||||
|
||||
observer, err := meter.NewInt64ValueObserver("test.observer", func(_ context.Context, result otel.Int64ObserverResult) {})
|
||||
observer, err := meter.NewInt64ValueObserver("test.observer", func(_ context.Context, result metric.Int64ObserverResult) {})
|
||||
|
||||
require.NotNil(t, err)
|
||||
require.NotNil(t, observer.AsyncImpl())
|
||||
@ -467,6 +467,6 @@ func TestNilCallbackObserverNoop(t *testing.T) {
|
||||
|
||||
observer := Must(meter).NewInt64ValueObserver("test.observer", nil)
|
||||
|
||||
_, ok := observer.AsyncImpl().(otel.NoopAsync)
|
||||
_, ok := observer.AsyncImpl().(metric.NoopAsync)
|
||||
require.True(t, ok)
|
||||
}
|
@ -19,27 +19,27 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
)
|
||||
|
||||
// MeterProvider is a standard MeterProvider for wrapping `MeterImpl`
|
||||
type MeterProvider struct {
|
||||
impl otel.MeterImpl
|
||||
impl metric.MeterImpl
|
||||
}
|
||||
|
||||
var _ otel.MeterProvider = (*MeterProvider)(nil)
|
||||
var _ metric.MeterProvider = (*MeterProvider)(nil)
|
||||
|
||||
// uniqueInstrumentMeterImpl implements the otel.MeterImpl interface, adding
|
||||
// uniqueInstrumentMeterImpl implements the metric.MeterImpl interface, adding
|
||||
// uniqueness checking for instrument descriptors. Use NewUniqueInstrumentMeter
|
||||
// to wrap an implementation with uniqueness checking.
|
||||
type uniqueInstrumentMeterImpl struct {
|
||||
lock sync.Mutex
|
||||
impl otel.MeterImpl
|
||||
state map[key]otel.InstrumentImpl
|
||||
impl metric.MeterImpl
|
||||
state map[key]metric.InstrumentImpl
|
||||
}
|
||||
|
||||
var _ otel.MeterImpl = (*uniqueInstrumentMeterImpl)(nil)
|
||||
var _ metric.MeterImpl = (*uniqueInstrumentMeterImpl)(nil)
|
||||
|
||||
type key struct {
|
||||
instrumentName string
|
||||
@ -49,15 +49,15 @@ type key struct {
|
||||
|
||||
// NewMeterProvider returns a new provider that implements instrument
|
||||
// name-uniqueness checking.
|
||||
func NewMeterProvider(impl otel.MeterImpl) *MeterProvider {
|
||||
func NewMeterProvider(impl metric.MeterImpl) *MeterProvider {
|
||||
return &MeterProvider{
|
||||
impl: NewUniqueInstrumentMeterImpl(impl),
|
||||
}
|
||||
}
|
||||
|
||||
// Meter implements MeterProvider.
|
||||
func (p *MeterProvider) Meter(instrumentationName string, opts ...otel.MeterOption) otel.Meter {
|
||||
return otel.WrapMeterImpl(p.impl, instrumentationName, opts...)
|
||||
func (p *MeterProvider) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter {
|
||||
return metric.WrapMeterImpl(p.impl, instrumentationName, opts...)
|
||||
}
|
||||
|
||||
// ErrMetricKindMismatch is the standard error for mismatched metric
|
||||
@ -65,21 +65,21 @@ func (p *MeterProvider) Meter(instrumentationName string, opts ...otel.MeterOpti
|
||||
var ErrMetricKindMismatch = fmt.Errorf(
|
||||
"A metric was already registered by this name with another kind or number type")
|
||||
|
||||
// NewUniqueInstrumentMeterImpl returns a wrapped otel.MeterImpl with
|
||||
// NewUniqueInstrumentMeterImpl returns a wrapped metric.MeterImpl with
|
||||
// the addition of uniqueness checking.
|
||||
func NewUniqueInstrumentMeterImpl(impl otel.MeterImpl) otel.MeterImpl {
|
||||
func NewUniqueInstrumentMeterImpl(impl metric.MeterImpl) metric.MeterImpl {
|
||||
return &uniqueInstrumentMeterImpl{
|
||||
impl: impl,
|
||||
state: map[key]otel.InstrumentImpl{},
|
||||
state: map[key]metric.InstrumentImpl{},
|
||||
}
|
||||
}
|
||||
|
||||
// RecordBatch implements otel.MeterImpl.
|
||||
func (u *uniqueInstrumentMeterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, ms ...otel.Measurement) {
|
||||
// RecordBatch implements metric.MeterImpl.
|
||||
func (u *uniqueInstrumentMeterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, ms ...metric.Measurement) {
|
||||
u.impl.RecordBatch(ctx, labels, ms...)
|
||||
}
|
||||
|
||||
func keyOf(descriptor otel.Descriptor) key {
|
||||
func keyOf(descriptor metric.Descriptor) key {
|
||||
return key{
|
||||
descriptor.Name(),
|
||||
descriptor.InstrumentationName(),
|
||||
@ -89,7 +89,7 @@ func keyOf(descriptor otel.Descriptor) key {
|
||||
|
||||
// NewMetricKindMismatchError formats an error that describes a
|
||||
// mismatched metric instrument definition.
|
||||
func NewMetricKindMismatchError(desc otel.Descriptor) error {
|
||||
func NewMetricKindMismatchError(desc metric.Descriptor) error {
|
||||
return fmt.Errorf("Metric was %s (%s %s)registered as a %s %s: %w",
|
||||
desc.Name(),
|
||||
desc.InstrumentationName(),
|
||||
@ -99,9 +99,9 @@ func NewMetricKindMismatchError(desc otel.Descriptor) error {
|
||||
ErrMetricKindMismatch)
|
||||
}
|
||||
|
||||
// Compatible determines whether two otel.Descriptors are considered
|
||||
// Compatible determines whether two metric.Descriptors are considered
|
||||
// the same for the purpose of uniqueness checking.
|
||||
func Compatible(candidate, existing otel.Descriptor) bool {
|
||||
func Compatible(candidate, existing metric.Descriptor) bool {
|
||||
return candidate.InstrumentKind() == existing.InstrumentKind() &&
|
||||
candidate.NumberKind() == existing.NumberKind()
|
||||
}
|
||||
@ -111,7 +111,7 @@ func Compatible(candidate, existing otel.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 otel.Descriptor) (otel.InstrumentImpl, error) {
|
||||
func (u *uniqueInstrumentMeterImpl) checkUniqueness(descriptor metric.Descriptor) (metric.InstrumentImpl, error) {
|
||||
impl, ok := u.state[keyOf(descriptor)]
|
||||
if !ok {
|
||||
return nil, nil
|
||||
@ -124,8 +124,8 @@ func (u *uniqueInstrumentMeterImpl) checkUniqueness(descriptor otel.Descriptor)
|
||||
return impl, nil
|
||||
}
|
||||
|
||||
// NewSyncInstrument implements otel.MeterImpl.
|
||||
func (u *uniqueInstrumentMeterImpl) NewSyncInstrument(descriptor otel.Descriptor) (otel.SyncImpl, error) {
|
||||
// NewSyncInstrument implements metric.MeterImpl.
|
||||
func (u *uniqueInstrumentMeterImpl) NewSyncInstrument(descriptor metric.Descriptor) (metric.SyncImpl, error) {
|
||||
u.lock.Lock()
|
||||
defer u.lock.Unlock()
|
||||
|
||||
@ -134,7 +134,7 @@ func (u *uniqueInstrumentMeterImpl) NewSyncInstrument(descriptor otel.Descriptor
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if impl != nil {
|
||||
return impl.(otel.SyncImpl), nil
|
||||
return impl.(metric.SyncImpl), nil
|
||||
}
|
||||
|
||||
syncInst, err := u.impl.NewSyncInstrument(descriptor)
|
||||
@ -145,11 +145,11 @@ func (u *uniqueInstrumentMeterImpl) NewSyncInstrument(descriptor otel.Descriptor
|
||||
return syncInst, nil
|
||||
}
|
||||
|
||||
// NewAsyncInstrument implements otel.MeterImpl.
|
||||
// NewAsyncInstrument implements metric.MeterImpl.
|
||||
func (u *uniqueInstrumentMeterImpl) NewAsyncInstrument(
|
||||
descriptor otel.Descriptor,
|
||||
runner otel.AsyncRunner,
|
||||
) (otel.AsyncImpl, error) {
|
||||
descriptor metric.Descriptor,
|
||||
runner metric.AsyncRunner,
|
||||
) (metric.AsyncImpl, error) {
|
||||
u.lock.Lock()
|
||||
defer u.lock.Unlock()
|
||||
|
||||
@ -158,7 +158,7 @@ func (u *uniqueInstrumentMeterImpl) NewAsyncInstrument(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if impl != nil {
|
||||
return impl.(otel.AsyncImpl), nil
|
||||
return impl.(metric.AsyncImpl), nil
|
||||
}
|
||||
|
||||
asyncInst, err := u.impl.NewAsyncInstrument(descriptor, runner)
|
||||
|
@ -21,49 +21,49 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/registry"
|
||||
"go.opentelemetry.io/otel/oteltest"
|
||||
)
|
||||
|
||||
type (
|
||||
newFunc func(m otel.Meter, name string) (otel.InstrumentImpl, error)
|
||||
newFunc func(m metric.Meter, name string) (metric.InstrumentImpl, error)
|
||||
)
|
||||
|
||||
var (
|
||||
allNew = map[string]newFunc{
|
||||
"counter.int64": func(m otel.Meter, name string) (otel.InstrumentImpl, error) {
|
||||
"counter.int64": func(m metric.Meter, name string) (metric.InstrumentImpl, error) {
|
||||
return unwrap(m.NewInt64Counter(name))
|
||||
},
|
||||
"counter.float64": func(m otel.Meter, name string) (otel.InstrumentImpl, error) {
|
||||
"counter.float64": func(m metric.Meter, name string) (metric.InstrumentImpl, error) {
|
||||
return unwrap(m.NewFloat64Counter(name))
|
||||
},
|
||||
"valuerecorder.int64": func(m otel.Meter, name string) (otel.InstrumentImpl, error) {
|
||||
"valuerecorder.int64": func(m metric.Meter, name string) (metric.InstrumentImpl, error) {
|
||||
return unwrap(m.NewInt64ValueRecorder(name))
|
||||
},
|
||||
"valuerecorder.float64": func(m otel.Meter, name string) (otel.InstrumentImpl, error) {
|
||||
"valuerecorder.float64": func(m metric.Meter, name string) (metric.InstrumentImpl, error) {
|
||||
return unwrap(m.NewFloat64ValueRecorder(name))
|
||||
},
|
||||
"valueobserver.int64": func(m otel.Meter, name string) (otel.InstrumentImpl, error) {
|
||||
return unwrap(m.NewInt64ValueObserver(name, func(context.Context, otel.Int64ObserverResult) {}))
|
||||
"valueobserver.int64": func(m metric.Meter, name string) (metric.InstrumentImpl, error) {
|
||||
return unwrap(m.NewInt64ValueObserver(name, func(context.Context, metric.Int64ObserverResult) {}))
|
||||
},
|
||||
"valueobserver.float64": func(m otel.Meter, name string) (otel.InstrumentImpl, error) {
|
||||
return unwrap(m.NewFloat64ValueObserver(name, func(context.Context, otel.Float64ObserverResult) {}))
|
||||
"valueobserver.float64": func(m metric.Meter, name string) (metric.InstrumentImpl, error) {
|
||||
return unwrap(m.NewFloat64ValueObserver(name, func(context.Context, metric.Float64ObserverResult) {}))
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func unwrap(impl interface{}, err error) (otel.InstrumentImpl, error) {
|
||||
func unwrap(impl interface{}, err error) (metric.InstrumentImpl, error) {
|
||||
if impl == nil {
|
||||
return nil, err
|
||||
}
|
||||
if s, ok := impl.(interface {
|
||||
SyncImpl() otel.SyncImpl
|
||||
SyncImpl() metric.SyncImpl
|
||||
}); ok {
|
||||
return s.SyncImpl(), err
|
||||
}
|
||||
if a, ok := impl.(interface {
|
||||
AsyncImpl() otel.AsyncImpl
|
||||
AsyncImpl() metric.AsyncImpl
|
||||
}); ok {
|
||||
return a.AsyncImpl(), err
|
||||
}
|
||||
|
@ -19,10 +19,9 @@ import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
apimetric "go.opentelemetry.io/otel"
|
||||
internalmetric "go.opentelemetry.io/otel/internal/metric"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
"go.opentelemetry.io/otel/metric/registry"
|
||||
)
|
||||
@ -53,18 +52,18 @@ type (
|
||||
Measurement struct {
|
||||
// Number needs to be aligned for 64-bit atomic operations.
|
||||
Number number.Number
|
||||
Instrument apimetric.InstrumentImpl
|
||||
Instrument metric.InstrumentImpl
|
||||
}
|
||||
|
||||
Instrument struct {
|
||||
meter *MeterImpl
|
||||
descriptor apimetric.Descriptor
|
||||
descriptor metric.Descriptor
|
||||
}
|
||||
|
||||
Async struct {
|
||||
Instrument
|
||||
|
||||
runner apimetric.AsyncRunner
|
||||
runner metric.AsyncRunner
|
||||
}
|
||||
|
||||
Sync struct {
|
||||
@ -73,13 +72,13 @@ type (
|
||||
)
|
||||
|
||||
var (
|
||||
_ apimetric.SyncImpl = &Sync{}
|
||||
_ apimetric.BoundSyncImpl = &Handle{}
|
||||
_ apimetric.MeterImpl = &MeterImpl{}
|
||||
_ apimetric.AsyncImpl = &Async{}
|
||||
_ metric.SyncImpl = &Sync{}
|
||||
_ metric.BoundSyncImpl = &Handle{}
|
||||
_ metric.MeterImpl = &MeterImpl{}
|
||||
_ metric.AsyncImpl = &Async{}
|
||||
)
|
||||
|
||||
func (i Instrument) Descriptor() apimetric.Descriptor {
|
||||
func (i Instrument) Descriptor() metric.Descriptor {
|
||||
return i.descriptor
|
||||
}
|
||||
|
||||
@ -91,7 +90,7 @@ func (s *Sync) Implementation() interface{} {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Sync) Bind(labels []label.KeyValue) apimetric.BoundSyncImpl {
|
||||
func (s *Sync) Bind(labels []label.KeyValue) metric.BoundSyncImpl {
|
||||
return &Handle{
|
||||
Instrument: s,
|
||||
Labels: labels,
|
||||
@ -109,26 +108,26 @@ func (h *Handle) RecordOne(ctx context.Context, number number.Number) {
|
||||
func (h *Handle) Unbind() {
|
||||
}
|
||||
|
||||
func (m *MeterImpl) doRecordSingle(ctx context.Context, labels []label.KeyValue, instrument apimetric.InstrumentImpl, number number.Number) {
|
||||
func (m *MeterImpl) doRecordSingle(ctx context.Context, labels []label.KeyValue, instrument metric.InstrumentImpl, number number.Number) {
|
||||
m.collect(ctx, labels, []Measurement{{
|
||||
Instrument: instrument,
|
||||
Number: number,
|
||||
}})
|
||||
}
|
||||
|
||||
func NewMeterProvider() (*MeterImpl, apimetric.MeterProvider) {
|
||||
func NewMeterProvider() (*MeterImpl, metric.MeterProvider) {
|
||||
impl := &MeterImpl{
|
||||
asyncInstruments: internalmetric.NewAsyncInstrumentState(),
|
||||
}
|
||||
return impl, registry.NewMeterProvider(impl)
|
||||
}
|
||||
|
||||
func NewMeter() (*MeterImpl, apimetric.Meter) {
|
||||
func NewMeter() (*MeterImpl, metric.Meter) {
|
||||
impl, p := NewMeterProvider()
|
||||
return impl, p.Meter("mock")
|
||||
}
|
||||
|
||||
func (m *MeterImpl) NewSyncInstrument(descriptor otel.Descriptor) (apimetric.SyncImpl, error) {
|
||||
func (m *MeterImpl) NewSyncInstrument(descriptor metric.Descriptor) (metric.SyncImpl, error) {
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
|
||||
@ -140,7 +139,7 @@ func (m *MeterImpl) NewSyncInstrument(descriptor otel.Descriptor) (apimetric.Syn
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MeterImpl) NewAsyncInstrument(descriptor otel.Descriptor, runner otel.AsyncRunner) (apimetric.AsyncImpl, error) {
|
||||
func (m *MeterImpl) NewAsyncInstrument(descriptor metric.Descriptor, runner metric.AsyncRunner) (metric.AsyncImpl, error) {
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
|
||||
@ -155,7 +154,7 @@ func (m *MeterImpl) NewAsyncInstrument(descriptor otel.Descriptor, runner otel.A
|
||||
return a, nil
|
||||
}
|
||||
|
||||
func (m *MeterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, measurements ...apimetric.Measurement) {
|
||||
func (m *MeterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, measurements ...metric.Measurement) {
|
||||
mm := make([]Measurement, len(measurements))
|
||||
for i := 0; i < len(measurements); i++ {
|
||||
m := measurements[i]
|
||||
@ -167,7 +166,7 @@ func (m *MeterImpl) RecordBatch(ctx context.Context, labels []label.KeyValue, me
|
||||
m.collect(ctx, labels, mm)
|
||||
}
|
||||
|
||||
func (m *MeterImpl) CollectAsync(labels []label.KeyValue, obs ...otel.Observation) {
|
||||
func (m *MeterImpl) CollectAsync(labels []label.KeyValue, obs ...metric.Observation) {
|
||||
mm := make([]Measurement, len(obs))
|
||||
for i := 0; i < len(obs); i++ {
|
||||
o := obs[i]
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
)
|
||||
@ -29,16 +29,16 @@ func TestExportKindIncludes(t *testing.T) {
|
||||
require.True(t, DeltaExportKind.Includes(CumulativeExportKind|DeltaExportKind))
|
||||
}
|
||||
|
||||
var deltaMemoryKinds = []otel.InstrumentKind{
|
||||
otel.SumObserverInstrumentKind,
|
||||
otel.UpDownSumObserverInstrumentKind,
|
||||
var deltaMemoryKinds = []metric.InstrumentKind{
|
||||
metric.SumObserverInstrumentKind,
|
||||
metric.UpDownSumObserverInstrumentKind,
|
||||
}
|
||||
|
||||
var cumulativeMemoryKinds = []otel.InstrumentKind{
|
||||
otel.ValueRecorderInstrumentKind,
|
||||
otel.ValueObserverInstrumentKind,
|
||||
otel.CounterInstrumentKind,
|
||||
otel.UpDownCounterInstrumentKind,
|
||||
var cumulativeMemoryKinds = []metric.InstrumentKind{
|
||||
metric.ValueRecorderInstrumentKind,
|
||||
metric.ValueObserverInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
metric.UpDownCounterInstrumentKind,
|
||||
}
|
||||
|
||||
func TestExportKindMemoryRequired(t *testing.T) {
|
||||
@ -59,7 +59,7 @@ func TestExportKindSelectors(t *testing.T) {
|
||||
seks := StatelessExportKindSelector()
|
||||
|
||||
for _, ikind := range append(deltaMemoryKinds, cumulativeMemoryKinds...) {
|
||||
desc := otel.NewDescriptor("instrument", ikind, number.Int64Kind)
|
||||
desc := metric.NewDescriptor("instrument", ikind, number.Int64Kind)
|
||||
|
||||
var akind aggregation.Kind
|
||||
if ikind.Adding() {
|
||||
|
@ -21,8 +21,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
@ -95,7 +95,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 *otel.Descriptor, aggregator ...*Aggregator)
|
||||
AggregatorFor(descriptor *metric.Descriptor, aggregator ...*Aggregator)
|
||||
}
|
||||
|
||||
// Checkpointer is the interface used by a Controller to coordinate
|
||||
@ -153,7 +153,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 *otel.Descriptor) error
|
||||
Update(ctx context.Context, number number.Number, descriptor *metric.Descriptor) error
|
||||
|
||||
// SynchronizedMove is called during collection to finish one
|
||||
// period of aggregation by atomically saving the
|
||||
@ -174,7 +174,7 @@ type Aggregator interface {
|
||||
//
|
||||
// This call has no Context argument because it is expected to
|
||||
// perform only computation.
|
||||
SynchronizedMove(destination Aggregator, descriptor *otel.Descriptor) error
|
||||
SynchronizedMove(destination Aggregator, descriptor *metric.Descriptor) error
|
||||
|
||||
// Merge combines the checkpointed state from the argument
|
||||
// Aggregator into this Aggregator. Merge is not synchronized
|
||||
@ -182,7 +182,7 @@ type Aggregator interface {
|
||||
//
|
||||
// The owner of an Aggregator being merged is responsible for
|
||||
// synchronization of both Aggregator states.
|
||||
Merge(aggregator Aggregator, descriptor *otel.Descriptor) error
|
||||
Merge(aggregator Aggregator, descriptor *metric.Descriptor) error
|
||||
}
|
||||
|
||||
// Subtractor is an optional interface implemented by some
|
||||
@ -192,7 +192,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 *otel.Descriptor) error
|
||||
Subtract(operand, result Aggregator, descriptor *metric.Descriptor) error
|
||||
}
|
||||
|
||||
// Exporter handles presentation of the checkpoint of aggregate
|
||||
@ -222,7 +222,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 *otel.Descriptor, aggregatorKind aggregation.Kind) ExportKind
|
||||
ExportKindFor(descriptor *metric.Descriptor, aggregatorKind aggregation.Kind) ExportKind
|
||||
}
|
||||
|
||||
// CheckpointSet allows a controller to access a complete checkpoint of
|
||||
@ -263,7 +263,7 @@ type CheckpointSet interface {
|
||||
// are shared by the Accumulator->Processor and Processor->Exporter
|
||||
// steps.
|
||||
type Metadata struct {
|
||||
descriptor *otel.Descriptor
|
||||
descriptor *metric.Descriptor
|
||||
labels *label.Set
|
||||
resource *resource.Resource
|
||||
}
|
||||
@ -286,7 +286,7 @@ type Record struct {
|
||||
}
|
||||
|
||||
// Descriptor describes the metric instrument being exported.
|
||||
func (m Metadata) Descriptor() *otel.Descriptor {
|
||||
func (m Metadata) Descriptor() *metric.Descriptor {
|
||||
return m.descriptor
|
||||
}
|
||||
|
||||
@ -305,7 +305,7 @@ func (m Metadata) Resource() *resource.Resource {
|
||||
// Accumulations to send to Processors. The Descriptor, Labels, Resource,
|
||||
// and Aggregator represent aggregate metric events received over a single
|
||||
// collection period.
|
||||
func NewAccumulation(descriptor *otel.Descriptor, labels *label.Set, resource *resource.Resource, aggregator Aggregator) Accumulation {
|
||||
func NewAccumulation(descriptor *metric.Descriptor, labels *label.Set, resource *resource.Resource, aggregator Aggregator) Accumulation {
|
||||
return Accumulation{
|
||||
Metadata: Metadata{
|
||||
descriptor: descriptor,
|
||||
@ -325,7 +325,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 *otel.Descriptor, labels *label.Set, resource *resource.Resource, aggregation aggregation.Aggregation, start, end time.Time) Record {
|
||||
func NewRecord(descriptor *metric.Descriptor, labels *label.Set, resource *resource.Resource, aggregation aggregation.Aggregation, start, end time.Time) Record {
|
||||
return Record{
|
||||
Metadata: Metadata{
|
||||
descriptor: descriptor,
|
||||
@ -376,14 +376,14 @@ func (kind ExportKind) Includes(has ExportKind) bool {
|
||||
|
||||
// MemoryRequired returns whether an exporter of this kind requires
|
||||
// memory to export correctly.
|
||||
func (kind ExportKind) MemoryRequired(mkind otel.InstrumentKind) bool {
|
||||
func (kind ExportKind) MemoryRequired(mkind metric.InstrumentKind) bool {
|
||||
switch mkind {
|
||||
case otel.ValueRecorderInstrumentKind, otel.ValueObserverInstrumentKind,
|
||||
otel.CounterInstrumentKind, otel.UpDownCounterInstrumentKind:
|
||||
case metric.ValueRecorderInstrumentKind, metric.ValueObserverInstrumentKind,
|
||||
metric.CounterInstrumentKind, metric.UpDownCounterInstrumentKind:
|
||||
// Delta-oriented instruments:
|
||||
return kind.Includes(CumulativeExportKind)
|
||||
|
||||
case otel.SumObserverInstrumentKind, otel.UpDownSumObserverInstrumentKind:
|
||||
case metric.SumObserverInstrumentKind, metric.UpDownSumObserverInstrumentKind:
|
||||
// Cumulative-oriented instruments:
|
||||
return kind.Includes(DeltaExportKind)
|
||||
}
|
||||
@ -429,12 +429,12 @@ func StatelessExportKindSelector() ExportKindSelector {
|
||||
}
|
||||
|
||||
// ExportKindFor implements ExportKindSelector.
|
||||
func (c constantExportKindSelector) ExportKindFor(_ *otel.Descriptor, _ aggregation.Kind) ExportKind {
|
||||
func (c constantExportKindSelector) ExportKindFor(_ *metric.Descriptor, _ aggregation.Kind) ExportKind {
|
||||
return ExportKind(c)
|
||||
}
|
||||
|
||||
// ExportKindFor implements ExportKindSelector.
|
||||
func (s statelessExportKindSelector) ExportKindFor(desc *otel.Descriptor, kind aggregation.Kind) ExportKind {
|
||||
func (s statelessExportKindSelector) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) ExportKind {
|
||||
if kind == aggregation.SumKind && desc.InstrumentKind().PrecomputedSum() {
|
||||
return CumulativeExportKind
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
@ -30,7 +30,7 @@ import (
|
||||
)
|
||||
|
||||
type mapkey struct {
|
||||
desc *otel.Descriptor
|
||||
desc *metric.Descriptor
|
||||
distinct label.Distinct
|
||||
}
|
||||
|
||||
@ -49,17 +49,17 @@ type NoopAggregator struct{}
|
||||
var _ export.Aggregator = (*NoopAggregator)(nil)
|
||||
|
||||
// Update implements export.Aggregator.
|
||||
func (NoopAggregator) Update(context.Context, number.Number, *otel.Descriptor) error {
|
||||
func (NoopAggregator) Update(context.Context, number.Number, *metric.Descriptor) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SynchronizedMove implements export.Aggregator.
|
||||
func (NoopAggregator) SynchronizedMove(export.Aggregator, *otel.Descriptor) error {
|
||||
func (NoopAggregator) SynchronizedMove(export.Aggregator, *metric.Descriptor) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Merge implements export.Aggregator.
|
||||
func (NoopAggregator) Merge(export.Aggregator, *otel.Descriptor) error {
|
||||
func (NoopAggregator) Merge(export.Aggregator, *metric.Descriptor) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ func (p *CheckpointSet) Reset() {
|
||||
//
|
||||
// If there is an existing record with the same descriptor and labels,
|
||||
// the stored aggregator will be returned and should be merged.
|
||||
func (p *CheckpointSet) Add(desc *otel.Descriptor, newAgg export.Aggregator, labels ...label.KeyValue) (agg export.Aggregator, added bool) {
|
||||
func (p *CheckpointSet) Add(desc *metric.Descriptor, newAgg export.Aggregator, labels ...label.KeyValue) (agg export.Aggregator, added bool) {
|
||||
elabels := label.NewSet(labels...)
|
||||
|
||||
key := mapkey{
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
@ -35,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 ValueRecorder metrics.
|
||||
func RangeTest(num number.Number, descriptor *otel.Descriptor) error {
|
||||
func RangeTest(num number.Number, descriptor *metric.Descriptor) error {
|
||||
numberKind := descriptor.NumberKind()
|
||||
|
||||
if numberKind == number.Float64Kind && math.IsNaN(num.AsFloat64()) {
|
||||
@ -43,7 +43,7 @@ func RangeTest(num number.Number, descriptor *otel.Descriptor) error {
|
||||
}
|
||||
|
||||
switch descriptor.InstrumentKind() {
|
||||
case otel.CounterInstrumentKind, otel.SumObserverInstrumentKind:
|
||||
case metric.CounterInstrumentKind, metric.SumObserverInstrumentKind:
|
||||
if num.IsNegative(numberKind) {
|
||||
return aggregation.ErrNegativeInput
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator"
|
||||
@ -39,7 +39,7 @@ func TestInconsistentAggregatorErr(t *testing.T) {
|
||||
require.True(t, errors.Is(err, aggregation.ErrInconsistentType))
|
||||
}
|
||||
|
||||
func testRangeNaN(t *testing.T, desc *otel.Descriptor) {
|
||||
func testRangeNaN(t *testing.T, desc *metric.Descriptor) {
|
||||
// If the descriptor uses int64 numbers, this won't register as NaN
|
||||
nan := number.NewFloat64Number(math.NaN())
|
||||
err := aggregator.RangeTest(nan, desc)
|
||||
@ -51,7 +51,7 @@ func testRangeNaN(t *testing.T, desc *otel.Descriptor) {
|
||||
}
|
||||
}
|
||||
|
||||
func testRangeNegative(t *testing.T, desc *otel.Descriptor) {
|
||||
func testRangeNegative(t *testing.T, desc *metric.Descriptor) {
|
||||
var neg, pos number.Number
|
||||
|
||||
if desc.NumberKind() == number.Float64Kind {
|
||||
@ -73,9 +73,9 @@ func TestRangeTest(t *testing.T) {
|
||||
// Only Counters implement a range test.
|
||||
for _, nkind := range []number.Kind{number.Float64Kind, number.Int64Kind} {
|
||||
t.Run(nkind.String(), func(t *testing.T) {
|
||||
desc := otel.NewDescriptor(
|
||||
desc := metric.NewDescriptor(
|
||||
"name",
|
||||
otel.CounterInstrumentKind,
|
||||
metric.CounterInstrumentKind,
|
||||
nkind,
|
||||
)
|
||||
testRangeNegative(t, &desc)
|
||||
@ -86,12 +86,12 @@ func TestRangeTest(t *testing.T) {
|
||||
func TestNaNTest(t *testing.T) {
|
||||
for _, nkind := range []number.Kind{number.Float64Kind, number.Int64Kind} {
|
||||
t.Run(nkind.String(), func(t *testing.T) {
|
||||
for _, mkind := range []otel.InstrumentKind{
|
||||
otel.CounterInstrumentKind,
|
||||
otel.ValueRecorderInstrumentKind,
|
||||
otel.ValueObserverInstrumentKind,
|
||||
for _, mkind := range []metric.InstrumentKind{
|
||||
metric.CounterInstrumentKind,
|
||||
metric.ValueRecorderInstrumentKind,
|
||||
metric.ValueObserverInstrumentKind,
|
||||
} {
|
||||
desc := otel.NewDescriptor(
|
||||
desc := metric.NewDescriptor(
|
||||
"name",
|
||||
mkind,
|
||||
nkind,
|
||||
|
@ -22,8 +22,8 @@ import (
|
||||
"testing"
|
||||
"unsafe"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
ottest "go.opentelemetry.io/otel/internal/testing"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator"
|
||||
@ -54,8 +54,8 @@ func newProfiles() []Profile {
|
||||
}
|
||||
}
|
||||
|
||||
func NewAggregatorTest(mkind otel.InstrumentKind, nkind number.Kind) *otel.Descriptor {
|
||||
desc := otel.NewDescriptor("test.name", mkind, nkind)
|
||||
func NewAggregatorTest(mkind metric.InstrumentKind, nkind number.Kind) *metric.Descriptor {
|
||||
desc := metric.NewDescriptor("test.name", mkind, nkind)
|
||||
return &desc
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ func (n *Numbers) Points() []number.Number {
|
||||
}
|
||||
|
||||
// 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 *otel.Descriptor) {
|
||||
func CheckedUpdate(t *testing.T, agg export.Aggregator, number number.Number, descriptor *metric.Descriptor) {
|
||||
ctx := context.Background()
|
||||
|
||||
// Note: Aggregator tests are written assuming that the SDK
|
||||
@ -167,7 +167,7 @@ func CheckedUpdate(t *testing.T, agg export.Aggregator, number number.Number, de
|
||||
}
|
||||
}
|
||||
|
||||
func CheckedMerge(t *testing.T, aggInto, aggFrom export.Aggregator, descriptor *otel.Descriptor) {
|
||||
func CheckedMerge(t *testing.T, aggInto, aggFrom export.Aggregator, descriptor *metric.Descriptor) {
|
||||
if err := aggInto.Merge(aggFrom, descriptor); err != nil {
|
||||
t.Error("Unexpected Merge failure", err)
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
@ -95,7 +95,7 @@ func (c *Aggregator) Points() ([]number.Number, 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 *otel.Descriptor) error {
|
||||
func (c *Aggregator) SynchronizedMove(oa export.Aggregator, desc *metric.Descriptor) error {
|
||||
o, _ := oa.(*Aggregator)
|
||||
if o == nil {
|
||||
return aggregator.NewInconsistentAggregatorError(c, oa)
|
||||
@ -117,7 +117,7 @@ func (c *Aggregator) SynchronizedMove(oa export.Aggregator, desc *otel.Descripto
|
||||
// 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 *otel.Descriptor) error {
|
||||
func (c *Aggregator) Update(_ context.Context, number number.Number, desc *metric.Descriptor) error {
|
||||
c.lock.Lock()
|
||||
c.points = append(c.points, number)
|
||||
c.sum.AddNumber(desc.NumberKind(), number)
|
||||
@ -127,7 +127,7 @@ func (c *Aggregator) Update(_ context.Context, number number.Number, desc *otel.
|
||||
}
|
||||
|
||||
// Merge combines two data sets into one.
|
||||
func (c *Aggregator) Merge(oa export.Aggregator, desc *otel.Descriptor) error {
|
||||
func (c *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error {
|
||||
o, _ := oa.(*Aggregator)
|
||||
if o == nil {
|
||||
return aggregator.NewInconsistentAggregatorError(c, oa)
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest"
|
||||
@ -32,7 +32,7 @@ type updateTest struct {
|
||||
count int
|
||||
}
|
||||
|
||||
func checkZero(t *testing.T, agg *Aggregator, desc *otel.Descriptor) {
|
||||
func checkZero(t *testing.T, agg *Aggregator, desc *metric.Descriptor) {
|
||||
kind := desc.NumberKind()
|
||||
|
||||
sum, err := agg.Sum()
|
||||
@ -63,7 +63,7 @@ func new4() (_, _, _, _ *Aggregator) {
|
||||
}
|
||||
|
||||
func (ut *updateTest) run(t *testing.T, profile aggregatortest.Profile) {
|
||||
descriptor := aggregatortest.NewAggregatorTest(otel.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
agg, ckpt := new2()
|
||||
|
||||
all := aggregatortest.NewNumbers(profile.NumberKind)
|
||||
@ -130,7 +130,7 @@ type mergeTest struct {
|
||||
}
|
||||
|
||||
func (mt *mergeTest) run(t *testing.T, profile aggregatortest.Profile) {
|
||||
descriptor := aggregatortest.NewAggregatorTest(otel.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
agg1, agg2, ckpt1, ckpt2 := new4()
|
||||
|
||||
all := aggregatortest.NewNumbers(profile.NumberKind)
|
||||
@ -226,7 +226,7 @@ func TestArrayErrors(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
require.Equal(t, err, aggregation.ErrNoData)
|
||||
|
||||
descriptor := aggregatortest.NewAggregatorTest(otel.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
|
||||
aggregatortest.CheckedUpdate(t, agg, number.Number(0), descriptor)
|
||||
|
||||
@ -254,7 +254,7 @@ func TestArrayErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestArrayFloat64(t *testing.T) {
|
||||
descriptor := aggregatortest.NewAggregatorTest(otel.ValueRecorderInstrumentKind, number.Float64Kind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, number.Float64Kind)
|
||||
|
||||
fpsf := func(sign int) []float64 {
|
||||
// Check behavior of a bunch of odd floating
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
|
||||
sdk "github.com/DataDog/sketches-go/ddsketch"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
@ -43,7 +43,7 @@ var _ aggregation.MinMaxSumCount = &Aggregator{}
|
||||
var _ aggregation.Distribution = &Aggregator{}
|
||||
|
||||
// New returns a new DDSketch aggregator.
|
||||
func New(cnt int, desc *otel.Descriptor, cfg *Config) []Aggregator {
|
||||
func New(cnt int, desc *metric.Descriptor, cfg *Config) []Aggregator {
|
||||
if cfg == nil {
|
||||
cfg = NewDefaultConfig()
|
||||
}
|
||||
@ -115,7 +115,7 @@ func (c *Aggregator) toNumber(f float64) number.Number {
|
||||
|
||||
// SynchronizedMove saves the current state into oa and resets the current state to
|
||||
// a new sketch, taking a lock to prevent concurrent Update() calls.
|
||||
func (c *Aggregator) SynchronizedMove(oa export.Aggregator, _ *otel.Descriptor) error {
|
||||
func (c *Aggregator) SynchronizedMove(oa export.Aggregator, _ *metric.Descriptor) error {
|
||||
o, _ := oa.(*Aggregator)
|
||||
if o == nil {
|
||||
return aggregator.NewInconsistentAggregatorError(c, oa)
|
||||
@ -132,7 +132,7 @@ func (c *Aggregator) SynchronizedMove(oa export.Aggregator, _ *otel.Descriptor)
|
||||
// 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 *otel.Descriptor) error {
|
||||
func (c *Aggregator) Update(_ context.Context, number number.Number, desc *metric.Descriptor) error {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
c.sketch.Add(number.CoerceToFloat64(desc.NumberKind()))
|
||||
@ -140,7 +140,7 @@ func (c *Aggregator) Update(_ context.Context, number number.Number, desc *otel.
|
||||
}
|
||||
|
||||
// Merge combines two sketches into one.
|
||||
func (c *Aggregator) Merge(oa export.Aggregator, d *otel.Descriptor) error {
|
||||
func (c *Aggregator) Merge(oa export.Aggregator, d *metric.Descriptor) error {
|
||||
o, _ := oa.(*Aggregator)
|
||||
if o == nil {
|
||||
return aggregator.NewInconsistentAggregatorError(c, oa)
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest"
|
||||
)
|
||||
@ -31,17 +31,17 @@ const count = 1000
|
||||
type updateTest struct {
|
||||
}
|
||||
|
||||
func new2(desc *otel.Descriptor) (_, _ *Aggregator) {
|
||||
func new2(desc *metric.Descriptor) (_, _ *Aggregator) {
|
||||
alloc := New(2, desc, NewDefaultConfig())
|
||||
return &alloc[0], &alloc[1]
|
||||
}
|
||||
|
||||
func new4(desc *otel.Descriptor) (_, _, _, _ *Aggregator) {
|
||||
func new4(desc *metric.Descriptor) (_, _, _, _ *Aggregator) {
|
||||
alloc := New(4, desc, NewDefaultConfig())
|
||||
return &alloc[0], &alloc[1], &alloc[2], &alloc[3]
|
||||
}
|
||||
|
||||
func checkZero(t *testing.T, agg *Aggregator, desc *otel.Descriptor) {
|
||||
func checkZero(t *testing.T, agg *Aggregator, desc *metric.Descriptor) {
|
||||
kind := desc.NumberKind()
|
||||
|
||||
sum, err := agg.Sum()
|
||||
@ -66,7 +66,7 @@ func checkZero(t *testing.T, agg *Aggregator, desc *otel.Descriptor) {
|
||||
}
|
||||
|
||||
func (ut *updateTest) run(t *testing.T, profile aggregatortest.Profile) {
|
||||
descriptor := aggregatortest.NewAggregatorTest(otel.ValueRecorderInstrumentKind, 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(otel.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
|
||||
agg1, agg2, ckpt1, ckpt2 := new4(descriptor)
|
||||
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
|
||||
@ -38,7 +38,7 @@ func benchmarkHistogramSearchFloat64(b *testing.B, size int) {
|
||||
for i := range values {
|
||||
values[i] = rand.Float64() * inputRange
|
||||
}
|
||||
desc := aggregatortest.NewAggregatorTest(otel.ValueRecorderInstrumentKind, number.Float64Kind)
|
||||
desc := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, number.Float64Kind)
|
||||
agg := &histogram.New(1, desc, boundaries)[0]
|
||||
ctx := context.Background()
|
||||
|
||||
@ -89,7 +89,7 @@ func benchmarkHistogramSearchInt64(b *testing.B, size int) {
|
||||
for i := range values {
|
||||
values[i] = int64(rand.Float64() * inputRange)
|
||||
}
|
||||
desc := aggregatortest.NewAggregatorTest(otel.ValueRecorderInstrumentKind, number.Int64Kind)
|
||||
desc := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, number.Int64Kind)
|
||||
agg := &histogram.New(1, desc, boundaries)[0]
|
||||
ctx := context.Background()
|
||||
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
@ -64,7 +64,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 *otel.Descriptor, boundaries []float64) []Aggregator {
|
||||
func New(cnt int, desc *metric.Descriptor, boundaries []float64) []Aggregator {
|
||||
aggs := make([]Aggregator, cnt)
|
||||
|
||||
// Boundaries MUST be ordered otherwise the histogram could not
|
||||
@ -116,7 +116,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 *otel.Descriptor) error {
|
||||
func (c *Aggregator) SynchronizedMove(oa export.Aggregator, desc *metric.Descriptor) error {
|
||||
o, _ := oa.(*Aggregator)
|
||||
if o == nil {
|
||||
return aggregator.NewInconsistentAggregatorError(c, oa)
|
||||
@ -135,7 +135,7 @@ func emptyState(boundaries []float64) state {
|
||||
}
|
||||
|
||||
// Update adds the recorded measurement to the current data set.
|
||||
func (c *Aggregator) Update(_ context.Context, number number.Number, desc *otel.Descriptor) error {
|
||||
func (c *Aggregator) Update(_ context.Context, number number.Number, desc *metric.Descriptor) error {
|
||||
kind := desc.NumberKind()
|
||||
asFloat := number.CoerceToFloat64(kind)
|
||||
|
||||
@ -169,7 +169,7 @@ func (c *Aggregator) Update(_ context.Context, number number.Number, desc *otel.
|
||||
}
|
||||
|
||||
// Merge combines two histograms that have the same buckets into a single one.
|
||||
func (c *Aggregator) Merge(oa export.Aggregator, desc *otel.Descriptor) error {
|
||||
func (c *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error {
|
||||
o, _ := oa.(*Aggregator)
|
||||
if o == nil {
|
||||
return aggregator.NewInconsistentAggregatorError(c, oa)
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
|
||||
@ -61,17 +61,17 @@ var (
|
||||
boundaries = []float64{500, 250, 750}
|
||||
)
|
||||
|
||||
func new2(desc *otel.Descriptor) (_, _ *histogram.Aggregator) {
|
||||
func new2(desc *metric.Descriptor) (_, _ *histogram.Aggregator) {
|
||||
alloc := histogram.New(2, desc, boundaries)
|
||||
return &alloc[0], &alloc[1]
|
||||
}
|
||||
|
||||
func new4(desc *otel.Descriptor) (_, _, _, _ *histogram.Aggregator) {
|
||||
func new4(desc *metric.Descriptor) (_, _, _, _ *histogram.Aggregator) {
|
||||
alloc := histogram.New(4, desc, boundaries)
|
||||
return &alloc[0], &alloc[1], &alloc[2], &alloc[3]
|
||||
}
|
||||
|
||||
func checkZero(t *testing.T, agg *histogram.Aggregator, desc *otel.Descriptor) {
|
||||
func checkZero(t *testing.T, agg *histogram.Aggregator, desc *metric.Descriptor) {
|
||||
asum, err := agg.Sum()
|
||||
require.Equal(t, number.Number(0), asum, "Empty checkpoint sum = 0")
|
||||
require.NoError(t, err)
|
||||
@ -110,7 +110,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(otel.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
|
||||
agg, ckpt := new2(descriptor)
|
||||
|
||||
@ -155,7 +155,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(otel.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
|
||||
agg := &histogram.New(1, descriptor, boundaries)[0]
|
||||
buckets, err := agg.Histogram()
|
||||
@ -168,7 +168,7 @@ func TestHistogramInitial(t *testing.T) {
|
||||
|
||||
func TestHistogramMerge(t *testing.T) {
|
||||
aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) {
|
||||
descriptor := aggregatortest.NewAggregatorTest(otel.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
|
||||
agg1, agg2, ckpt1, ckpt2 := new4(descriptor)
|
||||
|
||||
@ -220,7 +220,7 @@ func TestHistogramMerge(t *testing.T) {
|
||||
|
||||
func TestHistogramNotSet(t *testing.T) {
|
||||
aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) {
|
||||
descriptor := aggregatortest.NewAggregatorTest(otel.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
|
||||
agg, ckpt := new2(descriptor)
|
||||
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
@ -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, _ *otel.Descriptor) error {
|
||||
func (g *Aggregator) SynchronizedMove(oa export.Aggregator, _ *metric.Descriptor) error {
|
||||
o, _ := oa.(*Aggregator)
|
||||
if o == nil {
|
||||
return aggregator.NewInconsistentAggregatorError(g, oa)
|
||||
@ -102,7 +102,7 @@ func (g *Aggregator) SynchronizedMove(oa export.Aggregator, _ *otel.Descriptor)
|
||||
}
|
||||
|
||||
// Update atomically sets the current "last" value.
|
||||
func (g *Aggregator) Update(_ context.Context, number number.Number, desc *otel.Descriptor) error {
|
||||
func (g *Aggregator) Update(_ context.Context, number number.Number, desc *metric.Descriptor) error {
|
||||
ngd := &lastValueData{
|
||||
value: number,
|
||||
timestamp: time.Now(),
|
||||
@ -113,7 +113,7 @@ func (g *Aggregator) Update(_ context.Context, number number.Number, desc *otel.
|
||||
|
||||
// Merge combines state from two aggregators. The most-recently set
|
||||
// value is chosen.
|
||||
func (g *Aggregator) Merge(oa export.Aggregator, desc *otel.Descriptor) error {
|
||||
func (g *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error {
|
||||
o, _ := oa.(*Aggregator)
|
||||
if o == nil {
|
||||
return aggregator.NewInconsistentAggregatorError(g, oa)
|
||||
|
@ -24,8 +24,8 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
ottest "go.opentelemetry.io/otel/internal/testing"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
@ -72,7 +72,7 @@ func TestLastValueUpdate(t *testing.T) {
|
||||
aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) {
|
||||
agg, ckpt := new2()
|
||||
|
||||
record := aggregatortest.NewAggregatorTest(otel.ValueObserverInstrumentKind, profile.NumberKind)
|
||||
record := aggregatortest.NewAggregatorTest(metric.ValueObserverInstrumentKind, profile.NumberKind)
|
||||
|
||||
var last number.Number
|
||||
for i := 0; i < count; i++ {
|
||||
@ -94,7 +94,7 @@ func TestLastValueMerge(t *testing.T) {
|
||||
aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) {
|
||||
agg1, agg2, ckpt1, ckpt2 := new4()
|
||||
|
||||
descriptor := aggregatortest.NewAggregatorTest(otel.ValueObserverInstrumentKind, profile.NumberKind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.ValueObserverInstrumentKind, profile.NumberKind)
|
||||
|
||||
first1 := profile.Random(+1)
|
||||
first2 := profile.Random(+1)
|
||||
@ -125,7 +125,7 @@ func TestLastValueMerge(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLastValueNotSet(t *testing.T) {
|
||||
descriptor := aggregatortest.NewAggregatorTest(otel.ValueObserverInstrumentKind, number.Int64Kind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.ValueObserverInstrumentKind, number.Int64Kind)
|
||||
|
||||
g, ckpt := new2()
|
||||
require.NoError(t, g.SynchronizedMove(ckpt, descriptor))
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
@ -50,7 +50,7 @@ var _ aggregation.MinMaxSumCount = &Aggregator{}
|
||||
// Max.
|
||||
//
|
||||
// This type uses a mutex for Update() and SynchronizedMove() concurrency.
|
||||
func New(cnt int, desc *otel.Descriptor) []Aggregator {
|
||||
func New(cnt int, desc *metric.Descriptor) []Aggregator {
|
||||
kind := desc.NumberKind()
|
||||
aggs := make([]Aggregator, cnt)
|
||||
for i := range aggs {
|
||||
@ -104,7 +104,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 *otel.Descriptor) error {
|
||||
func (c *Aggregator) SynchronizedMove(oa export.Aggregator, desc *metric.Descriptor) error {
|
||||
o, _ := oa.(*Aggregator)
|
||||
if o == nil {
|
||||
return aggregator.NewInconsistentAggregatorError(c, oa)
|
||||
@ -130,7 +130,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 *otel.Descriptor) error {
|
||||
func (c *Aggregator) Update(_ context.Context, number number.Number, desc *metric.Descriptor) error {
|
||||
kind := desc.NumberKind()
|
||||
|
||||
c.lock.Lock()
|
||||
@ -147,7 +147,7 @@ func (c *Aggregator) Update(_ context.Context, number number.Number, desc *otel.
|
||||
}
|
||||
|
||||
// Merge combines two data sets into one.
|
||||
func (c *Aggregator) Merge(oa export.Aggregator, desc *otel.Descriptor) error {
|
||||
func (c *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error {
|
||||
o, _ := oa.(*Aggregator)
|
||||
if o == nil {
|
||||
return aggregator.NewInconsistentAggregatorError(c, oa)
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest"
|
||||
@ -77,17 +77,17 @@ func TestMinMaxSumCountPositiveAndNegative(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func new2(desc *otel.Descriptor) (_, _ *Aggregator) {
|
||||
func new2(desc *metric.Descriptor) (_, _ *Aggregator) {
|
||||
alloc := New(2, desc)
|
||||
return &alloc[0], &alloc[1]
|
||||
}
|
||||
|
||||
func new4(desc *otel.Descriptor) (_, _, _, _ *Aggregator) {
|
||||
func new4(desc *metric.Descriptor) (_, _, _, _ *Aggregator) {
|
||||
alloc := New(4, desc)
|
||||
return &alloc[0], &alloc[1], &alloc[2], &alloc[3]
|
||||
}
|
||||
|
||||
func checkZero(t *testing.T, agg *Aggregator, desc *otel.Descriptor) {
|
||||
func checkZero(t *testing.T, agg *Aggregator, desc *metric.Descriptor) {
|
||||
kind := desc.NumberKind()
|
||||
|
||||
sum, err := agg.Sum()
|
||||
@ -109,7 +109,7 @@ func checkZero(t *testing.T, agg *Aggregator, desc *otel.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(otel.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
|
||||
agg, ckpt := new2(descriptor)
|
||||
|
||||
@ -157,7 +157,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(otel.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
|
||||
agg1, agg2, ckpt1, ckpt2 := new4(descriptor)
|
||||
|
||||
@ -215,7 +215,7 @@ func TestMinMaxSumCountMerge(t *testing.T) {
|
||||
|
||||
func TestMaxSumCountNotSet(t *testing.T) {
|
||||
aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) {
|
||||
descriptor := aggregatortest.NewAggregatorTest(otel.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
|
||||
alloc := New(2, descriptor)
|
||||
agg, ckpt := &alloc[0], &alloc[1]
|
||||
|
@ -17,7 +17,7 @@ package sum // import "go.opentelemetry.io/otel/sdk/metric/aggregator/sum"
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
@ -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, _ *otel.Descriptor) error {
|
||||
func (c *Aggregator) SynchronizedMove(oa export.Aggregator, _ *metric.Descriptor) error {
|
||||
o, _ := oa.(*Aggregator)
|
||||
if o == nil {
|
||||
return aggregator.NewInconsistentAggregatorError(c, oa)
|
||||
@ -70,13 +70,13 @@ func (c *Aggregator) SynchronizedMove(oa export.Aggregator, _ *otel.Descriptor)
|
||||
}
|
||||
|
||||
// Update atomically adds to the current value.
|
||||
func (c *Aggregator) Update(_ context.Context, num number.Number, desc *otel.Descriptor) error {
|
||||
func (c *Aggregator) Update(_ context.Context, num number.Number, desc *metric.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 *otel.Descriptor) error {
|
||||
func (c *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error {
|
||||
o, _ := oa.(*Aggregator)
|
||||
if o == nil {
|
||||
return aggregator.NewInconsistentAggregatorError(c, oa)
|
||||
@ -85,7 +85,7 @@ func (c *Aggregator) Merge(oa export.Aggregator, desc *otel.Descriptor) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Aggregator) Subtract(opAgg, resAgg export.Aggregator, descriptor *otel.Descriptor) error {
|
||||
func (c *Aggregator) Subtract(opAgg, resAgg export.Aggregator, descriptor *metric.Descriptor) error {
|
||||
op, _ := opAgg.(*Aggregator)
|
||||
if op == nil {
|
||||
return aggregator.NewInconsistentAggregatorError(c, opAgg)
|
||||
|
@ -21,8 +21,8 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
ottest "go.opentelemetry.io/otel/internal/testing"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest"
|
||||
)
|
||||
@ -54,7 +54,7 @@ func new4() (_, _, _, _ *Aggregator) {
|
||||
return &alloc[0], &alloc[1], &alloc[2], &alloc[3]
|
||||
}
|
||||
|
||||
func checkZero(t *testing.T, agg *Aggregator, desc *otel.Descriptor) {
|
||||
func checkZero(t *testing.T, agg *Aggregator, desc *metric.Descriptor) {
|
||||
kind := desc.NumberKind()
|
||||
|
||||
sum, err := agg.Sum()
|
||||
@ -66,7 +66,7 @@ func TestCounterSum(t *testing.T) {
|
||||
aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) {
|
||||
agg, ckpt := new2()
|
||||
|
||||
descriptor := aggregatortest.NewAggregatorTest(otel.CounterInstrumentKind, profile.NumberKind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.CounterInstrumentKind, profile.NumberKind)
|
||||
|
||||
sum := number.Number(0)
|
||||
for i := 0; i < count; i++ {
|
||||
@ -90,7 +90,7 @@ func TestValueRecorderSum(t *testing.T) {
|
||||
aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) {
|
||||
agg, ckpt := new2()
|
||||
|
||||
descriptor := aggregatortest.NewAggregatorTest(otel.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind)
|
||||
|
||||
sum := number.Number(0)
|
||||
|
||||
@ -116,7 +116,7 @@ func TestCounterMerge(t *testing.T) {
|
||||
aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) {
|
||||
agg1, agg2, ckpt1, ckpt2 := new4()
|
||||
|
||||
descriptor := aggregatortest.NewAggregatorTest(otel.CounterInstrumentKind, profile.NumberKind)
|
||||
descriptor := aggregatortest.NewAggregatorTest(metric.CounterInstrumentKind, profile.NumberKind)
|
||||
|
||||
sum := number.Number(0)
|
||||
for i := 0; i < count; i++ {
|
||||
|
@ -20,16 +20,16 @@ import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/global"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
sdk "go.opentelemetry.io/otel/sdk/metric"
|
||||
"go.opentelemetry.io/otel/sdk/metric/processor/processortest"
|
||||
)
|
||||
|
||||
type benchFixture struct {
|
||||
meter otel.Meter
|
||||
meter metric.Meter
|
||||
accumulator *sdk.Accumulator
|
||||
B *testing.B
|
||||
export.AggregatorSelector
|
||||
@ -43,7 +43,7 @@ func newFixture(b *testing.B) *benchFixture {
|
||||
}
|
||||
|
||||
bf.accumulator = sdk.NewAccumulator(bf, nil)
|
||||
bf.meter = otel.WrapMeterImpl(bf.accumulator, "benchmarks")
|
||||
bf.meter = metric.WrapMeterImpl(bf.accumulator, "benchmarks")
|
||||
return bf
|
||||
}
|
||||
|
||||
@ -51,12 +51,12 @@ func (f *benchFixture) Process(export.Accumulation) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *benchFixture) Meter(_ string, _ ...otel.MeterOption) otel.Meter {
|
||||
func (f *benchFixture) Meter(_ string, _ ...metric.MeterOption) metric.Meter {
|
||||
return f.meter
|
||||
}
|
||||
|
||||
func (f *benchFixture) meterMust() otel.MeterMust {
|
||||
return otel.Must(f.meter)
|
||||
func (f *benchFixture) meterMust() metric.MeterMust {
|
||||
return metric.Must(f.meter)
|
||||
}
|
||||
|
||||
func makeManyLabels(n int) [][]label.KeyValue {
|
||||
@ -401,7 +401,7 @@ func BenchmarkObserverRegistration(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
names = append(names, fmt.Sprintf("test.%d.lastvalue", i))
|
||||
}
|
||||
cb := func(_ context.Context, result otel.Int64ObserverResult) {}
|
||||
cb := func(_ context.Context, result metric.Int64ObserverResult) {}
|
||||
|
||||
b.ResetTimer()
|
||||
|
||||
@ -414,7 +414,7 @@ func BenchmarkValueObserverObservationInt64(b *testing.B) {
|
||||
ctx := context.Background()
|
||||
fix := newFixture(b)
|
||||
labs := makeLabels(1)
|
||||
_ = fix.meterMust().NewInt64ValueObserver("test.lastvalue", func(_ context.Context, result otel.Int64ObserverResult) {
|
||||
_ = fix.meterMust().NewInt64ValueObserver("test.lastvalue", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
result.Observe((int64)(i), labs...)
|
||||
}
|
||||
@ -429,7 +429,7 @@ func BenchmarkValueObserverObservationFloat64(b *testing.B) {
|
||||
ctx := context.Background()
|
||||
fix := newFixture(b)
|
||||
labs := makeLabels(1)
|
||||
_ = fix.meterMust().NewFloat64ValueObserver("test.lastvalue", func(_ context.Context, result otel.Float64ObserverResult) {
|
||||
_ = fix.meterMust().NewFloat64ValueObserver("test.lastvalue", func(_ context.Context, result metric.Float64ObserverResult) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
result.Observe((float64)(i), labs...)
|
||||
}
|
||||
@ -501,7 +501,7 @@ func benchmarkBatchRecord8Labels(b *testing.B, numInst int) {
|
||||
ctx := context.Background()
|
||||
fix := newFixture(b)
|
||||
labs := makeLabels(numLabels)
|
||||
var meas []otel.Measurement
|
||||
var meas []metric.Measurement
|
||||
|
||||
for i := 0; i < numInst; i++ {
|
||||
inst := fix.meterMust().NewInt64Counter(fmt.Sprintf("int64.%d.sum", i))
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/registry"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
sdk "go.opentelemetry.io/otel/sdk/metric"
|
||||
@ -81,7 +81,7 @@ func (c *Controller) SetClock(clock controllerTime.Clock) {
|
||||
|
||||
// MeterProvider returns a MeterProvider for the implementation managed by
|
||||
// this controller.
|
||||
func (c *Controller) MeterProvider() otel.MeterProvider {
|
||||
func (c *Controller) MeterProvider() metric.MeterProvider {
|
||||
return c.provider
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/metric/controller/controllertest"
|
||||
"go.opentelemetry.io/otel/sdk/metric/controller/pull"
|
||||
@ -44,7 +44,7 @@ func TestPullNoCache(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
meter := puller.MeterProvider().Meter("nocache")
|
||||
counter := otel.Must(meter).NewInt64Counter("counter.sum")
|
||||
counter := metric.Must(meter).NewInt64Counter("counter.sum")
|
||||
|
||||
counter.Add(ctx, 10, label.String("A", "B"))
|
||||
|
||||
@ -81,7 +81,7 @@ func TestPullWithCache(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
meter := puller.MeterProvider().Meter("nocache")
|
||||
counter := otel.Must(meter).NewInt64Counter("counter.sum")
|
||||
counter := metric.Must(meter).NewInt64Counter("counter.sum")
|
||||
|
||||
counter.Add(ctx, 10, label.String("A", "B"))
|
||||
|
||||
|
@ -19,8 +19,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/global"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/registry"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
sdk "go.opentelemetry.io/otel/sdk/metric"
|
||||
@ -84,7 +84,7 @@ func (c *Controller) SetClock(clock controllerTime.Clock) {
|
||||
}
|
||||
|
||||
// MeterProvider returns a MeterProvider instance for this controller.
|
||||
func (c *Controller) MeterProvider() otel.MeterProvider {
|
||||
func (c *Controller) MeterProvider() metric.MeterProvider {
|
||||
return c.provider
|
||||
}
|
||||
|
||||
|
@ -24,9 +24,9 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/global"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/controller/controllertest"
|
||||
@ -114,7 +114,7 @@ func TestPushTicker(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
counter := otel.Must(meter).NewInt64Counter("counter.sum")
|
||||
counter := metric.Must(meter).NewInt64Counter("counter.sum")
|
||||
|
||||
p.Start()
|
||||
|
||||
@ -194,8 +194,8 @@ func TestPushExportError(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
meter := p.MeterProvider().Meter("name")
|
||||
counter1 := otel.Must(meter).NewInt64Counter("counter1.sum")
|
||||
counter2 := otel.Must(meter).NewInt64Counter("counter2.sum")
|
||||
counter1 := metric.Must(meter).NewInt64Counter("counter1.sum")
|
||||
counter2 := metric.Must(meter).NewInt64Counter("counter2.sum")
|
||||
|
||||
p.Start()
|
||||
runtime.Gosched()
|
||||
|
@ -23,9 +23,9 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/global"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
@ -34,7 +34,7 @@ import (
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
)
|
||||
|
||||
var Must = otel.Must
|
||||
var Must = metric.Must
|
||||
var testResource = resource.NewWithAttributes(label.String("R", "V"))
|
||||
|
||||
type handler struct {
|
||||
@ -84,12 +84,12 @@ type testSelector struct {
|
||||
newAggCount int
|
||||
}
|
||||
|
||||
func (ts *testSelector) AggregatorFor(desc *otel.Descriptor, aggPtrs ...*export.Aggregator) {
|
||||
func (ts *testSelector) AggregatorFor(desc *metric.Descriptor, aggPtrs ...*export.Aggregator) {
|
||||
ts.newAggCount += len(aggPtrs)
|
||||
processortest.AggregatorSelector().AggregatorFor(desc, aggPtrs...)
|
||||
}
|
||||
|
||||
func newSDK(t *testing.T) (otel.Meter, *metricsdk.Accumulator, *correctnessProcessor) {
|
||||
func newSDK(t *testing.T) (metric.Meter, *metricsdk.Accumulator, *correctnessProcessor) {
|
||||
testHandler.Reset()
|
||||
processor := &correctnessProcessor{
|
||||
t: t,
|
||||
@ -99,7 +99,7 @@ func newSDK(t *testing.T) (otel.Meter, *metricsdk.Accumulator, *correctnessProce
|
||||
processor,
|
||||
testResource,
|
||||
)
|
||||
meter := otel.WrapMeterImpl(accum, "test")
|
||||
meter := metric.WrapMeterImpl(accum, "test")
|
||||
return meter, accum, processor
|
||||
}
|
||||
|
||||
@ -301,13 +301,13 @@ func TestObserverCollection(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
meter, sdk, processor := newSDK(t)
|
||||
|
||||
_ = Must(meter).NewFloat64ValueObserver("float.valueobserver.lastvalue", func(_ context.Context, result otel.Float64ObserverResult) {
|
||||
_ = Must(meter).NewFloat64ValueObserver("float.valueobserver.lastvalue", func(_ context.Context, result metric.Float64ObserverResult) {
|
||||
result.Observe(1, label.String("A", "B"))
|
||||
// last value wins
|
||||
result.Observe(-1, label.String("A", "B"))
|
||||
result.Observe(-1, label.String("C", "D"))
|
||||
})
|
||||
_ = Must(meter).NewInt64ValueObserver("int.valueobserver.lastvalue", func(_ context.Context, result otel.Int64ObserverResult) {
|
||||
_ = Must(meter).NewInt64ValueObserver("int.valueobserver.lastvalue", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||
result.Observe(-1, label.String("A", "B"))
|
||||
result.Observe(1)
|
||||
// last value wins
|
||||
@ -315,12 +315,12 @@ func TestObserverCollection(t *testing.T) {
|
||||
result.Observe(1)
|
||||
})
|
||||
|
||||
_ = Must(meter).NewFloat64SumObserver("float.sumobserver.sum", func(_ context.Context, result otel.Float64ObserverResult) {
|
||||
_ = Must(meter).NewFloat64SumObserver("float.sumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) {
|
||||
result.Observe(1, label.String("A", "B"))
|
||||
result.Observe(2, label.String("A", "B"))
|
||||
result.Observe(1, label.String("C", "D"))
|
||||
})
|
||||
_ = Must(meter).NewInt64SumObserver("int.sumobserver.sum", func(_ context.Context, result otel.Int64ObserverResult) {
|
||||
_ = Must(meter).NewInt64SumObserver("int.sumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||
result.Observe(2, label.String("A", "B"))
|
||||
result.Observe(1)
|
||||
// last value wins
|
||||
@ -328,12 +328,12 @@ func TestObserverCollection(t *testing.T) {
|
||||
result.Observe(1)
|
||||
})
|
||||
|
||||
_ = Must(meter).NewFloat64UpDownSumObserver("float.updownsumobserver.sum", func(_ context.Context, result otel.Float64ObserverResult) {
|
||||
_ = Must(meter).NewFloat64UpDownSumObserver("float.updownsumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) {
|
||||
result.Observe(1, label.String("A", "B"))
|
||||
result.Observe(-2, label.String("A", "B"))
|
||||
result.Observe(1, label.String("C", "D"))
|
||||
})
|
||||
_ = Must(meter).NewInt64UpDownSumObserver("int.updownsumobserver.sum", func(_ context.Context, result otel.Int64ObserverResult) {
|
||||
_ = Must(meter).NewInt64UpDownSumObserver("int.updownsumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||
result.Observe(2, label.String("A", "B"))
|
||||
result.Observe(1)
|
||||
// last value wins
|
||||
@ -341,7 +341,7 @@ func TestObserverCollection(t *testing.T) {
|
||||
result.Observe(-1)
|
||||
})
|
||||
|
||||
_ = Must(meter).NewInt64ValueObserver("empty.valueobserver.sum", func(_ context.Context, result otel.Int64ObserverResult) {
|
||||
_ = Must(meter).NewInt64ValueObserver("empty.valueobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||
})
|
||||
|
||||
collected := sdk.Collect(ctx)
|
||||
@ -375,13 +375,13 @@ func TestSumObserverInputRange(t *testing.T) {
|
||||
meter, sdk, processor := newSDK(t)
|
||||
|
||||
// TODO: these tests are testing for negative values, not for _descending values_. Fix.
|
||||
_ = Must(meter).NewFloat64SumObserver("float.sumobserver.sum", func(_ context.Context, result otel.Float64ObserverResult) {
|
||||
_ = Must(meter).NewFloat64SumObserver("float.sumobserver.sum", func(_ context.Context, result metric.Float64ObserverResult) {
|
||||
result.Observe(-2, label.String("A", "B"))
|
||||
require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush())
|
||||
result.Observe(-1, label.String("C", "D"))
|
||||
require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush())
|
||||
})
|
||||
_ = Must(meter).NewInt64SumObserver("int.sumobserver.sum", func(_ context.Context, result otel.Int64ObserverResult) {
|
||||
_ = Must(meter).NewInt64SumObserver("int.sumobserver.sum", func(_ context.Context, result metric.Int64ObserverResult) {
|
||||
result.Observe(-1, label.String("A", "B"))
|
||||
require.Equal(t, aggregation.ErrNegativeInput, testHandler.Flush())
|
||||
result.Observe(-1)
|
||||
@ -401,15 +401,15 @@ func TestObserverBatch(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
meter, sdk, processor := newSDK(t)
|
||||
|
||||
var floatValueObs otel.Float64ValueObserver
|
||||
var intValueObs otel.Int64ValueObserver
|
||||
var floatSumObs otel.Float64SumObserver
|
||||
var intSumObs otel.Int64SumObserver
|
||||
var floatUpDownSumObs otel.Float64UpDownSumObserver
|
||||
var intUpDownSumObs otel.Int64UpDownSumObserver
|
||||
var floatValueObs metric.Float64ValueObserver
|
||||
var intValueObs metric.Int64ValueObserver
|
||||
var floatSumObs metric.Float64SumObserver
|
||||
var intSumObs metric.Int64SumObserver
|
||||
var floatUpDownSumObs metric.Float64UpDownSumObserver
|
||||
var intUpDownSumObs metric.Int64UpDownSumObserver
|
||||
|
||||
var batch = Must(meter).NewBatchObserver(
|
||||
func(_ context.Context, result otel.BatchObserverResult) {
|
||||
func(_ context.Context, result metric.BatchObserverResult) {
|
||||
result.Observe(
|
||||
[]label.KeyValue{
|
||||
label.String("A", "B"),
|
||||
@ -531,15 +531,15 @@ func TestRecordPersistence(t *testing.T) {
|
||||
func TestIncorrectInstruments(t *testing.T) {
|
||||
// The Batch observe/record APIs are susceptible to
|
||||
// uninitialized instruments.
|
||||
var counter otel.Int64Counter
|
||||
var observer otel.Int64ValueObserver
|
||||
var counter metric.Int64Counter
|
||||
var observer metric.Int64ValueObserver
|
||||
|
||||
ctx := context.Background()
|
||||
meter, sdk, _ := newSDK(t)
|
||||
|
||||
// Now try with uninitialized instruments.
|
||||
meter.RecordBatch(ctx, nil, counter.Measurement(1))
|
||||
meter.NewBatchObserver(func(_ context.Context, result otel.BatchObserverResult) {
|
||||
meter.NewBatchObserver(func(_ context.Context, result metric.BatchObserverResult) {
|
||||
result.Observe(nil, observer.Observation(1))
|
||||
})
|
||||
|
||||
@ -548,14 +548,14 @@ func TestIncorrectInstruments(t *testing.T) {
|
||||
require.Equal(t, 0, collected)
|
||||
|
||||
// Now try with instruments from another SDK.
|
||||
var noopMeter otel.Meter
|
||||
counter = otel.Must(noopMeter).NewInt64Counter("name.sum")
|
||||
observer = otel.Must(noopMeter).NewBatchObserver(
|
||||
func(context.Context, otel.BatchObserverResult) {},
|
||||
var noopMeter metric.Meter
|
||||
counter = metric.Must(noopMeter).NewInt64Counter("name.sum")
|
||||
observer = metric.Must(noopMeter).NewBatchObserver(
|
||||
func(context.Context, metric.BatchObserverResult) {},
|
||||
).NewInt64ValueObserver("observer")
|
||||
|
||||
meter.RecordBatch(ctx, nil, counter.Measurement(1))
|
||||
meter.NewBatchObserver(func(_ context.Context, result otel.BatchObserverResult) {
|
||||
meter.NewBatchObserver(func(_ context.Context, result metric.BatchObserverResult) {
|
||||
result.Observe(nil, observer.Observation(1))
|
||||
})
|
||||
|
||||
@ -570,7 +570,7 @@ func TestSyncInAsync(t *testing.T) {
|
||||
|
||||
counter := Must(meter).NewFloat64Counter("counter.sum")
|
||||
_ = Must(meter).NewInt64ValueObserver("observer.lastvalue",
|
||||
func(ctx context.Context, result otel.Int64ObserverResult) {
|
||||
func(ctx context.Context, result metric.Int64ObserverResult) {
|
||||
result.Observe(10)
|
||||
counter.Add(ctx, 100)
|
||||
},
|
||||
|
@ -22,13 +22,13 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
|
||||
)
|
||||
|
||||
func TestStressInt64Histogram(t *testing.T) {
|
||||
desc := otel.NewDescriptor("some_metric", otel.ValueRecorderInstrumentKind, number.Int64Kind)
|
||||
desc := metric.NewDescriptor("some_metric", metric.ValueRecorderInstrumentKind, number.Int64Kind)
|
||||
|
||||
alloc := histogram.New(2, &desc, []float64{25, 50, 75})
|
||||
h, ckpt := &alloc[0], &alloc[1]
|
||||
|
@ -20,13 +20,13 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount"
|
||||
)
|
||||
|
||||
func TestStressInt64MinMaxSumCount(t *testing.T) {
|
||||
desc := otel.NewDescriptor("some_metric", otel.ValueRecorderInstrumentKind, number.Int64Kind)
|
||||
desc := metric.NewDescriptor("some_metric", metric.ValueRecorderInstrumentKind, number.Int64Kind)
|
||||
alloc := minmaxsumcount.New(2, &desc)
|
||||
mmsc, ckpt := &alloc[0], &alloc[1]
|
||||
|
||||
|
@ -20,8 +20,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
@ -41,13 +41,13 @@ type (
|
||||
// data for the same instrument with the same
|
||||
// resources, and this code has logic to combine data
|
||||
// properly from multiple accumulators. However, the
|
||||
// use of *otel.Descriptor in the stateKey makes
|
||||
// use of *metric.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 *otel.Descriptor
|
||||
descriptor *metric.Descriptor
|
||||
distinct label.Distinct
|
||||
resource label.Distinct
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
@ -41,7 +41,7 @@ func TestProcessor(t *testing.T) {
|
||||
kind export.ExportKind
|
||||
}
|
||||
type instrumentCase struct {
|
||||
kind otel.InstrumentKind
|
||||
kind metric.InstrumentKind
|
||||
}
|
||||
type numberCase struct {
|
||||
kind number.Kind
|
||||
@ -56,12 +56,12 @@ func TestProcessor(t *testing.T) {
|
||||
} {
|
||||
t.Run(tc.kind.String(), func(t *testing.T) {
|
||||
for _, ic := range []instrumentCase{
|
||||
{kind: otel.CounterInstrumentKind},
|
||||
{kind: otel.UpDownCounterInstrumentKind},
|
||||
{kind: otel.ValueRecorderInstrumentKind},
|
||||
{kind: otel.SumObserverInstrumentKind},
|
||||
{kind: otel.UpDownSumObserverInstrumentKind},
|
||||
{kind: otel.ValueObserverInstrumentKind},
|
||||
{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{
|
||||
@ -102,7 +102,7 @@ func asNumber(nkind number.Kind, value int64) number.Number {
|
||||
return number.NewFloat64Number(float64(value))
|
||||
}
|
||||
|
||||
func updateFor(t *testing.T, desc *otel.Descriptor, selector export.AggregatorSelector, res *resource.Resource, value int64, labs ...label.KeyValue) export.Accumulation {
|
||||
func updateFor(t *testing.T, desc *metric.Descriptor, selector export.AggregatorSelector, res *resource.Resource, value int64, labs ...label.KeyValue) export.Accumulation {
|
||||
ls := label.NewSet(labs...)
|
||||
var agg export.Aggregator
|
||||
selector.AggregatorFor(desc, &agg)
|
||||
@ -114,7 +114,7 @@ func updateFor(t *testing.T, desc *otel.Descriptor, selector export.AggregatorSe
|
||||
func testProcessor(
|
||||
t *testing.T,
|
||||
ekind export.ExportKind,
|
||||
mkind otel.InstrumentKind,
|
||||
mkind metric.InstrumentKind,
|
||||
nkind number.Kind,
|
||||
akind aggregation.Kind,
|
||||
) {
|
||||
@ -131,8 +131,8 @@ func testProcessor(
|
||||
|
||||
instSuffix := fmt.Sprint(".", strings.ToLower(akind.String()))
|
||||
|
||||
desc1 := otel.NewDescriptor(fmt.Sprint("inst1", instSuffix), mkind, nkind)
|
||||
desc2 := otel.NewDescriptor(fmt.Sprint("inst2", instSuffix), mkind, nkind)
|
||||
desc1 := metric.NewDescriptor(fmt.Sprint("inst1", instSuffix), mkind, nkind)
|
||||
desc2 := metric.NewDescriptor(fmt.Sprint("inst2", instSuffix), mkind, nkind)
|
||||
|
||||
for nc := 0; nc < nCheckpoint; nc++ {
|
||||
|
||||
@ -258,7 +258,7 @@ func testProcessor(
|
||||
|
||||
type bogusExporter struct{}
|
||||
|
||||
func (bogusExporter) ExportKindFor(*otel.Descriptor, aggregation.Kind) export.ExportKind {
|
||||
func (bogusExporter) ExportKindFor(*metric.Descriptor, aggregation.Kind) export.ExportKind {
|
||||
return 1000000
|
||||
}
|
||||
|
||||
@ -295,7 +295,7 @@ func TestBasicInconsistent(t *testing.T) {
|
||||
// Test no start
|
||||
b = basic.New(processorTest.AggregatorSelector(), export.StatelessExportKindSelector())
|
||||
|
||||
desc := otel.NewDescriptor("inst", otel.CounterInstrumentKind, number.Int64Kind)
|
||||
desc := metric.NewDescriptor("inst", metric.CounterInstrumentKind, number.Int64Kind)
|
||||
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.StatelessExportKindSelector())
|
||||
afterNew := time.Now()
|
||||
|
||||
desc := otel.NewDescriptor("inst", otel.CounterInstrumentKind, number.Int64Kind)
|
||||
desc := metric.NewDescriptor("inst", metric.CounterInstrumentKind, number.Int64Kind)
|
||||
accum := export.NewAccumulation(&desc, label.EmptySet(), resource.Empty(), metrictest.NoopAggregator{})
|
||||
|
||||
b.StartCollection()
|
||||
@ -364,7 +364,7 @@ func TestStatefulNoMemoryCumulative(t *testing.T) {
|
||||
res := resource.NewWithAttributes(label.String("R", "V"))
|
||||
ekindSel := export.CumulativeExportKindSelector()
|
||||
|
||||
desc := otel.NewDescriptor("inst.sum", otel.CounterInstrumentKind, number.Int64Kind)
|
||||
desc := metric.NewDescriptor("inst.sum", metric.CounterInstrumentKind, number.Int64Kind)
|
||||
selector := processorTest.AggregatorSelector()
|
||||
|
||||
processor := basic.New(selector, ekindSel, basic.WithMemory(false))
|
||||
@ -398,7 +398,7 @@ func TestStatefulNoMemoryDelta(t *testing.T) {
|
||||
res := resource.NewWithAttributes(label.String("R", "V"))
|
||||
ekindSel := export.DeltaExportKindSelector()
|
||||
|
||||
desc := otel.NewDescriptor("inst.sum", otel.SumObserverInstrumentKind, number.Int64Kind)
|
||||
desc := metric.NewDescriptor("inst.sum", metric.SumObserverInstrumentKind, number.Int64Kind)
|
||||
selector := processorTest.AggregatorSelector()
|
||||
|
||||
processor := basic.New(selector, ekindSel, basic.WithMemory(false))
|
||||
@ -435,7 +435,7 @@ func TestMultiObserverSum(t *testing.T) {
|
||||
} {
|
||||
|
||||
res := resource.NewWithAttributes(label.String("R", "V"))
|
||||
desc := otel.NewDescriptor("observe.sum", otel.SumObserverInstrumentKind, number.Int64Kind)
|
||||
desc := metric.NewDescriptor("observe.sum", metric.SumObserverInstrumentKind, number.Int64Kind)
|
||||
selector := processorTest.AggregatorSelector()
|
||||
|
||||
processor := basic.New(selector, ekindSel, basic.WithMemory(false))
|
||||
|
@ -21,8 +21,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/array"
|
||||
@ -39,7 +39,7 @@ type (
|
||||
// unique descriptor, distinct labels, and distinct resource
|
||||
// attributes.
|
||||
mapKey struct {
|
||||
desc *otel.Descriptor
|
||||
desc *metric.Descriptor
|
||||
labels label.Distinct
|
||||
resource label.Distinct
|
||||
}
|
||||
@ -161,7 +161,7 @@ func AggregatorSelector() export.AggregatorSelector {
|
||||
}
|
||||
|
||||
// AggregatorFor implements export.AggregatorSelector.
|
||||
func (testAggregatorSelector) AggregatorFor(desc *otel.Descriptor, aggPtrs ...*export.Aggregator) {
|
||||
func (testAggregatorSelector) AggregatorFor(desc *metric.Descriptor, aggPtrs ...*export.Aggregator) {
|
||||
|
||||
switch {
|
||||
case strings.HasSuffix(desc.Name(), ".disabled"):
|
||||
|
@ -20,8 +20,8 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
metricsdk "go.opentelemetry.io/otel/sdk/metric"
|
||||
processorTest "go.opentelemetry.io/otel/sdk/metric/processor/processortest"
|
||||
@ -34,12 +34,12 @@ func generateTestData(proc export.Processor) {
|
||||
proc,
|
||||
resource.NewWithAttributes(label.String("R", "V")),
|
||||
)
|
||||
meter := otel.WrapMeterImpl(accum, "testing")
|
||||
meter := metric.WrapMeterImpl(accum, "testing")
|
||||
|
||||
counter := otel.Must(meter).NewFloat64Counter("counter.sum")
|
||||
counter := metric.Must(meter).NewFloat64Counter("counter.sum")
|
||||
|
||||
_ = otel.Must(meter).NewInt64SumObserver("observer.sum",
|
||||
func(_ context.Context, result otel.Int64ObserverResult) {
|
||||
_ = metric.Must(meter).NewInt64SumObserver("observer.sum",
|
||||
func(_ context.Context, result metric.Int64ObserverResult) {
|
||||
result.Observe(10, label.String("K1", "V1"))
|
||||
result.Observe(11, label.String("K1", "V2"))
|
||||
},
|
||||
|
@ -15,8 +15,8 @@
|
||||
package reducer // import "go.opentelemetry.io/otel/sdk/metric/processor/reducer"
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
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 *otel.Descriptor) label.Filter
|
||||
LabelFilterFor(descriptor *metric.Descriptor) label.Filter
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -20,8 +20,8 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
metricsdk "go.opentelemetry.io/otel/sdk/metric"
|
||||
"go.opentelemetry.io/otel/sdk/metric/processor/basic"
|
||||
@ -45,20 +45,20 @@ var (
|
||||
|
||||
type testFilter struct{}
|
||||
|
||||
func (testFilter) LabelFilterFor(_ *otel.Descriptor) label.Filter {
|
||||
func (testFilter) LabelFilterFor(_ *metric.Descriptor) label.Filter {
|
||||
return func(label label.KeyValue) bool {
|
||||
return label.Key == "A" || label.Key == "C"
|
||||
}
|
||||
}
|
||||
|
||||
func generateData(impl otel.MeterImpl) {
|
||||
func generateData(impl metric.MeterImpl) {
|
||||
ctx := context.Background()
|
||||
meter := otel.WrapMeterImpl(impl, "testing")
|
||||
meter := metric.WrapMeterImpl(impl, "testing")
|
||||
|
||||
counter := otel.Must(meter).NewFloat64Counter("counter.sum")
|
||||
counter := metric.Must(meter).NewFloat64Counter("counter.sum")
|
||||
|
||||
_ = otel.Must(meter).NewInt64SumObserver("observer.sum",
|
||||
func(_ context.Context, result otel.Int64ObserverResult) {
|
||||
_ = metric.Must(meter).NewInt64SumObserver("observer.sum",
|
||||
func(_ context.Context, result metric.Int64ObserverResult) {
|
||||
result.Observe(10, kvs1...)
|
||||
result.Observe(10, kvs2...)
|
||||
},
|
||||
|
@ -21,11 +21,10 @@ import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
api "go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/global"
|
||||
internal "go.opentelemetry.io/otel/internal/metric"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator"
|
||||
@ -77,7 +76,7 @@ type (
|
||||
// mapkey uniquely describes a metric instrument in terms of
|
||||
// its InstrumentID and the encoded form of its labels.
|
||||
mapkey struct {
|
||||
descriptor *otel.Descriptor
|
||||
descriptor *metric.Descriptor
|
||||
ordered label.Distinct
|
||||
}
|
||||
|
||||
@ -125,7 +124,7 @@ type (
|
||||
|
||||
instrument struct {
|
||||
meter *Accumulator
|
||||
descriptor otel.Descriptor
|
||||
descriptor metric.Descriptor
|
||||
}
|
||||
|
||||
asyncInstrument struct {
|
||||
@ -143,15 +142,15 @@ type (
|
||||
)
|
||||
|
||||
var (
|
||||
_ api.MeterImpl = &Accumulator{}
|
||||
_ api.AsyncImpl = &asyncInstrument{}
|
||||
_ api.SyncImpl = &syncInstrument{}
|
||||
_ api.BoundSyncImpl = &record{}
|
||||
_ metric.MeterImpl = &Accumulator{}
|
||||
_ metric.AsyncImpl = &asyncInstrument{}
|
||||
_ metric.SyncImpl = &syncInstrument{}
|
||||
_ metric.BoundSyncImpl = &record{}
|
||||
|
||||
ErrUninitializedInstrument = fmt.Errorf("use of an uninitialized instrument")
|
||||
)
|
||||
|
||||
func (inst *instrument) Descriptor() api.Descriptor {
|
||||
func (inst *instrument) Descriptor() metric.Descriptor {
|
||||
return inst.descriptor
|
||||
}
|
||||
|
||||
@ -287,7 +286,7 @@ func (s *syncInstrument) acquireHandle(kvs []label.KeyValue, labelPtr *label.Set
|
||||
}
|
||||
}
|
||||
|
||||
func (s *syncInstrument) Bind(kvs []label.KeyValue) api.BoundSyncImpl {
|
||||
func (s *syncInstrument) Bind(kvs []label.KeyValue) metric.BoundSyncImpl {
|
||||
return s.acquireHandle(kvs, nil)
|
||||
}
|
||||
|
||||
@ -314,8 +313,8 @@ func NewAccumulator(processor export.Processor, resource *resource.Resource) *Ac
|
||||
}
|
||||
}
|
||||
|
||||
// NewSyncInstrument implements api.MetricImpl.
|
||||
func (m *Accumulator) NewSyncInstrument(descriptor api.Descriptor) (api.SyncImpl, error) {
|
||||
// NewSyncInstrument implements metric.MetricImpl.
|
||||
func (m *Accumulator) NewSyncInstrument(descriptor metric.Descriptor) (metric.SyncImpl, error) {
|
||||
return &syncInstrument{
|
||||
instrument: instrument{
|
||||
descriptor: descriptor,
|
||||
@ -324,8 +323,8 @@ func (m *Accumulator) NewSyncInstrument(descriptor api.Descriptor) (api.SyncImpl
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NewAsyncInstrument implements api.MetricImpl.
|
||||
func (m *Accumulator) NewAsyncInstrument(descriptor api.Descriptor, runner otel.AsyncRunner) (api.AsyncImpl, error) {
|
||||
// NewAsyncInstrument implements metric.MetricImpl.
|
||||
func (m *Accumulator) NewAsyncInstrument(descriptor metric.Descriptor, runner metric.AsyncRunner) (metric.AsyncImpl, error) {
|
||||
a := &asyncInstrument{
|
||||
instrument: instrument{
|
||||
descriptor: descriptor,
|
||||
@ -401,7 +400,7 @@ func (m *Accumulator) collectSyncInstruments() int {
|
||||
}
|
||||
|
||||
// CollectAsync implements internal.AsyncCollector.
|
||||
func (m *Accumulator) CollectAsync(kv []label.KeyValue, obs ...otel.Observation) {
|
||||
func (m *Accumulator) CollectAsync(kv []label.KeyValue, obs ...metric.Observation) {
|
||||
labels := label.NewSetWithSortable(kv, &m.asyncSortSlice)
|
||||
|
||||
for _, ob := range obs {
|
||||
@ -478,7 +477,7 @@ func (m *Accumulator) checkpointAsync(a *asyncInstrument) int {
|
||||
}
|
||||
|
||||
// RecordBatch enters a batch of metric events.
|
||||
func (m *Accumulator) RecordBatch(ctx context.Context, kvs []label.KeyValue, measurements ...api.Measurement) {
|
||||
func (m *Accumulator) RecordBatch(ctx context.Context, kvs []label.KeyValue, measurements ...metric.Measurement) {
|
||||
// Labels will be computed the first time acquireHandle is
|
||||
// called. Subsequent calls to acquireHandle will re-use the
|
||||
// previously computed value instead of recomputing the
|
||||
@ -501,7 +500,7 @@ func (m *Accumulator) RecordBatch(ctx context.Context, kvs []label.KeyValue, mea
|
||||
}
|
||||
}
|
||||
|
||||
// RecordOne implements api.SyncImpl.
|
||||
// RecordOne implements metric.SyncImpl.
|
||||
func (r *record) RecordOne(ctx context.Context, num number.Number) {
|
||||
if r.current == nil {
|
||||
// The instrument is disabled according to the AggregatorSelector.
|
||||
@ -520,7 +519,7 @@ func (r *record) RecordOne(ctx context.Context, num number.Number) {
|
||||
atomic.AddInt64(&r.updateCount, 1)
|
||||
}
|
||||
|
||||
// Unbind implements api.SyncImpl.
|
||||
// Unbind implements metric.SyncImpl.
|
||||
func (r *record) Unbind() {
|
||||
r.refMapped.unref()
|
||||
}
|
||||
@ -534,7 +533,7 @@ func (r *record) mapkey() mapkey {
|
||||
|
||||
// fromSync gets a sync implementation object, checking for
|
||||
// uninitialized instruments and instruments created by another SDK.
|
||||
func (m *Accumulator) fromSync(sync otel.SyncImpl) *syncInstrument {
|
||||
func (m *Accumulator) fromSync(sync metric.SyncImpl) *syncInstrument {
|
||||
if sync != nil {
|
||||
if inst, ok := sync.Implementation().(*syncInstrument); ok {
|
||||
return inst
|
||||
@ -546,7 +545,7 @@ func (m *Accumulator) fromSync(sync otel.SyncImpl) *syncInstrument {
|
||||
|
||||
// fromSync gets an async implementation object, checking for
|
||||
// uninitialized instruments and instruments created by another SDK.
|
||||
func (m *Accumulator) fromAsync(async otel.AsyncImpl) *asyncInstrument {
|
||||
func (m *Accumulator) fromAsync(async metric.AsyncImpl) *asyncInstrument {
|
||||
if async != nil {
|
||||
if inst, ok := async.Implementation().(*asyncInstrument); ok {
|
||||
return inst
|
||||
|
@ -15,7 +15,7 @@
|
||||
package simple // import "go.opentelemetry.io/otel/sdk/metric/selector/simple"
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/array"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/ddsketch"
|
||||
@ -94,11 +94,11 @@ func lastValueAggs(aggPtrs []*export.Aggregator) {
|
||||
}
|
||||
}
|
||||
|
||||
func (selectorInexpensive) AggregatorFor(descriptor *otel.Descriptor, aggPtrs ...*export.Aggregator) {
|
||||
func (selectorInexpensive) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) {
|
||||
switch descriptor.InstrumentKind() {
|
||||
case otel.ValueObserverInstrumentKind:
|
||||
case metric.ValueObserverInstrumentKind:
|
||||
lastValueAggs(aggPtrs)
|
||||
case otel.ValueRecorderInstrumentKind:
|
||||
case metric.ValueRecorderInstrumentKind:
|
||||
aggs := minmaxsumcount.New(len(aggPtrs), descriptor)
|
||||
for i := range aggPtrs {
|
||||
*aggPtrs[i] = &aggs[i]
|
||||
@ -108,11 +108,11 @@ func (selectorInexpensive) AggregatorFor(descriptor *otel.Descriptor, aggPtrs ..
|
||||
}
|
||||
}
|
||||
|
||||
func (s selectorSketch) AggregatorFor(descriptor *otel.Descriptor, aggPtrs ...*export.Aggregator) {
|
||||
func (s selectorSketch) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) {
|
||||
switch descriptor.InstrumentKind() {
|
||||
case otel.ValueObserverInstrumentKind:
|
||||
case metric.ValueObserverInstrumentKind:
|
||||
lastValueAggs(aggPtrs)
|
||||
case otel.ValueRecorderInstrumentKind:
|
||||
case metric.ValueRecorderInstrumentKind:
|
||||
aggs := ddsketch.New(len(aggPtrs), descriptor, s.config)
|
||||
for i := range aggPtrs {
|
||||
*aggPtrs[i] = &aggs[i]
|
||||
@ -122,11 +122,11 @@ func (s selectorSketch) AggregatorFor(descriptor *otel.Descriptor, aggPtrs ...*e
|
||||
}
|
||||
}
|
||||
|
||||
func (selectorExact) AggregatorFor(descriptor *otel.Descriptor, aggPtrs ...*export.Aggregator) {
|
||||
func (selectorExact) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) {
|
||||
switch descriptor.InstrumentKind() {
|
||||
case otel.ValueObserverInstrumentKind:
|
||||
case metric.ValueObserverInstrumentKind:
|
||||
lastValueAggs(aggPtrs)
|
||||
case otel.ValueRecorderInstrumentKind:
|
||||
case metric.ValueRecorderInstrumentKind:
|
||||
aggs := array.New(len(aggPtrs))
|
||||
for i := range aggPtrs {
|
||||
*aggPtrs[i] = &aggs[i]
|
||||
@ -136,11 +136,11 @@ func (selectorExact) AggregatorFor(descriptor *otel.Descriptor, aggPtrs ...*expo
|
||||
}
|
||||
}
|
||||
|
||||
func (s selectorHistogram) AggregatorFor(descriptor *otel.Descriptor, aggPtrs ...*export.Aggregator) {
|
||||
func (s selectorHistogram) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) {
|
||||
switch descriptor.InstrumentKind() {
|
||||
case otel.ValueObserverInstrumentKind:
|
||||
case metric.ValueObserverInstrumentKind:
|
||||
lastValueAggs(aggPtrs)
|
||||
case otel.ValueRecorderInstrumentKind:
|
||||
case metric.ValueRecorderInstrumentKind:
|
||||
aggs := histogram.New(len(aggPtrs), descriptor, s.boundaries)
|
||||
for i := range aggPtrs {
|
||||
*aggPtrs[i] = &aggs[i]
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/array"
|
||||
@ -32,15 +32,15 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
testCounterDesc = otel.NewDescriptor("counter", otel.CounterInstrumentKind, number.Int64Kind)
|
||||
testUpDownCounterDesc = otel.NewDescriptor("updowncounter", otel.UpDownCounterInstrumentKind, number.Int64Kind)
|
||||
testSumObserverDesc = otel.NewDescriptor("sumobserver", otel.SumObserverInstrumentKind, number.Int64Kind)
|
||||
testUpDownSumObserverDesc = otel.NewDescriptor("updownsumobserver", otel.UpDownSumObserverInstrumentKind, number.Int64Kind)
|
||||
testValueRecorderDesc = otel.NewDescriptor("valuerecorder", otel.ValueRecorderInstrumentKind, number.Int64Kind)
|
||||
testValueObserverDesc = otel.NewDescriptor("valueobserver", otel.ValueObserverInstrumentKind, number.Int64Kind)
|
||||
testCounterDesc = metric.NewDescriptor("counter", metric.CounterInstrumentKind, number.Int64Kind)
|
||||
testUpDownCounterDesc = metric.NewDescriptor("updowncounter", metric.UpDownCounterInstrumentKind, number.Int64Kind)
|
||||
testSumObserverDesc = metric.NewDescriptor("sumobserver", metric.SumObserverInstrumentKind, number.Int64Kind)
|
||||
testUpDownSumObserverDesc = metric.NewDescriptor("updownsumobserver", metric.UpDownSumObserverInstrumentKind, number.Int64Kind)
|
||||
testValueRecorderDesc = metric.NewDescriptor("valuerecorder", metric.ValueRecorderInstrumentKind, number.Int64Kind)
|
||||
testValueObserverDesc = metric.NewDescriptor("valueobserver", metric.ValueObserverInstrumentKind, number.Int64Kind)
|
||||
)
|
||||
|
||||
func oneAgg(sel export.AggregatorSelector, desc *otel.Descriptor) export.Aggregator {
|
||||
func oneAgg(sel export.AggregatorSelector, desc *metric.Descriptor) export.Aggregator {
|
||||
var agg export.Aggregator
|
||||
sel.AggregatorFor(desc, &agg)
|
||||
return agg
|
||||
|
@ -31,8 +31,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
@ -46,7 +46,7 @@ const (
|
||||
epsilon = 1e-10
|
||||
)
|
||||
|
||||
var Must = otel.Must
|
||||
var Must = metric.Must
|
||||
|
||||
type (
|
||||
testFixture struct {
|
||||
@ -69,11 +69,11 @@ type (
|
||||
|
||||
testKey struct {
|
||||
labels string
|
||||
descriptor *otel.Descriptor
|
||||
descriptor *metric.Descriptor
|
||||
}
|
||||
|
||||
testImpl struct {
|
||||
newInstrument func(meter otel.Meter, name string) SyncImpler
|
||||
newInstrument func(meter metric.Meter, name string) SyncImpler
|
||||
getUpdateValue func() number.Number
|
||||
operate func(interface{}, context.Context, number.Number, []label.KeyValue)
|
||||
newStore func() interface{}
|
||||
@ -88,7 +88,7 @@ type (
|
||||
}
|
||||
|
||||
SyncImpler interface {
|
||||
SyncImpl() otel.SyncImpl
|
||||
SyncImpl() metric.SyncImpl
|
||||
}
|
||||
|
||||
// lastValueState supports merging lastValue values, for the case
|
||||
@ -157,11 +157,11 @@ func (f *testFixture) someLabels() []label.KeyValue {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *testFixture) startWorker(impl *Accumulator, meter otel.Meter, wg *sync.WaitGroup, i int) {
|
||||
func (f *testFixture) startWorker(impl *Accumulator, meter metric.Meter, wg *sync.WaitGroup, i int) {
|
||||
ctx := context.Background()
|
||||
name := fmt.Sprint("test_", i)
|
||||
instrument := f.impl.newInstrument(meter, name)
|
||||
var descriptor *otel.Descriptor
|
||||
var descriptor *metric.Descriptor
|
||||
if ii, ok := instrument.SyncImpl().(*syncInstrument); ok {
|
||||
descriptor = &ii.descriptor
|
||||
}
|
||||
@ -265,13 +265,13 @@ func (f *testFixture) Process(accumulation export.Accumulation) error {
|
||||
|
||||
agg := accumulation.Aggregator()
|
||||
switch accumulation.Descriptor().InstrumentKind() {
|
||||
case otel.CounterInstrumentKind:
|
||||
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 otel.ValueRecorderInstrumentKind:
|
||||
case metric.ValueRecorderInstrumentKind:
|
||||
lv, ts, err := agg.(aggregation.LastValue).LastValue()
|
||||
if err != nil && err != aggregation.ErrNoData {
|
||||
f.T.Fatal("Last value error: ", err)
|
||||
@ -295,7 +295,7 @@ func stressTest(t *testing.T, impl testImpl) {
|
||||
cc := concurrency()
|
||||
|
||||
sdk := NewAccumulator(fixture, nil)
|
||||
meter := otel.WrapMeterImpl(sdk, "stress_test")
|
||||
meter := metric.WrapMeterImpl(sdk, "stress_test")
|
||||
fixture.wg.Add(cc + 1)
|
||||
|
||||
for i := 0; i < cc; i++ {
|
||||
@ -340,7 +340,7 @@ func float64sEqual(a, b number.Number) bool {
|
||||
|
||||
func intCounterTestImpl() testImpl {
|
||||
return testImpl{
|
||||
newInstrument: func(meter otel.Meter, name string) SyncImpler {
|
||||
newInstrument: func(meter metric.Meter, name string) SyncImpler {
|
||||
return Must(meter).NewInt64Counter(name + ".sum")
|
||||
},
|
||||
getUpdateValue: func() number.Number {
|
||||
@ -352,7 +352,7 @@ func intCounterTestImpl() testImpl {
|
||||
}
|
||||
},
|
||||
operate: func(inst interface{}, ctx context.Context, value number.Number, labels []label.KeyValue) {
|
||||
counter := inst.(otel.Int64Counter)
|
||||
counter := inst.(metric.Int64Counter)
|
||||
counter.Add(ctx, value.AsInt64(), labels...)
|
||||
},
|
||||
newStore: func() interface{} {
|
||||
@ -378,7 +378,7 @@ func TestStressInt64Counter(t *testing.T) {
|
||||
|
||||
func floatCounterTestImpl() testImpl {
|
||||
return testImpl{
|
||||
newInstrument: func(meter otel.Meter, name string) SyncImpler {
|
||||
newInstrument: func(meter metric.Meter, name string) SyncImpler {
|
||||
return Must(meter).NewFloat64Counter(name + ".sum")
|
||||
},
|
||||
getUpdateValue: func() number.Number {
|
||||
@ -390,7 +390,7 @@ func floatCounterTestImpl() testImpl {
|
||||
}
|
||||
},
|
||||
operate: func(inst interface{}, ctx context.Context, value number.Number, labels []label.KeyValue) {
|
||||
counter := inst.(otel.Float64Counter)
|
||||
counter := inst.(metric.Float64Counter)
|
||||
counter.Add(ctx, value.AsFloat64(), labels...)
|
||||
},
|
||||
newStore: func() interface{} {
|
||||
@ -418,7 +418,7 @@ func TestStressFloat64Counter(t *testing.T) {
|
||||
|
||||
func intLastValueTestImpl() testImpl {
|
||||
return testImpl{
|
||||
newInstrument: func(meter otel.Meter, name string) SyncImpler {
|
||||
newInstrument: func(meter metric.Meter, name string) SyncImpler {
|
||||
return Must(meter).NewInt64ValueRecorder(name + ".lastvalue")
|
||||
},
|
||||
getUpdateValue: func() number.Number {
|
||||
@ -426,7 +426,7 @@ func intLastValueTestImpl() testImpl {
|
||||
return number.NewInt64Number(rand.Int63() - r1)
|
||||
},
|
||||
operate: func(inst interface{}, ctx context.Context, value number.Number, labels []label.KeyValue) {
|
||||
valuerecorder := inst.(otel.Int64ValueRecorder)
|
||||
valuerecorder := inst.(metric.Int64ValueRecorder)
|
||||
valuerecorder.Record(ctx, value.AsInt64(), labels...)
|
||||
},
|
||||
newStore: func() interface{} {
|
||||
@ -460,14 +460,14 @@ func TestStressInt64LastValue(t *testing.T) {
|
||||
|
||||
func floatLastValueTestImpl() testImpl {
|
||||
return testImpl{
|
||||
newInstrument: func(meter otel.Meter, name string) SyncImpler {
|
||||
newInstrument: func(meter metric.Meter, name string) SyncImpler {
|
||||
return Must(meter).NewFloat64ValueRecorder(name + ".lastvalue")
|
||||
},
|
||||
getUpdateValue: func() number.Number {
|
||||
return number.NewFloat64Number((-0.5 + rand.Float64()) * 100000)
|
||||
},
|
||||
operate: func(inst interface{}, ctx context.Context, value number.Number, labels []label.KeyValue) {
|
||||
valuerecorder := inst.(otel.Float64ValueRecorder)
|
||||
valuerecorder := inst.(metric.Float64ValueRecorder)
|
||||
valuerecorder.Record(ctx, value.AsFloat64(), labels...)
|
||||
},
|
||||
newStore: func() interface{} {
|
||||
|
Loading…
x
Reference in New Issue
Block a user