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