1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-07-05 00:28:58 +02:00

Move InstrumentKind into the new metric/sdkapi package (#2091)

* Move InstrumentKind into the new metric/sdkapi package

* remove the alias

* remove the alias (everywhere)

* Changelog

* Add a test

* merge updates

* fix changelog

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
Joshua MacDonald
2021-08-11 16:02:28 -07:00
committed by GitHub
parent 1cb5cdca6b
commit df384a9a33
30 changed files with 340 additions and 268 deletions

View File

@ -14,6 +14,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Changed ### Changed
- Metric SDK/API implementation type `InstrumentKind` moves into `sdkapi` sub-package. (#2091)
### Deprecated ### Deprecated
- The `go.opentelemetry.io/otel/bridge/opencensus/utils` package is deprecated. - The `go.opentelemetry.io/otel/bridge/opencensus/utils` package is deprecated.
@ -51,7 +53,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- The `SpanModels` function is now exported from the `go.opentelemetry.io/otel/exporters/zipkin` package to convert OpenTelemetry spans into Zipkin model spans. (#2027) - The `SpanModels` function is now exported from the `go.opentelemetry.io/otel/exporters/zipkin` package to convert OpenTelemetry spans into Zipkin model spans. (#2027)
- Rename the `"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc".RetrySettings` to `RetryConfig`. (#2095) - Rename the `"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc".RetrySettings` to `RetryConfig`. (#2095)
- Rename the `"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp".RetrySettings` to `RetryConfig`. (#2095)
### Deprecated ### Deprecated

View File

@ -28,6 +28,7 @@ import (
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
"go.opentelemetry.io/otel/metric/unit" "go.opentelemetry.io/otel/metric/unit"
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"
@ -133,21 +134,21 @@ func convertResource(res *ocresource.Resource) *resource.Resource {
func convertDescriptor(ocDescriptor metricdata.Descriptor) (metric.Descriptor, error) { func convertDescriptor(ocDescriptor metricdata.Descriptor) (metric.Descriptor, error) {
var ( var (
nkind number.Kind nkind number.Kind
ikind metric.InstrumentKind ikind sdkapi.InstrumentKind
) )
switch ocDescriptor.Type { switch ocDescriptor.Type {
case metricdata.TypeGaugeInt64: case metricdata.TypeGaugeInt64:
nkind = number.Int64Kind nkind = number.Int64Kind
ikind = metric.ValueObserverInstrumentKind ikind = sdkapi.ValueObserverInstrumentKind
case metricdata.TypeGaugeFloat64: case metricdata.TypeGaugeFloat64:
nkind = number.Float64Kind nkind = number.Float64Kind
ikind = metric.ValueObserverInstrumentKind ikind = sdkapi.ValueObserverInstrumentKind
case metricdata.TypeCumulativeInt64: case metricdata.TypeCumulativeInt64:
nkind = number.Int64Kind nkind = number.Int64Kind
ikind = metric.SumObserverInstrumentKind ikind = sdkapi.SumObserverInstrumentKind
case metricdata.TypeCumulativeFloat64: case metricdata.TypeCumulativeFloat64:
nkind = number.Float64Kind nkind = number.Float64Kind
ikind = metric.SumObserverInstrumentKind ikind = sdkapi.SumObserverInstrumentKind
default: default:
// Includes TypeGaugeDistribution, TypeCumulativeDistribution, TypeSummary // Includes TypeGaugeDistribution, TypeCumulativeDistribution, TypeSummary
return metric.Descriptor{}, fmt.Errorf("%w; descriptor type: %v", errConversion, ocDescriptor.Type) return metric.Descriptor{}, fmt.Errorf("%w; descriptor type: %v", errConversion, ocDescriptor.Type)

View File

@ -29,6 +29,7 @@ import (
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
"go.opentelemetry.io/otel/metric/unit" "go.opentelemetry.io/otel/metric/unit"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
exportmetric "go.opentelemetry.io/otel/sdk/export/metric" exportmetric "go.opentelemetry.io/otel/sdk/export/metric"
@ -70,7 +71,7 @@ func TestExportMetrics(t *testing.T) {
now := time.Now() now := time.Now()
basicDesc := metric.NewDescriptor( basicDesc := metric.NewDescriptor(
"", "",
metric.ValueObserverInstrumentKind, sdkapi.ValueObserverInstrumentKind,
number.Int64Kind, number.Int64Kind,
metric.WithInstrumentationName("OpenCensus Bridge"), metric.WithInstrumentationName("OpenCensus Bridge"),
) )
@ -384,7 +385,7 @@ func TestConvertDescriptor(t *testing.T) {
desc: "empty descriptor", desc: "empty descriptor",
expected: metric.NewDescriptor( expected: metric.NewDescriptor(
"", "",
metric.ValueObserverInstrumentKind, sdkapi.ValueObserverInstrumentKind,
number.Int64Kind, number.Int64Kind,
metric.WithInstrumentationName("OpenCensus Bridge"), metric.WithInstrumentationName("OpenCensus Bridge"),
), ),
@ -399,7 +400,7 @@ func TestConvertDescriptor(t *testing.T) {
}, },
expected: metric.NewDescriptor( expected: metric.NewDescriptor(
"foo", "foo",
metric.ValueObserverInstrumentKind, sdkapi.ValueObserverInstrumentKind,
number.Int64Kind, number.Int64Kind,
metric.WithInstrumentationName("OpenCensus Bridge"), metric.WithInstrumentationName("OpenCensus Bridge"),
metric.WithDescription("bar"), metric.WithDescription("bar"),
@ -416,7 +417,7 @@ func TestConvertDescriptor(t *testing.T) {
}, },
expected: metric.NewDescriptor( expected: metric.NewDescriptor(
"foo", "foo",
metric.ValueObserverInstrumentKind, sdkapi.ValueObserverInstrumentKind,
number.Float64Kind, number.Float64Kind,
metric.WithInstrumentationName("OpenCensus Bridge"), metric.WithInstrumentationName("OpenCensus Bridge"),
metric.WithDescription("bar"), metric.WithDescription("bar"),
@ -433,7 +434,7 @@ func TestConvertDescriptor(t *testing.T) {
}, },
expected: metric.NewDescriptor( expected: metric.NewDescriptor(
"foo", "foo",
metric.SumObserverInstrumentKind, sdkapi.SumObserverInstrumentKind,
number.Int64Kind, number.Int64Kind,
metric.WithInstrumentationName("OpenCensus Bridge"), metric.WithInstrumentationName("OpenCensus Bridge"),
metric.WithDescription("bar"), metric.WithDescription("bar"),
@ -450,7 +451,7 @@ func TestConvertDescriptor(t *testing.T) {
}, },
expected: metric.NewDescriptor( expected: metric.NewDescriptor(
"foo", "foo",
metric.SumObserverInstrumentKind, sdkapi.SumObserverInstrumentKind,
number.Float64Kind, number.Float64Kind,
metric.WithInstrumentationName("OpenCensus Bridge"), metric.WithInstrumentationName("OpenCensus Bridge"),
metric.WithDescription("bar"), metric.WithDescription("bar"),

View File

@ -31,6 +31,7 @@ import (
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
metricsdk "go.opentelemetry.io/otel/sdk/export/metric" metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/resource"
commonpb "go.opentelemetry.io/proto/otlp/common/v1" commonpb "go.opentelemetry.io/proto/otlp/common/v1"
@ -98,7 +99,7 @@ func (m *checkpointSet) ForEach(_ metricsdk.ExportKindSelector, fn func(metricsd
type record struct { type record struct {
name string name string
iKind metric.InstrumentKind iKind sdkapi.InstrumentKind
nKind number.Kind nKind number.Kind
resource *resource.Resource resource *resource.Resource
opts []metric.InstrumentOption opts []metric.InstrumentOption
@ -184,7 +185,7 @@ func TestNoGroupingExport(t *testing.T) {
[]record{ []record{
{ {
"int64-count", "int64-count",
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
number.Int64Kind, number.Int64Kind,
nil, nil,
nil, nil,
@ -192,7 +193,7 @@ func TestNoGroupingExport(t *testing.T) {
}, },
{ {
"int64-count", "int64-count",
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
number.Int64Kind, number.Int64Kind,
nil, nil,
nil, nil,
@ -239,7 +240,7 @@ func TestNoGroupingExport(t *testing.T) {
func TestValuerecorderMetricGroupingExport(t *testing.T) { func TestValuerecorderMetricGroupingExport(t *testing.T) {
r := record{ r := record{
"valuerecorder", "valuerecorder",
metric.ValueRecorderInstrumentKind, sdkapi.ValueRecorderInstrumentKind,
number.Int64Kind, number.Int64Kind,
nil, nil,
nil, nil,
@ -290,7 +291,7 @@ func TestValuerecorderMetricGroupingExport(t *testing.T) {
func TestCountInt64MetricGroupingExport(t *testing.T) { func TestCountInt64MetricGroupingExport(t *testing.T) {
r := record{ r := record{
"int64-count", "int64-count",
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
number.Int64Kind, number.Int64Kind,
nil, nil,
nil, nil,
@ -340,7 +341,7 @@ func TestCountInt64MetricGroupingExport(t *testing.T) {
func TestCountFloat64MetricGroupingExport(t *testing.T) { func TestCountFloat64MetricGroupingExport(t *testing.T) {
r := record{ r := record{
"float64-count", "float64-count",
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
number.Float64Kind, number.Float64Kind,
nil, nil,
nil, nil,
@ -394,7 +395,7 @@ func TestResourceMetricGroupingExport(t *testing.T) {
[]record{ []record{
{ {
"int64-count", "int64-count",
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
number.Int64Kind, number.Int64Kind,
testInstA, testInstA,
nil, nil,
@ -402,7 +403,7 @@ func TestResourceMetricGroupingExport(t *testing.T) {
}, },
{ {
"int64-count", "int64-count",
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
number.Int64Kind, number.Int64Kind,
testInstA, testInstA,
nil, nil,
@ -410,7 +411,7 @@ func TestResourceMetricGroupingExport(t *testing.T) {
}, },
{ {
"int64-count", "int64-count",
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
number.Int64Kind, number.Int64Kind,
testInstA, testInstA,
nil, nil,
@ -418,7 +419,7 @@ func TestResourceMetricGroupingExport(t *testing.T) {
}, },
{ {
"int64-count", "int64-count",
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
number.Int64Kind, number.Int64Kind,
testInstB, testInstB,
nil, nil,
@ -512,7 +513,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
[]record{ []record{
{ {
"int64-count", "int64-count",
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
number.Int64Kind, number.Int64Kind,
testInstA, testInstA,
countingLib1, countingLib1,
@ -520,7 +521,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
}, },
{ {
"int64-count", "int64-count",
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
number.Int64Kind, number.Int64Kind,
testInstA, testInstA,
countingLib2, countingLib2,
@ -528,7 +529,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
}, },
{ {
"int64-count", "int64-count",
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
number.Int64Kind, number.Int64Kind,
testInstA, testInstA,
countingLib1, countingLib1,
@ -536,7 +537,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
}, },
{ {
"int64-count", "int64-count",
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
number.Int64Kind, number.Int64Kind,
testInstA, testInstA,
countingLib1, countingLib1,
@ -544,7 +545,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
}, },
{ {
"int64-count", "int64-count",
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
number.Int64Kind, number.Int64Kind,
testInstA, testInstA,
summingLib, summingLib,
@ -552,7 +553,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
}, },
{ {
"int64-count", "int64-count",
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
number.Int64Kind, number.Int64Kind,
testInstB, testInstB,
countingLib1, countingLib1,
@ -688,16 +689,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 metric.InstrumentKind instrumentKind sdkapi.InstrumentKind
aggTemporality metricpb.AggregationTemporality aggTemporality metricpb.AggregationTemporality
monotonic bool monotonic bool
} }
for _, k := range []testcase{ for _, k := range []testcase{
{"counter", metric.CounterInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, true}, {"counter", sdkapi.CounterInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, true},
{"updowncounter", metric.UpDownCounterInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, false}, {"updowncounter", sdkapi.UpDownCounterInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, false},
{"sumobserver", metric.SumObserverInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE, true}, {"sumobserver", sdkapi.SumObserverInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE, true},
{"updownsumobserver", metric.UpDownSumObserverInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE, false}, {"updownsumobserver", sdkapi.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(

View File

@ -27,6 +27,7 @@ import (
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
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"
arrAgg "go.opentelemetry.io/otel/sdk/metric/aggregator/exact" arrAgg "go.opentelemetry.io/otel/sdk/metric/aggregator/exact"
@ -122,7 +123,7 @@ func TestMinMaxSumCountValue(t *testing.T) {
} }
func TestMinMaxSumCountDatapoints(t *testing.T) { func TestMinMaxSumCountDatapoints(t *testing.T) {
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("", sdkapi.ValueRecorderInstrumentKind, number.Int64Kind)
labels := attribute.NewSet(attribute.String("one", "1")) labels := attribute.NewSet(attribute.String("one", "1"))
mmscs := minmaxsumcount.New(2, &metric.Descriptor{}) mmscs := minmaxsumcount.New(2, &metric.Descriptor{})
mmsc, ckpt := &mmscs[0], &mmscs[1] mmsc, ckpt := &mmscs[0], &mmscs[1]
@ -178,7 +179,7 @@ func TestMinMaxSumCountPropagatesErrors(t *testing.T) {
} }
func TestSumIntDataPoints(t *testing.T) { func TestSumIntDataPoints(t *testing.T) {
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("", sdkapi.ValueRecorderInstrumentKind, number.Int64Kind)
labels := attribute.NewSet(attribute.String("one", "1")) labels := attribute.NewSet(attribute.String("one", "1"))
sums := sumAgg.New(2) sums := sumAgg.New(2)
s, ckpt := &sums[0], &sums[1] s, ckpt := &sums[0], &sums[1]
@ -218,7 +219,7 @@ func TestSumIntDataPoints(t *testing.T) {
} }
func TestSumFloatDataPoints(t *testing.T) { func TestSumFloatDataPoints(t *testing.T) {
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Float64Kind) desc := metric.NewDescriptor("", sdkapi.ValueRecorderInstrumentKind, number.Float64Kind)
labels := attribute.NewSet(attribute.String("one", "1")) labels := attribute.NewSet(attribute.String("one", "1"))
sums := sumAgg.New(2) sums := sumAgg.New(2)
s, ckpt := &sums[0], &sums[1] s, ckpt := &sums[0], &sums[1]
@ -256,7 +257,7 @@ func TestSumFloatDataPoints(t *testing.T) {
} }
func TestLastValueIntDataPoints(t *testing.T) { func TestLastValueIntDataPoints(t *testing.T) {
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("", sdkapi.ValueRecorderInstrumentKind, number.Int64Kind)
labels := attribute.NewSet(attribute.String("one", "1")) labels := attribute.NewSet(attribute.String("one", "1"))
lvs := lvAgg.New(2) lvs := lvAgg.New(2)
lv, ckpt := &lvs[0], &lvs[1] lv, ckpt := &lvs[0], &lvs[1]
@ -291,7 +292,7 @@ func TestLastValueIntDataPoints(t *testing.T) {
} }
func TestExactIntDataPoints(t *testing.T) { func TestExactIntDataPoints(t *testing.T) {
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("", sdkapi.ValueRecorderInstrumentKind, number.Int64Kind)
labels := attribute.NewSet(attribute.String("one", "1")) labels := attribute.NewSet(attribute.String("one", "1"))
arrs := arrAgg.New(2) arrs := arrAgg.New(2)
e, ckpt := &arrs[0], &arrs[1] e, ckpt := &arrs[0], &arrs[1]
@ -326,7 +327,7 @@ func TestExactIntDataPoints(t *testing.T) {
} }
func TestExactFloatDataPoints(t *testing.T) { func TestExactFloatDataPoints(t *testing.T) {
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Float64Kind) desc := metric.NewDescriptor("", sdkapi.ValueRecorderInstrumentKind, number.Float64Kind)
labels := attribute.NewSet(attribute.String("one", "1")) labels := attribute.NewSet(attribute.String("one", "1"))
arrs := arrAgg.New(2) arrs := arrAgg.New(2)
e, ckpt := &arrs[0], &arrs[1] e, ckpt := &arrs[0], &arrs[1]
@ -360,7 +361,7 @@ func TestExactFloatDataPoints(t *testing.T) {
} }
func TestSumErrUnknownValueType(t *testing.T) { func TestSumErrUnknownValueType(t *testing.T) {
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Kind(-1)) desc := metric.NewDescriptor("", sdkapi.ValueRecorderInstrumentKind, number.Kind(-1))
labels := attribute.NewSet() labels := attribute.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)
@ -445,7 +446,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 := metric.NewDescriptor("things", metric.CounterInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("things", sdkapi.CounterInstrumentKind, number.Int64Kind)
labels := attribute.NewSet() labels := attribute.NewSet()
res := resource.Empty() res := resource.Empty()
test := &testAgg{ test := &testAgg{
@ -482,7 +483,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 := metric.NewDescriptor("things", metric.CounterInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("things", sdkapi.CounterInstrumentKind, number.Int64Kind)
labels := attribute.NewSet() labels := attribute.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))

View File

@ -22,6 +22,7 @@ import (
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
exportmetric "go.opentelemetry.io/otel/sdk/export/metric" exportmetric "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregator/sum" "go.opentelemetry.io/otel/sdk/metric/aggregator/sum"
"go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/resource"
@ -59,7 +60,7 @@ var _ exportmetric.CheckpointSet = OneRecordCheckpointSet{}
func (OneRecordCheckpointSet) ForEach(kindSelector exportmetric.ExportKindSelector, recordFunc func(exportmetric.Record) error) error { func (OneRecordCheckpointSet) ForEach(kindSelector exportmetric.ExportKindSelector, recordFunc func(exportmetric.Record) error) error {
desc := metric.NewDescriptor( desc := metric.NewDescriptor(
"foo", "foo",
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
number.Int64Kind, number.Int64Kind,
) )
res := resource.NewSchemaless(attribute.String("a", "b")) res := resource.NewSchemaless(attribute.String("a", "b"))

View File

@ -29,6 +29,7 @@ import (
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
exportmetric "go.opentelemetry.io/otel/sdk/export/metric" exportmetric "go.opentelemetry.io/otel/sdk/export/metric"
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic" controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
processor "go.opentelemetry.io/otel/sdk/metric/processor/basic" processor "go.opentelemetry.io/otel/sdk/metric/processor/basic"
@ -47,22 +48,22 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlpmetric.Exporter
labels := []attribute.KeyValue{attribute.Bool("test", true)} labels := []attribute.KeyValue{attribute.Bool("test", true)}
type data struct { type data struct {
iKind metric.InstrumentKind iKind sdkapi.InstrumentKind
nKind number.Kind nKind number.Kind
val int64 val int64
} }
instruments := map[string]data{ instruments := map[string]data{
"test-int64-counter": {metric.CounterInstrumentKind, number.Int64Kind, 1}, "test-int64-counter": {sdkapi.CounterInstrumentKind, number.Int64Kind, 1},
"test-float64-counter": {metric.CounterInstrumentKind, number.Float64Kind, 1}, "test-float64-counter": {sdkapi.CounterInstrumentKind, number.Float64Kind, 1},
"test-int64-valuerecorder": {metric.ValueRecorderInstrumentKind, number.Int64Kind, 2}, "test-int64-valuerecorder": {sdkapi.ValueRecorderInstrumentKind, number.Int64Kind, 2},
"test-float64-valuerecorder": {metric.ValueRecorderInstrumentKind, number.Float64Kind, 2}, "test-float64-valuerecorder": {sdkapi.ValueRecorderInstrumentKind, number.Float64Kind, 2},
"test-int64-valueobserver": {metric.ValueObserverInstrumentKind, number.Int64Kind, 3}, "test-int64-valueobserver": {sdkapi.ValueObserverInstrumentKind, number.Int64Kind, 3},
"test-float64-valueobserver": {metric.ValueObserverInstrumentKind, number.Float64Kind, 3}, "test-float64-valueobserver": {sdkapi.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 metric.CounterInstrumentKind: case sdkapi.CounterInstrumentKind:
switch data.nKind { switch data.nKind {
case number.Int64Kind: case number.Int64Kind:
metric.Must(meter).NewInt64Counter(name).Add(ctx, data.val, labels...) metric.Must(meter).NewInt64Counter(name).Add(ctx, data.val, labels...)
@ -71,7 +72,7 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlpmetric.Exporter
default: default:
assert.Failf(t, "unsupported number testing kind", data.nKind.String()) assert.Failf(t, "unsupported number testing kind", data.nKind.String())
} }
case metric.ValueRecorderInstrumentKind: case sdkapi.ValueRecorderInstrumentKind:
switch data.nKind { switch data.nKind {
case number.Int64Kind: case number.Int64Kind:
metric.Must(meter).NewInt64ValueRecorder(name).Record(ctx, data.val, labels...) metric.Must(meter).NewInt64ValueRecorder(name).Record(ctx, data.val, labels...)
@ -80,7 +81,7 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlpmetric.Exporter
default: default:
assert.Failf(t, "unsupported number testing kind", data.nKind.String()) assert.Failf(t, "unsupported number testing kind", data.nKind.String())
} }
case metric.ValueObserverInstrumentKind: case sdkapi.ValueObserverInstrumentKind:
switch data.nKind { switch data.nKind {
case number.Int64Kind: case number.Int64Kind:
metric.Must(meter).NewInt64ValueObserver(name, metric.Must(meter).NewInt64ValueObserver(name,
@ -130,13 +131,13 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlpmetric.Exporter
seen[m.Name] = struct{}{} seen[m.Name] = struct{}{}
switch data.iKind { switch data.iKind {
case metric.CounterInstrumentKind, metric.ValueObserverInstrumentKind: case sdkapi.CounterInstrumentKind, sdkapi.ValueObserverInstrumentKind:
var dp []*metricpb.NumberDataPoint var dp []*metricpb.NumberDataPoint
switch data.iKind { switch data.iKind {
case metric.CounterInstrumentKind: case sdkapi.CounterInstrumentKind:
require.NotNil(t, m.GetSum()) require.NotNil(t, m.GetSum())
dp = m.GetSum().GetDataPoints() dp = m.GetSum().GetDataPoints()
case metric.ValueObserverInstrumentKind: case sdkapi.ValueObserverInstrumentKind:
require.NotNil(t, m.GetGauge()) require.NotNil(t, m.GetGauge())
dp = m.GetGauge().GetDataPoints() dp = m.GetGauge().GetDataPoints()
} }
@ -150,7 +151,7 @@ func RunEndToEndTest(ctx context.Context, t *testing.T, exp *otlpmetric.Exporter
assert.Equal(t, v, dp[0].Value, "invalid value for %q", m.Name) assert.Equal(t, v, dp[0].Value, "invalid value for %q", m.Name)
} }
} }
case metric.ValueRecorderInstrumentKind: case sdkapi.ValueRecorderInstrumentKind:
require.NotNil(t, m.GetSummary()) require.NotNil(t, m.GetSummary())
if dp := m.GetSummary().DataPoints; assert.Len(t, dp, 1) { if dp := m.GetSummary().DataPoints; assert.Len(t, dp, 1) {
count := dp[0].Count count := dp[0].Count

View File

@ -19,6 +19,7 @@ import (
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
"go.opentelemetry.io/otel/metric/unit" "go.opentelemetry.io/otel/metric/unit"
) )
@ -64,7 +65,7 @@ func (m Meter) NewBatchObserver(callback BatchObserverFunc) BatchObserver {
// duplicate registration). // duplicate registration).
func (m Meter) NewInt64Counter(name string, options ...InstrumentOption) (Int64Counter, error) { func (m Meter) NewInt64Counter(name string, options ...InstrumentOption) (Int64Counter, error) {
return wrapInt64CounterInstrument( return wrapInt64CounterInstrument(
m.newSync(name, CounterInstrumentKind, number.Int64Kind, options)) m.newSync(name, sdkapi.CounterInstrumentKind, number.Int64Kind, options))
} }
// NewFloat64Counter creates a new floating point Counter with the // NewFloat64Counter creates a new floating point Counter with the
@ -73,7 +74,7 @@ func (m Meter) NewInt64Counter(name string, options ...InstrumentOption) (Int64C
// duplicate registration). // duplicate registration).
func (m Meter) NewFloat64Counter(name string, options ...InstrumentOption) (Float64Counter, error) { func (m Meter) NewFloat64Counter(name string, options ...InstrumentOption) (Float64Counter, error) {
return wrapFloat64CounterInstrument( return wrapFloat64CounterInstrument(
m.newSync(name, CounterInstrumentKind, number.Float64Kind, options)) m.newSync(name, sdkapi.CounterInstrumentKind, number.Float64Kind, options))
} }
// NewInt64UpDownCounter creates a new integer UpDownCounter instrument with the // NewInt64UpDownCounter creates a new integer UpDownCounter instrument with the
@ -82,7 +83,7 @@ func (m Meter) NewFloat64Counter(name string, options ...InstrumentOption) (Floa
// duplicate registration). // duplicate registration).
func (m Meter) NewInt64UpDownCounter(name string, options ...InstrumentOption) (Int64UpDownCounter, error) { func (m Meter) NewInt64UpDownCounter(name string, options ...InstrumentOption) (Int64UpDownCounter, error) {
return wrapInt64UpDownCounterInstrument( return wrapInt64UpDownCounterInstrument(
m.newSync(name, UpDownCounterInstrumentKind, number.Int64Kind, options)) m.newSync(name, sdkapi.UpDownCounterInstrumentKind, number.Int64Kind, options))
} }
// NewFloat64UpDownCounter creates a new floating point UpDownCounter with the // NewFloat64UpDownCounter creates a new floating point UpDownCounter with the
@ -91,7 +92,7 @@ func (m Meter) NewInt64UpDownCounter(name string, options ...InstrumentOption) (
// duplicate registration). // duplicate registration).
func (m Meter) NewFloat64UpDownCounter(name string, options ...InstrumentOption) (Float64UpDownCounter, error) { func (m Meter) NewFloat64UpDownCounter(name string, options ...InstrumentOption) (Float64UpDownCounter, error) {
return wrapFloat64UpDownCounterInstrument( return wrapFloat64UpDownCounterInstrument(
m.newSync(name, UpDownCounterInstrumentKind, number.Float64Kind, options)) m.newSync(name, sdkapi.UpDownCounterInstrumentKind, number.Float64Kind, options))
} }
// NewInt64ValueRecorder creates a new integer ValueRecorder instrument with the // NewInt64ValueRecorder creates a new integer ValueRecorder instrument with the
@ -100,7 +101,7 @@ func (m Meter) NewFloat64UpDownCounter(name string, options ...InstrumentOption)
// duplicate registration). // duplicate registration).
func (m Meter) NewInt64ValueRecorder(name string, opts ...InstrumentOption) (Int64ValueRecorder, error) { func (m Meter) NewInt64ValueRecorder(name string, opts ...InstrumentOption) (Int64ValueRecorder, error) {
return wrapInt64ValueRecorderInstrument( return wrapInt64ValueRecorderInstrument(
m.newSync(name, ValueRecorderInstrumentKind, number.Int64Kind, opts)) m.newSync(name, sdkapi.ValueRecorderInstrumentKind, number.Int64Kind, opts))
} }
// NewFloat64ValueRecorder creates a new floating point ValueRecorder with the // NewFloat64ValueRecorder creates a new floating point ValueRecorder with the
@ -109,7 +110,7 @@ func (m Meter) NewInt64ValueRecorder(name string, opts ...InstrumentOption) (Int
// duplicate registration). // duplicate registration).
func (m Meter) NewFloat64ValueRecorder(name string, opts ...InstrumentOption) (Float64ValueRecorder, error) { func (m Meter) NewFloat64ValueRecorder(name string, opts ...InstrumentOption) (Float64ValueRecorder, error) {
return wrapFloat64ValueRecorderInstrument( return wrapFloat64ValueRecorderInstrument(
m.newSync(name, ValueRecorderInstrumentKind, number.Float64Kind, opts)) m.newSync(name, sdkapi.ValueRecorderInstrumentKind, number.Float64Kind, opts))
} }
// NewInt64ValueObserver creates a new integer ValueObserver instrument // NewInt64ValueObserver creates a new integer ValueObserver instrument
@ -121,7 +122,7 @@ func (m Meter) NewInt64ValueObserver(name string, callback Int64ObserverFunc, op
return wrapInt64ValueObserverInstrument(NoopAsync{}, nil) return wrapInt64ValueObserverInstrument(NoopAsync{}, nil)
} }
return wrapInt64ValueObserverInstrument( return wrapInt64ValueObserverInstrument(
m.newAsync(name, ValueObserverInstrumentKind, number.Int64Kind, opts, m.newAsync(name, sdkapi.ValueObserverInstrumentKind, number.Int64Kind, opts,
newInt64AsyncRunner(callback))) newInt64AsyncRunner(callback)))
} }
@ -134,7 +135,7 @@ func (m Meter) NewFloat64ValueObserver(name string, callback Float64ObserverFunc
return wrapFloat64ValueObserverInstrument(NoopAsync{}, nil) return wrapFloat64ValueObserverInstrument(NoopAsync{}, nil)
} }
return wrapFloat64ValueObserverInstrument( return wrapFloat64ValueObserverInstrument(
m.newAsync(name, ValueObserverInstrumentKind, number.Float64Kind, opts, m.newAsync(name, sdkapi.ValueObserverInstrumentKind, number.Float64Kind, opts,
newFloat64AsyncRunner(callback))) newFloat64AsyncRunner(callback)))
} }
@ -147,7 +148,7 @@ func (m Meter) NewInt64SumObserver(name string, callback Int64ObserverFunc, opts
return wrapInt64SumObserverInstrument(NoopAsync{}, nil) return wrapInt64SumObserverInstrument(NoopAsync{}, nil)
} }
return wrapInt64SumObserverInstrument( return wrapInt64SumObserverInstrument(
m.newAsync(name, SumObserverInstrumentKind, number.Int64Kind, opts, m.newAsync(name, sdkapi.SumObserverInstrumentKind, number.Int64Kind, opts,
newInt64AsyncRunner(callback))) newInt64AsyncRunner(callback)))
} }
@ -160,7 +161,7 @@ func (m Meter) NewFloat64SumObserver(name string, callback Float64ObserverFunc,
return wrapFloat64SumObserverInstrument(NoopAsync{}, nil) return wrapFloat64SumObserverInstrument(NoopAsync{}, nil)
} }
return wrapFloat64SumObserverInstrument( return wrapFloat64SumObserverInstrument(
m.newAsync(name, SumObserverInstrumentKind, number.Float64Kind, opts, m.newAsync(name, sdkapi.SumObserverInstrumentKind, number.Float64Kind, opts,
newFloat64AsyncRunner(callback))) newFloat64AsyncRunner(callback)))
} }
@ -173,7 +174,7 @@ func (m Meter) NewInt64UpDownSumObserver(name string, callback Int64ObserverFunc
return wrapInt64UpDownSumObserverInstrument(NoopAsync{}, nil) return wrapInt64UpDownSumObserverInstrument(NoopAsync{}, nil)
} }
return wrapInt64UpDownSumObserverInstrument( return wrapInt64UpDownSumObserverInstrument(
m.newAsync(name, UpDownSumObserverInstrumentKind, number.Int64Kind, opts, m.newAsync(name, sdkapi.UpDownSumObserverInstrumentKind, number.Int64Kind, opts,
newInt64AsyncRunner(callback))) newInt64AsyncRunner(callback)))
} }
@ -186,7 +187,7 @@ func (m Meter) NewFloat64UpDownSumObserver(name string, callback Float64Observer
return wrapFloat64UpDownSumObserverInstrument(NoopAsync{}, nil) return wrapFloat64UpDownSumObserverInstrument(NoopAsync{}, nil)
} }
return wrapFloat64UpDownSumObserverInstrument( return wrapFloat64UpDownSumObserverInstrument(
m.newAsync(name, UpDownSumObserverInstrumentKind, number.Float64Kind, opts, m.newAsync(name, sdkapi.UpDownSumObserverInstrumentKind, number.Float64Kind, opts,
newFloat64AsyncRunner(callback))) newFloat64AsyncRunner(callback)))
} }
@ -199,7 +200,7 @@ func (b BatchObserver) NewInt64ValueObserver(name string, opts ...InstrumentOpti
return wrapInt64ValueObserverInstrument(NoopAsync{}, nil) return wrapInt64ValueObserverInstrument(NoopAsync{}, nil)
} }
return wrapInt64ValueObserverInstrument( return wrapInt64ValueObserverInstrument(
b.meter.newAsync(name, ValueObserverInstrumentKind, number.Int64Kind, opts, b.runner)) b.meter.newAsync(name, sdkapi.ValueObserverInstrumentKind, number.Int64Kind, opts, b.runner))
} }
// NewFloat64ValueObserver creates a new floating point ValueObserver with // NewFloat64ValueObserver creates a new floating point ValueObserver with
@ -211,7 +212,7 @@ func (b BatchObserver) NewFloat64ValueObserver(name string, opts ...InstrumentOp
return wrapFloat64ValueObserverInstrument(NoopAsync{}, nil) return wrapFloat64ValueObserverInstrument(NoopAsync{}, nil)
} }
return wrapFloat64ValueObserverInstrument( return wrapFloat64ValueObserverInstrument(
b.meter.newAsync(name, ValueObserverInstrumentKind, number.Float64Kind, opts, b.meter.newAsync(name, sdkapi.ValueObserverInstrumentKind, number.Float64Kind, opts,
b.runner)) b.runner))
} }
@ -224,7 +225,7 @@ func (b BatchObserver) NewInt64SumObserver(name string, opts ...InstrumentOption
return wrapInt64SumObserverInstrument(NoopAsync{}, nil) return wrapInt64SumObserverInstrument(NoopAsync{}, nil)
} }
return wrapInt64SumObserverInstrument( return wrapInt64SumObserverInstrument(
b.meter.newAsync(name, SumObserverInstrumentKind, number.Int64Kind, opts, b.runner)) b.meter.newAsync(name, sdkapi.SumObserverInstrumentKind, number.Int64Kind, opts, b.runner))
} }
// NewFloat64SumObserver creates a new floating point SumObserver with // NewFloat64SumObserver creates a new floating point SumObserver with
@ -236,7 +237,7 @@ func (b BatchObserver) NewFloat64SumObserver(name string, opts ...InstrumentOpti
return wrapFloat64SumObserverInstrument(NoopAsync{}, nil) return wrapFloat64SumObserverInstrument(NoopAsync{}, nil)
} }
return wrapFloat64SumObserverInstrument( return wrapFloat64SumObserverInstrument(
b.meter.newAsync(name, SumObserverInstrumentKind, number.Float64Kind, opts, b.meter.newAsync(name, sdkapi.SumObserverInstrumentKind, number.Float64Kind, opts,
b.runner)) b.runner))
} }
@ -249,7 +250,7 @@ func (b BatchObserver) NewInt64UpDownSumObserver(name string, opts ...Instrument
return wrapInt64UpDownSumObserverInstrument(NoopAsync{}, nil) return wrapInt64UpDownSumObserverInstrument(NoopAsync{}, nil)
} }
return wrapInt64UpDownSumObserverInstrument( return wrapInt64UpDownSumObserverInstrument(
b.meter.newAsync(name, UpDownSumObserverInstrumentKind, number.Int64Kind, opts, b.runner)) b.meter.newAsync(name, sdkapi.UpDownSumObserverInstrumentKind, number.Int64Kind, opts, b.runner))
} }
// NewFloat64UpDownSumObserver creates a new floating point UpDownSumObserver with // NewFloat64UpDownSumObserver creates a new floating point UpDownSumObserver with
@ -261,7 +262,7 @@ func (b BatchObserver) NewFloat64UpDownSumObserver(name string, opts ...Instrume
return wrapFloat64UpDownSumObserverInstrument(NoopAsync{}, nil) return wrapFloat64UpDownSumObserverInstrument(NoopAsync{}, nil)
} }
return wrapFloat64UpDownSumObserverInstrument( return wrapFloat64UpDownSumObserverInstrument(
b.meter.newAsync(name, UpDownSumObserverInstrumentKind, number.Float64Kind, opts, b.meter.newAsync(name, sdkapi.UpDownSumObserverInstrumentKind, number.Float64Kind, opts,
b.runner)) b.runner))
} }
@ -273,7 +274,7 @@ func (m Meter) MeterImpl() MeterImpl {
// newAsync constructs one new asynchronous instrument. // newAsync constructs one new asynchronous instrument.
func (m Meter) newAsync( func (m Meter) newAsync(
name string, name string,
mkind InstrumentKind, mkind sdkapi.InstrumentKind,
nkind number.Kind, nkind number.Kind,
opts []InstrumentOption, opts []InstrumentOption,
runner AsyncRunner, runner AsyncRunner,
@ -293,7 +294,7 @@ func (m Meter) newAsync(
// newSync constructs one new synchronous instrument. // newSync constructs one new synchronous instrument.
func (m Meter) newSync( func (m Meter) newSync(
name string, name string,
metricKind InstrumentKind, metricKind sdkapi.InstrumentKind,
numberKind number.Kind, numberKind number.Kind,
opts []InstrumentOption, opts []InstrumentOption,
) ( ) (
@ -521,13 +522,13 @@ func (bm BatchObserverMust) NewFloat64UpDownSumObserver(name string, oos ...Inst
// options. // options.
type Descriptor struct { type Descriptor struct {
name string name string
instrumentKind InstrumentKind instrumentKind sdkapi.InstrumentKind
numberKind number.Kind numberKind number.Kind
config InstrumentConfig config InstrumentConfig
} }
// NewDescriptor returns a Descriptor with the given contents. // NewDescriptor returns a Descriptor with the given contents.
func NewDescriptor(name string, ikind InstrumentKind, nkind number.Kind, opts ...InstrumentOption) Descriptor { func NewDescriptor(name string, ikind sdkapi.InstrumentKind, nkind number.Kind, opts ...InstrumentOption) Descriptor {
return Descriptor{ return Descriptor{
name: name, name: name,
instrumentKind: ikind, instrumentKind: ikind,
@ -542,7 +543,7 @@ func (d Descriptor) Name() string {
} }
// InstrumentKind returns the specific kind of instrument. // InstrumentKind returns the specific kind of instrument.
func (d Descriptor) InstrumentKind() InstrumentKind { func (d Descriptor) InstrumentKind() sdkapi.InstrumentKind {
return d.instrumentKind return d.instrumentKind
} }

View File

@ -12,8 +12,6 @@
// 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.
//go:generate stringer -type=InstrumentKind
package metric // import "go.opentelemetry.io/otel/metric" package metric // import "go.opentelemetry.io/otel/metric"
import ( import (
@ -27,69 +25,6 @@ import (
// ErrSDKReturnedNilImpl is returned when a new `MeterImpl` returns nil. // ErrSDKReturnedNilImpl is returned when a new `MeterImpl` returns nil.
var ErrSDKReturnedNilImpl = errors.New("SDK returned a nil implementation") var ErrSDKReturnedNilImpl = errors.New("SDK returned a nil implementation")
// InstrumentKind describes the kind of instrument.
type InstrumentKind int8
const (
// ValueRecorderInstrumentKind indicates a ValueRecorder instrument.
ValueRecorderInstrumentKind InstrumentKind = iota
// ValueObserverInstrumentKind indicates an ValueObserver instrument.
ValueObserverInstrumentKind
// CounterInstrumentKind indicates a Counter instrument.
CounterInstrumentKind
// UpDownCounterInstrumentKind indicates a UpDownCounter instrument.
UpDownCounterInstrumentKind
// SumObserverInstrumentKind indicates a SumObserver instrument.
SumObserverInstrumentKind
// UpDownSumObserverInstrumentKind indicates a UpDownSumObserver
// instrument.
UpDownSumObserverInstrumentKind
)
// Synchronous returns whether this is a synchronous kind of instrument.
func (k InstrumentKind) Synchronous() bool {
switch k {
case CounterInstrumentKind, UpDownCounterInstrumentKind, ValueRecorderInstrumentKind:
return true
}
return false
}
// Asynchronous returns whether this is an asynchronous kind of instrument.
func (k InstrumentKind) Asynchronous() bool {
return !k.Synchronous()
}
// Adding returns whether this kind of instrument adds its inputs (as opposed to Grouping).
func (k InstrumentKind) Adding() bool {
switch k {
case CounterInstrumentKind, UpDownCounterInstrumentKind, SumObserverInstrumentKind, UpDownSumObserverInstrumentKind:
return true
}
return false
}
// Grouping returns whether this kind of instrument groups its inputs (as opposed to Adding).
func (k InstrumentKind) Grouping() bool {
return !k.Adding()
}
// Monotonic returns whether this kind of instrument exposes a non-decreasing sum.
func (k InstrumentKind) Monotonic() bool {
switch k {
case CounterInstrumentKind, SumObserverInstrumentKind:
return true
}
return false
}
// PrecomputedSum returns whether this kind of instrument receives precomputed sums.
func (k InstrumentKind) PrecomputedSum() bool {
return k.Adding() && k.Asynchronous()
}
// Observation is used for reporting an asynchronous batch of metric // Observation is used for reporting an asynchronous batch of metric
// values. Instances of this type should be created by asynchronous // values. Instances of this type should be created by asynchronous
// instruments (e.g., Int64ValueObserver.Observation()). // instruments (e.g., Int64ValueObserver.Observation()).

View File

@ -23,6 +23,7 @@ import (
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/metrictest" "go.opentelemetry.io/otel/metric/metrictest"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
"go.opentelemetry.io/otel/metric/unit" "go.opentelemetry.io/otel/metric/unit"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
@ -33,49 +34,49 @@ import (
var Must = metric.Must var Must = metric.Must
var ( var (
syncKinds = []metric.InstrumentKind{ syncKinds = []sdkapi.InstrumentKind{
metric.ValueRecorderInstrumentKind, sdkapi.ValueRecorderInstrumentKind,
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
metric.UpDownCounterInstrumentKind, sdkapi.UpDownCounterInstrumentKind,
} }
asyncKinds = []metric.InstrumentKind{ asyncKinds = []sdkapi.InstrumentKind{
metric.ValueObserverInstrumentKind, sdkapi.ValueObserverInstrumentKind,
metric.SumObserverInstrumentKind, sdkapi.SumObserverInstrumentKind,
metric.UpDownSumObserverInstrumentKind, sdkapi.UpDownSumObserverInstrumentKind,
} }
addingKinds = []metric.InstrumentKind{ addingKinds = []sdkapi.InstrumentKind{
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
metric.UpDownCounterInstrumentKind, sdkapi.UpDownCounterInstrumentKind,
metric.SumObserverInstrumentKind, sdkapi.SumObserverInstrumentKind,
metric.UpDownSumObserverInstrumentKind, sdkapi.UpDownSumObserverInstrumentKind,
} }
groupingKinds = []metric.InstrumentKind{ groupingKinds = []sdkapi.InstrumentKind{
metric.ValueRecorderInstrumentKind, sdkapi.ValueRecorderInstrumentKind,
metric.ValueObserverInstrumentKind, sdkapi.ValueObserverInstrumentKind,
} }
monotonicKinds = []metric.InstrumentKind{ monotonicKinds = []sdkapi.InstrumentKind{
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
metric.SumObserverInstrumentKind, sdkapi.SumObserverInstrumentKind,
} }
nonMonotonicKinds = []metric.InstrumentKind{ nonMonotonicKinds = []sdkapi.InstrumentKind{
metric.UpDownCounterInstrumentKind, sdkapi.UpDownCounterInstrumentKind,
metric.UpDownSumObserverInstrumentKind, sdkapi.UpDownSumObserverInstrumentKind,
metric.ValueRecorderInstrumentKind, sdkapi.ValueRecorderInstrumentKind,
metric.ValueObserverInstrumentKind, sdkapi.ValueObserverInstrumentKind,
} }
precomputedSumKinds = []metric.InstrumentKind{ precomputedSumKinds = []sdkapi.InstrumentKind{
metric.SumObserverInstrumentKind, sdkapi.SumObserverInstrumentKind,
metric.UpDownSumObserverInstrumentKind, sdkapi.UpDownSumObserverInstrumentKind,
} }
nonPrecomputedSumKinds = []metric.InstrumentKind{ nonPrecomputedSumKinds = []sdkapi.InstrumentKind{
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
metric.UpDownCounterInstrumentKind, sdkapi.UpDownCounterInstrumentKind,
metric.ValueRecorderInstrumentKind, sdkapi.ValueRecorderInstrumentKind,
metric.ValueObserverInstrumentKind, sdkapi.ValueObserverInstrumentKind,
} }
) )
@ -119,7 +120,7 @@ func TestPrecomputedSum(t *testing.T) {
} }
} }
func checkSyncBatches(ctx context.Context, t *testing.T, labels []attribute.KeyValue, mock *metrictest.MeterImpl, nkind number.Kind, mkind metric.InstrumentKind, instrument metric.InstrumentImpl, expected ...float64) { func checkSyncBatches(ctx context.Context, t *testing.T, labels []attribute.KeyValue, mock *metrictest.MeterImpl, nkind number.Kind, mkind sdkapi.InstrumentKind, instrument metric.InstrumentImpl, expected ...float64) {
t.Helper() t.Helper()
batchesCount := len(mock.MeasurementBatches) batchesCount := len(mock.MeasurementBatches)
@ -316,7 +317,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, metric.CounterInstrumentKind, c.SyncImpl(), checkSyncBatches(ctx, t, labels, mockSDK, number.Float64Kind, sdkapi.CounterInstrumentKind, c.SyncImpl(),
1994.1, -742, 42, 1994.1, -742, 42,
) )
}) })
@ -329,7 +330,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, metric.CounterInstrumentKind, c.SyncImpl(), checkSyncBatches(ctx, t, labels, mockSDK, number.Int64Kind, sdkapi.CounterInstrumentKind, c.SyncImpl(),
42, 4200, 420000, 42, 4200, 420000,
) )
@ -343,7 +344,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, metric.UpDownCounterInstrumentKind, c.SyncImpl(), checkSyncBatches(ctx, t, labels, mockSDK, number.Int64Kind, sdkapi.UpDownCounterInstrumentKind, c.SyncImpl(),
100, -100, 42, 100, -100, 42,
) )
}) })
@ -356,7 +357,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, metric.UpDownCounterInstrumentKind, c.SyncImpl(), checkSyncBatches(ctx, t, labels, mockSDK, number.Float64Kind, sdkapi.UpDownCounterInstrumentKind, c.SyncImpl(),
100.1, -76, -100.1, 100.1, -76, -100.1,
) )
}) })
@ -372,7 +373,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, metric.ValueRecorderInstrumentKind, m.SyncImpl(), checkSyncBatches(ctx, t, labels, mockSDK, number.Float64Kind, sdkapi.ValueRecorderInstrumentKind, m.SyncImpl(),
42, 0, -100.5, 42, 0, -100.5,
) )
}) })
@ -385,7 +386,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, metric.ValueRecorderInstrumentKind, m.SyncImpl(), checkSyncBatches(ctx, t, labels, mockSDK, number.Int64Kind, sdkapi.ValueRecorderInstrumentKind, m.SyncImpl(),
173, 80, 0, 173, 80, 0,
) )
}) })
@ -399,7 +400,7 @@ func TestObserverInstruments(t *testing.T) {
result.Observe(42.1, labels...) result.Observe(42.1, labels...)
}) })
mockSDK.RunAsyncInstruments() mockSDK.RunAsyncInstruments()
checkObserverBatch(t, labels, mockSDK, number.Float64Kind, metric.ValueObserverInstrumentKind, o.AsyncImpl(), checkObserverBatch(t, labels, mockSDK, number.Float64Kind, sdkapi.ValueObserverInstrumentKind, o.AsyncImpl(),
42.1, 42.1,
) )
}) })
@ -410,7 +411,7 @@ func TestObserverInstruments(t *testing.T) {
result.Observe(-142, labels...) result.Observe(-142, labels...)
}) })
mockSDK.RunAsyncInstruments() mockSDK.RunAsyncInstruments()
checkObserverBatch(t, labels, mockSDK, number.Int64Kind, metric.ValueObserverInstrumentKind, o.AsyncImpl(), checkObserverBatch(t, labels, mockSDK, number.Int64Kind, sdkapi.ValueObserverInstrumentKind, o.AsyncImpl(),
-142, -142,
) )
}) })
@ -421,7 +422,7 @@ func TestObserverInstruments(t *testing.T) {
result.Observe(42.1, labels...) result.Observe(42.1, labels...)
}) })
mockSDK.RunAsyncInstruments() mockSDK.RunAsyncInstruments()
checkObserverBatch(t, labels, mockSDK, number.Float64Kind, metric.SumObserverInstrumentKind, o.AsyncImpl(), checkObserverBatch(t, labels, mockSDK, number.Float64Kind, sdkapi.SumObserverInstrumentKind, o.AsyncImpl(),
42.1, 42.1,
) )
}) })
@ -432,7 +433,7 @@ func TestObserverInstruments(t *testing.T) {
result.Observe(-142, labels...) result.Observe(-142, labels...)
}) })
mockSDK.RunAsyncInstruments() mockSDK.RunAsyncInstruments()
checkObserverBatch(t, labels, mockSDK, number.Int64Kind, metric.SumObserverInstrumentKind, o.AsyncImpl(), checkObserverBatch(t, labels, mockSDK, number.Int64Kind, sdkapi.SumObserverInstrumentKind, o.AsyncImpl(),
-142, -142,
) )
}) })
@ -443,7 +444,7 @@ func TestObserverInstruments(t *testing.T) {
result.Observe(42.1, labels...) result.Observe(42.1, labels...)
}) })
mockSDK.RunAsyncInstruments() mockSDK.RunAsyncInstruments()
checkObserverBatch(t, labels, mockSDK, number.Float64Kind, metric.UpDownSumObserverInstrumentKind, o.AsyncImpl(), checkObserverBatch(t, labels, mockSDK, number.Float64Kind, sdkapi.UpDownSumObserverInstrumentKind, o.AsyncImpl(),
42.1, 42.1,
) )
}) })
@ -454,7 +455,7 @@ func TestObserverInstruments(t *testing.T) {
result.Observe(-142, labels...) result.Observe(-142, labels...)
}) })
mockSDK.RunAsyncInstruments() mockSDK.RunAsyncInstruments()
checkObserverBatch(t, labels, mockSDK, number.Int64Kind, metric.UpDownSumObserverInstrumentKind, o.AsyncImpl(), checkObserverBatch(t, labels, mockSDK, number.Int64Kind, sdkapi.UpDownSumObserverInstrumentKind, o.AsyncImpl(),
-142, -142,
) )
}) })
@ -505,7 +506,7 @@ func TestBatchObserverInstruments(t *testing.T) {
require.Equal(t, 0, m2.Number.CompareNumber(number.Float64Kind, metrictest.ResolveNumberByKind(t, number.Float64Kind, 42))) require.Equal(t, 0, m2.Number.CompareNumber(number.Float64Kind, metrictest.ResolveNumberByKind(t, number.Float64Kind, 42)))
} }
func checkObserverBatch(t *testing.T, labels []attribute.KeyValue, mock *metrictest.MeterImpl, nkind number.Kind, mkind metric.InstrumentKind, observer metric.AsyncImpl, expected float64) { func checkObserverBatch(t *testing.T, labels []attribute.KeyValue, mock *metrictest.MeterImpl, nkind number.Kind, mkind sdkapi.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 {

View File

@ -0,0 +1,80 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:generate stringer -type=InstrumentKind
package sdkapi // import "go.opentelemetry.io/otel/metric/sdkapi"
// InstrumentKind describes the kind of instrument.
type InstrumentKind int8
const (
// ValueRecorderInstrumentKind indicates a ValueRecorder instrument.
ValueRecorderInstrumentKind InstrumentKind = iota
// ValueObserverInstrumentKind indicates an ValueObserver instrument.
ValueObserverInstrumentKind
// CounterInstrumentKind indicates a Counter instrument.
CounterInstrumentKind
// UpDownCounterInstrumentKind indicates a UpDownCounter instrument.
UpDownCounterInstrumentKind
// SumObserverInstrumentKind indicates a SumObserver instrument.
SumObserverInstrumentKind
// UpDownSumObserverInstrumentKind indicates a UpDownSumObserver
// instrument.
UpDownSumObserverInstrumentKind
)
// Synchronous returns whether this is a synchronous kind of instrument.
func (k InstrumentKind) Synchronous() bool {
switch k {
case CounterInstrumentKind, UpDownCounterInstrumentKind, ValueRecorderInstrumentKind:
return true
}
return false
}
// Asynchronous returns whether this is an asynchronous kind of instrument.
func (k InstrumentKind) Asynchronous() bool {
return !k.Synchronous()
}
// Adding returns whether this kind of instrument adds its inputs (as opposed to Grouping).
func (k InstrumentKind) Adding() bool {
switch k {
case CounterInstrumentKind, UpDownCounterInstrumentKind, SumObserverInstrumentKind, UpDownSumObserverInstrumentKind:
return true
}
return false
}
// Grouping returns whether this kind of instrument groups its inputs (as opposed to Adding).
func (k InstrumentKind) Grouping() bool {
return !k.Adding()
}
// Monotonic returns whether this kind of instrument exposes a non-decreasing sum.
func (k InstrumentKind) Monotonic() bool {
switch k {
case CounterInstrumentKind, SumObserverInstrumentKind:
return true
}
return false
}
// PrecomputedSum returns whether this kind of instrument receives precomputed sums.
func (k InstrumentKind) PrecomputedSum() bool {
return k.Adding() && k.Asynchronous()
}

View File

@ -1,6 +1,6 @@
// Code generated by "stringer -type=InstrumentKind"; DO NOT EDIT. // Code generated by "stringer -type=InstrumentKind"; DO NOT EDIT.
package metric package sdkapi
import "strconv" import "strconv"

View File

@ -0,0 +1,32 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package sdkapi_test
import (
"testing"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/metric/sdkapi"
)
func TestInstrumentKinds(t *testing.T) {
require.Equal(t, sdkapi.ValueRecorderInstrumentKind.String(), "ValueRecorderInstrumentKind")
require.Equal(t, sdkapi.ValueObserverInstrumentKind.String(), "ValueObserverInstrumentKind")
require.Equal(t, sdkapi.CounterInstrumentKind.String(), "CounterInstrumentKind")
require.Equal(t, sdkapi.UpDownCounterInstrumentKind.String(), "UpDownCounterInstrumentKind")
require.Equal(t, sdkapi.SumObserverInstrumentKind.String(), "SumObserverInstrumentKind")
require.Equal(t, sdkapi.UpDownSumObserverInstrumentKind.String(), "UpDownSumObserverInstrumentKind")
}

View File

@ -21,6 +21,7 @@ import (
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation" "go.opentelemetry.io/otel/sdk/export/metric/aggregation"
) )
@ -29,16 +30,16 @@ func TestExportKindIncludes(t *testing.T) {
require.True(t, DeltaExportKind.Includes(CumulativeExportKind|DeltaExportKind)) require.True(t, DeltaExportKind.Includes(CumulativeExportKind|DeltaExportKind))
} }
var deltaMemoryKinds = []metric.InstrumentKind{ var deltaMemoryKinds = []sdkapi.InstrumentKind{
metric.SumObserverInstrumentKind, sdkapi.SumObserverInstrumentKind,
metric.UpDownSumObserverInstrumentKind, sdkapi.UpDownSumObserverInstrumentKind,
} }
var cumulativeMemoryKinds = []metric.InstrumentKind{ var cumulativeMemoryKinds = []sdkapi.InstrumentKind{
metric.ValueRecorderInstrumentKind, sdkapi.ValueRecorderInstrumentKind,
metric.ValueObserverInstrumentKind, sdkapi.ValueObserverInstrumentKind,
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
metric.UpDownCounterInstrumentKind, sdkapi.UpDownCounterInstrumentKind,
} }
func TestExportKindMemoryRequired(t *testing.T) { func TestExportKindMemoryRequired(t *testing.T) {

View File

@ -24,6 +24,7 @@ import (
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
"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"
) )
@ -379,14 +380,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 metric.InstrumentKind) bool { func (kind ExportKind) MemoryRequired(mkind sdkapi.InstrumentKind) bool {
switch mkind { switch mkind {
case metric.ValueRecorderInstrumentKind, metric.ValueObserverInstrumentKind, case sdkapi.ValueRecorderInstrumentKind, sdkapi.ValueObserverInstrumentKind,
metric.CounterInstrumentKind, metric.UpDownCounterInstrumentKind: sdkapi.CounterInstrumentKind, sdkapi.UpDownCounterInstrumentKind:
// Delta-oriented instruments: // Delta-oriented instruments:
return kind.Includes(CumulativeExportKind) return kind.Includes(CumulativeExportKind)
case metric.SumObserverInstrumentKind, metric.UpDownSumObserverInstrumentKind: case sdkapi.SumObserverInstrumentKind, sdkapi.UpDownSumObserverInstrumentKind:
// Cumulative-oriented instruments: // Cumulative-oriented instruments:
return kind.Includes(DeltaExportKind) return kind.Includes(DeltaExportKind)
} }

View File

@ -20,6 +20,7 @@ import (
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
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 +44,7 @@ func RangeTest(num number.Number, descriptor *metric.Descriptor) error {
} }
switch descriptor.InstrumentKind() { switch descriptor.InstrumentKind() {
case metric.CounterInstrumentKind, metric.SumObserverInstrumentKind: case sdkapi.CounterInstrumentKind, sdkapi.SumObserverInstrumentKind:
if num.IsNegative(numberKind) { if num.IsNegative(numberKind) {
return aggregation.ErrNegativeInput return aggregation.ErrNegativeInput
} }

View File

@ -23,6 +23,7 @@ import (
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
"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"
"go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue" "go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue"
@ -75,7 +76,7 @@ func TestRangeTest(t *testing.T) {
t.Run(nkind.String(), func(t *testing.T) { t.Run(nkind.String(), func(t *testing.T) {
desc := metric.NewDescriptor( desc := metric.NewDescriptor(
"name", "name",
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
nkind, nkind,
) )
testRangeNegative(t, &desc) testRangeNegative(t, &desc)
@ -86,10 +87,10 @@ 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 []metric.InstrumentKind{ for _, mkind := range []sdkapi.InstrumentKind{
metric.CounterInstrumentKind, sdkapi.CounterInstrumentKind,
metric.ValueRecorderInstrumentKind, sdkapi.ValueRecorderInstrumentKind,
metric.ValueObserverInstrumentKind, sdkapi.ValueObserverInstrumentKind,
} { } {
desc := metric.NewDescriptor( desc := metric.NewDescriptor(
"name", "name",

View File

@ -28,6 +28,7 @@ import (
ottest "go.opentelemetry.io/otel/internal/internaltest" ottest "go.opentelemetry.io/otel/internal/internaltest"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
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" "go.opentelemetry.io/otel/sdk/metric/aggregator"
@ -64,7 +65,7 @@ func newProfiles() []Profile {
} }
} }
func NewAggregatorTest(mkind metric.InstrumentKind, nkind number.Kind) *metric.Descriptor { func NewAggregatorTest(mkind sdkapi.InstrumentKind, nkind number.Kind) *metric.Descriptor {
desc := metric.NewDescriptor("test.name", mkind, nkind) desc := metric.NewDescriptor("test.name", mkind, nkind)
return &desc return &desc
} }
@ -191,7 +192,7 @@ func (NoopAggregator) Merge(export.Aggregator, *metric.Descriptor) error {
return nil return nil
} }
func SynchronizedMoveResetTest(t *testing.T, mkind metric.InstrumentKind, nf func(*metric.Descriptor) export.Aggregator) { func SynchronizedMoveResetTest(t *testing.T, mkind sdkapi.InstrumentKind, nf func(*metric.Descriptor) export.Aggregator) {
t.Run("reset on nil", func(t *testing.T) { t.Run("reset on nil", func(t *testing.T) {
// Ensures that SynchronizedMove(nil, descriptor) discards and // Ensures that SynchronizedMove(nil, descriptor) discards and
// resets the aggregator. // resets the aggregator.

View File

@ -24,6 +24,7 @@ import (
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
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/aggregatortest" "go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest"
@ -66,7 +67,7 @@ func sumOf(samples []aggregation.Point, k number.Kind) number.Number {
} }
func (ut *updateTest) run(t *testing.T, profile aggregatortest.Profile) { func (ut *updateTest) run(t *testing.T, profile aggregatortest.Profile) {
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind)
agg, ckpt := new2() agg, ckpt := new2()
all := aggregatortest.NewNumbers(profile.NumberKind) all := aggregatortest.NewNumbers(profile.NumberKind)
@ -128,7 +129,7 @@ func advance() {
} }
func (mt *mergeTest) run(t *testing.T, profile aggregatortest.Profile) { func (mt *mergeTest) run(t *testing.T, profile aggregatortest.Profile) {
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind)
agg1, agg2, ckpt1, ckpt2 := new4() agg1, agg2, ckpt1, ckpt2 := new4()
all := aggregatortest.NewNumbers(profile.NumberKind) all := aggregatortest.NewNumbers(profile.NumberKind)
@ -214,7 +215,7 @@ func TestExactErrors(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(metric.ValueRecorderInstrumentKind, profile.NumberKind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind)
advance() advance()
aggregatortest.CheckedUpdate(t, agg, number.Number(0), descriptor) aggregatortest.CheckedUpdate(t, agg, number.Number(0), descriptor)
@ -232,7 +233,7 @@ func TestExactErrors(t *testing.T) {
} }
func TestExactFloat64(t *testing.T) { func TestExactFloat64(t *testing.T) {
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, number.Float64Kind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.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
@ -310,7 +311,7 @@ func TestExactFloat64(t *testing.T) {
func TestSynchronizedMoveReset(t *testing.T) { func TestSynchronizedMoveReset(t *testing.T) {
aggregatortest.SynchronizedMoveResetTest( aggregatortest.SynchronizedMoveResetTest(
t, t,
metric.ValueRecorderInstrumentKind, sdkapi.ValueRecorderInstrumentKind,
func(desc *metric.Descriptor) export.Aggregator { func(desc *metric.Descriptor) export.Aggregator {
return &New(1)[0] return &New(1)[0]
}, },
@ -321,7 +322,7 @@ func TestMergeBehavior(t *testing.T) {
aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) {
for _, forward := range []bool{false, true} { for _, forward := range []bool{false, true} {
t.Run(fmt.Sprint("Forward=", forward), func(t *testing.T) { t.Run(fmt.Sprint("Forward=", forward), func(t *testing.T) {
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind)
agg1, agg2, ckpt, _ := new4() agg1, agg2, ckpt, _ := new4()
all := aggregatortest.NewNumbers(profile.NumberKind) all := aggregatortest.NewNumbers(profile.NumberKind)

View File

@ -19,8 +19,8 @@ import (
"math/rand" "math/rand"
"testing" "testing"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
"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(metric.ValueRecorderInstrumentKind, number.Float64Kind) desc := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, number.Float64Kind)
agg := &histogram.New(1, desc, histogram.WithExplicitBoundaries(boundaries))[0] agg := &histogram.New(1, desc, histogram.WithExplicitBoundaries(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(metric.ValueRecorderInstrumentKind, number.Int64Kind) desc := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, number.Int64Kind)
agg := &histogram.New(1, desc, histogram.WithExplicitBoundaries(boundaries))[0] agg := &histogram.New(1, desc, histogram.WithExplicitBoundaries(boundaries))[0]
ctx := context.Background() ctx := context.Background()

View File

@ -25,6 +25,7 @@ import (
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
"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"
@ -111,7 +112,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(metric.ValueRecorderInstrumentKind, profile.NumberKind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind)
agg, ckpt := new2(descriptor, histogram.WithExplicitBoundaries(testBoundaries)) agg, ckpt := new2(descriptor, histogram.WithExplicitBoundaries(testBoundaries))
@ -137,7 +138,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(metric.ValueRecorderInstrumentKind, profile.NumberKind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind)
agg := &histogram.New(1, descriptor, histogram.WithExplicitBoundaries(testBoundaries))[0] agg := &histogram.New(1, descriptor, histogram.WithExplicitBoundaries(testBoundaries))[0]
buckets, err := agg.Histogram() buckets, err := agg.Histogram()
@ -150,7 +151,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(metric.ValueRecorderInstrumentKind, profile.NumberKind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind)
agg1, agg2, ckpt1, ckpt2 := new4(descriptor, histogram.WithExplicitBoundaries(testBoundaries)) agg1, agg2, ckpt1, ckpt2 := new4(descriptor, histogram.WithExplicitBoundaries(testBoundaries))
@ -178,7 +179,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(metric.ValueRecorderInstrumentKind, profile.NumberKind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind)
agg, ckpt := new2(descriptor, histogram.WithExplicitBoundaries(testBoundaries)) agg, ckpt := new2(descriptor, histogram.WithExplicitBoundaries(testBoundaries))
@ -239,7 +240,7 @@ func checkHistogram(t *testing.T, all aggregatortest.Numbers, profile aggregator
func TestSynchronizedMoveReset(t *testing.T) { func TestSynchronizedMoveReset(t *testing.T) {
aggregatortest.SynchronizedMoveResetTest( aggregatortest.SynchronizedMoveResetTest(
t, t,
metric.ValueRecorderInstrumentKind, sdkapi.ValueRecorderInstrumentKind,
func(desc *metric.Descriptor) export.Aggregator { func(desc *metric.Descriptor) export.Aggregator {
return &histogram.New(1, desc, histogram.WithExplicitBoundaries(testBoundaries))[0] return &histogram.New(1, desc, histogram.WithExplicitBoundaries(testBoundaries))[0]
}, },
@ -249,7 +250,7 @@ func TestSynchronizedMoveReset(t *testing.T) {
func TestHistogramDefaultBoundaries(t *testing.T) { func TestHistogramDefaultBoundaries(t *testing.T) {
aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) { aggregatortest.RunProfiles(t, func(t *testing.T, profile aggregatortest.Profile) {
ctx := context.Background() ctx := context.Background()
descriptor := aggregatortest.NewAggregatorTest(metric.ValueRecorderInstrumentKind, profile.NumberKind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind)
agg, ckpt := new2(descriptor) agg, ckpt := new2(descriptor)

View File

@ -27,6 +27,7 @@ import (
ottest "go.opentelemetry.io/otel/internal/internaltest" ottest "go.opentelemetry.io/otel/internal/internaltest"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
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/aggregatortest" "go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest"
@ -72,7 +73,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(metric.ValueObserverInstrumentKind, profile.NumberKind) record := aggregatortest.NewAggregatorTest(sdkapi.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 +95,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(metric.ValueObserverInstrumentKind, profile.NumberKind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueObserverInstrumentKind, profile.NumberKind)
first1 := profile.Random(+1) first1 := profile.Random(+1)
first2 := profile.Random(+1) first2 := profile.Random(+1)
@ -127,7 +128,7 @@ func TestLastValueMerge(t *testing.T) {
} }
func TestLastValueNotSet(t *testing.T) { func TestLastValueNotSet(t *testing.T) {
descriptor := aggregatortest.NewAggregatorTest(metric.ValueObserverInstrumentKind, number.Int64Kind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueObserverInstrumentKind, number.Int64Kind)
g, ckpt := new2() g, ckpt := new2()
require.NoError(t, g.SynchronizedMove(ckpt, descriptor)) require.NoError(t, g.SynchronizedMove(ckpt, descriptor))
@ -138,7 +139,7 @@ func TestLastValueNotSet(t *testing.T) {
func TestSynchronizedMoveReset(t *testing.T) { func TestSynchronizedMoveReset(t *testing.T) {
aggregatortest.SynchronizedMoveResetTest( aggregatortest.SynchronizedMoveResetTest(
t, t,
metric.ValueObserverInstrumentKind, sdkapi.ValueObserverInstrumentKind,
func(desc *metric.Descriptor) export.Aggregator { func(desc *metric.Descriptor) export.Aggregator {
return &New(1)[0] return &New(1)[0]
}, },

View File

@ -24,6 +24,7 @@ import (
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
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/aggregatortest" "go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest"
@ -110,7 +111,7 @@ func checkZero(t *testing.T, agg *Aggregator, desc *metric.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(metric.ValueRecorderInstrumentKind, profile.NumberKind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind)
agg, ckpt := new2(descriptor) agg, ckpt := new2(descriptor)
@ -158,7 +159,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(metric.ValueRecorderInstrumentKind, profile.NumberKind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind)
agg1, agg2, ckpt1, ckpt2 := new4(descriptor) agg1, agg2, ckpt1, ckpt2 := new4(descriptor)
@ -216,7 +217,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(metric.ValueRecorderInstrumentKind, profile.NumberKind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind)
alloc := New(2, descriptor) alloc := New(2, descriptor)
agg, ckpt := &alloc[0], &alloc[1] agg, ckpt := &alloc[0], &alloc[1]
@ -240,7 +241,7 @@ func TestMaxSumCountNotSet(t *testing.T) {
func TestSynchronizedMoveReset(t *testing.T) { func TestSynchronizedMoveReset(t *testing.T) {
aggregatortest.SynchronizedMoveResetTest( aggregatortest.SynchronizedMoveResetTest(
t, t,
metric.ValueRecorderInstrumentKind, sdkapi.ValueRecorderInstrumentKind,
func(desc *metric.Descriptor) export.Aggregator { func(desc *metric.Descriptor) export.Aggregator {
return &New(1, desc)[0] return &New(1, desc)[0]
}, },

View File

@ -24,6 +24,7 @@ import (
ottest "go.opentelemetry.io/otel/internal/internaltest" ottest "go.opentelemetry.io/otel/internal/internaltest"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest" "go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest"
) )
@ -67,7 +68,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(metric.CounterInstrumentKind, profile.NumberKind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.CounterInstrumentKind, profile.NumberKind)
sum := number.Number(0) sum := number.Number(0)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
@ -91,7 +92,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(metric.ValueRecorderInstrumentKind, profile.NumberKind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.ValueRecorderInstrumentKind, profile.NumberKind)
sum := number.Number(0) sum := number.Number(0)
@ -117,7 +118,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(metric.CounterInstrumentKind, profile.NumberKind) descriptor := aggregatortest.NewAggregatorTest(sdkapi.CounterInstrumentKind, profile.NumberKind)
sum := number.Number(0) sum := number.Number(0)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
@ -146,7 +147,7 @@ func TestCounterMerge(t *testing.T) {
func TestSynchronizedMoveReset(t *testing.T) { func TestSynchronizedMoveReset(t *testing.T) {
aggregatortest.SynchronizedMoveResetTest( aggregatortest.SynchronizedMoveResetTest(
t, t,
metric.SumObserverInstrumentKind, sdkapi.SumObserverInstrumentKind,
func(desc *metric.Descriptor) export.Aggregator { func(desc *metric.Descriptor) export.Aggregator {
return &New(1)[0] return &New(1)[0]
}, },

View File

@ -24,11 +24,12 @@ import (
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
"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 := metric.NewDescriptor("some_metric", metric.ValueRecorderInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("some_metric", sdkapi.ValueRecorderInstrumentKind, number.Int64Kind)
alloc := histogram.New(2, &desc, histogram.WithExplicitBoundaries([]float64{25, 50, 75})) alloc := histogram.New(2, &desc, histogram.WithExplicitBoundaries([]float64{25, 50, 75}))
h, ckpt := &alloc[0], &alloc[1] h, ckpt := &alloc[0], &alloc[1]

View File

@ -22,11 +22,12 @@ import (
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
"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 := metric.NewDescriptor("some_metric", metric.ValueRecorderInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("some_metric", sdkapi.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]

View File

@ -27,6 +27,7 @@ import (
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
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"
sdk "go.opentelemetry.io/otel/sdk/metric" sdk "go.opentelemetry.io/otel/sdk/metric"
@ -47,7 +48,7 @@ func TestProcessor(t *testing.T) {
kind export.ExportKind kind export.ExportKind
} }
type instrumentCase struct { type instrumentCase struct {
kind metric.InstrumentKind kind sdkapi.InstrumentKind
} }
type numberCase struct { type numberCase struct {
kind number.Kind kind number.Kind
@ -62,12 +63,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: metric.CounterInstrumentKind}, {kind: sdkapi.CounterInstrumentKind},
{kind: metric.UpDownCounterInstrumentKind}, {kind: sdkapi.UpDownCounterInstrumentKind},
{kind: metric.ValueRecorderInstrumentKind}, {kind: sdkapi.ValueRecorderInstrumentKind},
{kind: metric.SumObserverInstrumentKind}, {kind: sdkapi.SumObserverInstrumentKind},
{kind: metric.UpDownSumObserverInstrumentKind}, {kind: sdkapi.UpDownSumObserverInstrumentKind},
{kind: metric.ValueObserverInstrumentKind}, {kind: sdkapi.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{
@ -119,7 +120,7 @@ func updateFor(t *testing.T, desc *metric.Descriptor, selector export.Aggregator
func testProcessor( func testProcessor(
t *testing.T, t *testing.T,
ekind export.ExportKind, ekind export.ExportKind,
mkind metric.InstrumentKind, mkind sdkapi.InstrumentKind,
nkind number.Kind, nkind number.Kind,
akind aggregation.Kind, akind aggregation.Kind,
) { ) {
@ -300,7 +301,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 := metric.NewDescriptor("inst", metric.CounterInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("inst", sdkapi.CounterInstrumentKind, number.Int64Kind)
accum := export.NewAccumulation(&desc, attribute.EmptySet(), resource.Empty(), aggregatortest.NoopAggregator{}) accum := export.NewAccumulation(&desc, attribute.EmptySet(), resource.Empty(), aggregatortest.NoopAggregator{})
require.Equal(t, basic.ErrInconsistentState, b.Process(accum)) require.Equal(t, basic.ErrInconsistentState, b.Process(accum))
@ -325,7 +326,7 @@ func TestBasicTimestamps(t *testing.T) {
time.Sleep(time.Nanosecond) time.Sleep(time.Nanosecond)
afterNew := time.Now() afterNew := time.Now()
desc := metric.NewDescriptor("inst", metric.CounterInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("inst", sdkapi.CounterInstrumentKind, number.Int64Kind)
accum := export.NewAccumulation(&desc, attribute.EmptySet(), resource.Empty(), aggregatortest.NoopAggregator{}) accum := export.NewAccumulation(&desc, attribute.EmptySet(), resource.Empty(), aggregatortest.NoopAggregator{})
b.StartCollection() b.StartCollection()
@ -371,7 +372,7 @@ func TestStatefulNoMemoryCumulative(t *testing.T) {
res := resource.NewSchemaless(attribute.String("R", "V")) res := resource.NewSchemaless(attribute.String("R", "V"))
ekindSel := export.CumulativeExportKindSelector() ekindSel := export.CumulativeExportKindSelector()
desc := metric.NewDescriptor("inst.sum", metric.CounterInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("inst.sum", sdkapi.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))
@ -405,7 +406,7 @@ func TestStatefulNoMemoryDelta(t *testing.T) {
res := resource.NewSchemaless(attribute.String("R", "V")) res := resource.NewSchemaless(attribute.String("R", "V"))
ekindSel := export.DeltaExportKindSelector() ekindSel := export.DeltaExportKindSelector()
desc := metric.NewDescriptor("inst.sum", metric.SumObserverInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("inst.sum", sdkapi.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))
@ -442,7 +443,7 @@ func TestMultiObserverSum(t *testing.T) {
} { } {
res := resource.NewSchemaless(attribute.String("R", "V")) res := resource.NewSchemaless(attribute.String("R", "V"))
desc := metric.NewDescriptor("observe.sum", metric.SumObserverInstrumentKind, number.Int64Kind) desc := metric.NewDescriptor("observe.sum", sdkapi.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))

View File

@ -16,6 +16,7 @@ package simple // import "go.opentelemetry.io/otel/sdk/metric/selector/simple"
import ( import (
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/sdkapi"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregator/exact" "go.opentelemetry.io/otel/sdk/metric/aggregator/exact"
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram" "go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
@ -79,9 +80,9 @@ func lastValueAggs(aggPtrs []*export.Aggregator) {
func (selectorInexpensive) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) { func (selectorInexpensive) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) {
switch descriptor.InstrumentKind() { switch descriptor.InstrumentKind() {
case metric.ValueObserverInstrumentKind: case sdkapi.ValueObserverInstrumentKind:
lastValueAggs(aggPtrs) lastValueAggs(aggPtrs)
case metric.ValueRecorderInstrumentKind: case sdkapi.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]
@ -93,9 +94,9 @@ func (selectorInexpensive) AggregatorFor(descriptor *metric.Descriptor, aggPtrs
func (selectorExact) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) { func (selectorExact) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) {
switch descriptor.InstrumentKind() { switch descriptor.InstrumentKind() {
case metric.ValueObserverInstrumentKind: case sdkapi.ValueObserverInstrumentKind:
lastValueAggs(aggPtrs) lastValueAggs(aggPtrs)
case metric.ValueRecorderInstrumentKind: case sdkapi.ValueRecorderInstrumentKind:
aggs := exact.New(len(aggPtrs)) aggs := exact.New(len(aggPtrs))
for i := range aggPtrs { for i := range aggPtrs {
*aggPtrs[i] = &aggs[i] *aggPtrs[i] = &aggs[i]
@ -107,9 +108,9 @@ func (selectorExact) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*ex
func (s selectorHistogram) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) { func (s selectorHistogram) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) {
switch descriptor.InstrumentKind() { switch descriptor.InstrumentKind() {
case metric.ValueObserverInstrumentKind: case sdkapi.ValueObserverInstrumentKind:
lastValueAggs(aggPtrs) lastValueAggs(aggPtrs)
case metric.ValueRecorderInstrumentKind: case sdkapi.ValueRecorderInstrumentKind:
aggs := histogram.New(len(aggPtrs), descriptor, s.options...) aggs := histogram.New(len(aggPtrs), descriptor, s.options...)
for i := range aggPtrs { for i := range aggPtrs {
*aggPtrs[i] = &aggs[i] *aggPtrs[i] = &aggs[i]

View File

@ -21,6 +21,7 @@ import (
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
export "go.opentelemetry.io/otel/sdk/export/metric" export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregator/exact" "go.opentelemetry.io/otel/sdk/metric/aggregator/exact"
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram" "go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
@ -31,12 +32,12 @@ import (
) )
var ( var (
testCounterDesc = metric.NewDescriptor("counter", metric.CounterInstrumentKind, number.Int64Kind) testCounterDesc = metric.NewDescriptor("counter", sdkapi.CounterInstrumentKind, number.Int64Kind)
testUpDownCounterDesc = metric.NewDescriptor("updowncounter", metric.UpDownCounterInstrumentKind, number.Int64Kind) testUpDownCounterDesc = metric.NewDescriptor("updowncounter", sdkapi.UpDownCounterInstrumentKind, number.Int64Kind)
testSumObserverDesc = metric.NewDescriptor("sumobserver", metric.SumObserverInstrumentKind, number.Int64Kind) testSumObserverDesc = metric.NewDescriptor("sumobserver", sdkapi.SumObserverInstrumentKind, number.Int64Kind)
testUpDownSumObserverDesc = metric.NewDescriptor("updownsumobserver", metric.UpDownSumObserverInstrumentKind, number.Int64Kind) testUpDownSumObserverDesc = metric.NewDescriptor("updownsumobserver", sdkapi.UpDownSumObserverInstrumentKind, number.Int64Kind)
testValueRecorderDesc = metric.NewDescriptor("valuerecorder", metric.ValueRecorderInstrumentKind, number.Int64Kind) testValueRecorderDesc = metric.NewDescriptor("valuerecorder", sdkapi.ValueRecorderInstrumentKind, number.Int64Kind)
testValueObserverDesc = metric.NewDescriptor("valueobserver", metric.ValueObserverInstrumentKind, number.Int64Kind) testValueObserverDesc = metric.NewDescriptor("valueobserver", sdkapi.ValueObserverInstrumentKind, number.Int64Kind)
) )
func oneAgg(sel export.AggregatorSelector, desc *metric.Descriptor) export.Aggregator { func oneAgg(sel export.AggregatorSelector, desc *metric.Descriptor) export.Aggregator {

View File

@ -34,6 +34,7 @@ import (
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number" "go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
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/processor/processortest" "go.opentelemetry.io/otel/sdk/metric/processor/processortest"
@ -265,13 +266,13 @@ func (f *testFixture) Process(accumulation export.Accumulation) error {
agg := accumulation.Aggregator() agg := accumulation.Aggregator()
switch accumulation.Descriptor().InstrumentKind() { switch accumulation.Descriptor().InstrumentKind() {
case metric.CounterInstrumentKind: case sdkapi.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 metric.ValueRecorderInstrumentKind: case sdkapi.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)