Skip to content

Commit

Permalink
Move InstrumentKind into the new metric/sdkapi package (open-telemetr…
Browse files Browse the repository at this point in the history
…y#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 <[email protected]>
  • Loading branch information
jmacd and MrAlias authored Aug 11, 2021
1 parent 1cb5cdc commit df384a9
Show file tree
Hide file tree
Showing 30 changed files with 340 additions and 268 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Changed

- Metric SDK/API implementation type `InstrumentKind` moves into `sdkapi` sub-package. (#2091)

### Deprecated

- The `go.opentelemetry.io/otel/bridge/opencensus/utils` package is deprecated.
Expand Down Expand Up @@ -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)
- 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

Expand Down
11 changes: 6 additions & 5 deletions bridge/opencensus/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
"go.opentelemetry.io/otel/metric/unit"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
Expand Down Expand Up @@ -133,21 +134,21 @@ func convertResource(res *ocresource.Resource) *resource.Resource {
func convertDescriptor(ocDescriptor metricdata.Descriptor) (metric.Descriptor, error) {
var (
nkind number.Kind
ikind metric.InstrumentKind
ikind sdkapi.InstrumentKind
)
switch ocDescriptor.Type {
case metricdata.TypeGaugeInt64:
nkind = number.Int64Kind
ikind = metric.ValueObserverInstrumentKind
ikind = sdkapi.ValueObserverInstrumentKind
case metricdata.TypeGaugeFloat64:
nkind = number.Float64Kind
ikind = metric.ValueObserverInstrumentKind
ikind = sdkapi.ValueObserverInstrumentKind
case metricdata.TypeCumulativeInt64:
nkind = number.Int64Kind
ikind = metric.SumObserverInstrumentKind
ikind = sdkapi.SumObserverInstrumentKind
case metricdata.TypeCumulativeFloat64:
nkind = number.Float64Kind
ikind = metric.SumObserverInstrumentKind
ikind = sdkapi.SumObserverInstrumentKind
default:
// Includes TypeGaugeDistribution, TypeCumulativeDistribution, TypeSummary
return metric.Descriptor{}, fmt.Errorf("%w; descriptor type: %v", errConversion, ocDescriptor.Type)
Expand Down
13 changes: 7 additions & 6 deletions bridge/opencensus/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
"go.opentelemetry.io/otel/metric/unit"
export "go.opentelemetry.io/otel/sdk/export/metric"
exportmetric "go.opentelemetry.io/otel/sdk/export/metric"
Expand Down Expand Up @@ -70,7 +71,7 @@ func TestExportMetrics(t *testing.T) {
now := time.Now()
basicDesc := metric.NewDescriptor(
"",
metric.ValueObserverInstrumentKind,
sdkapi.ValueObserverInstrumentKind,
number.Int64Kind,
metric.WithInstrumentationName("OpenCensus Bridge"),
)
Expand Down Expand Up @@ -384,7 +385,7 @@ func TestConvertDescriptor(t *testing.T) {
desc: "empty descriptor",
expected: metric.NewDescriptor(
"",
metric.ValueObserverInstrumentKind,
sdkapi.ValueObserverInstrumentKind,
number.Int64Kind,
metric.WithInstrumentationName("OpenCensus Bridge"),
),
Expand All @@ -399,7 +400,7 @@ func TestConvertDescriptor(t *testing.T) {
},
expected: metric.NewDescriptor(
"foo",
metric.ValueObserverInstrumentKind,
sdkapi.ValueObserverInstrumentKind,
number.Int64Kind,
metric.WithInstrumentationName("OpenCensus Bridge"),
metric.WithDescription("bar"),
Expand All @@ -416,7 +417,7 @@ func TestConvertDescriptor(t *testing.T) {
},
expected: metric.NewDescriptor(
"foo",
metric.ValueObserverInstrumentKind,
sdkapi.ValueObserverInstrumentKind,
number.Float64Kind,
metric.WithInstrumentationName("OpenCensus Bridge"),
metric.WithDescription("bar"),
Expand All @@ -433,7 +434,7 @@ func TestConvertDescriptor(t *testing.T) {
},
expected: metric.NewDescriptor(
"foo",
metric.SumObserverInstrumentKind,
sdkapi.SumObserverInstrumentKind,
number.Int64Kind,
metric.WithInstrumentationName("OpenCensus Bridge"),
metric.WithDescription("bar"),
Expand All @@ -450,7 +451,7 @@ func TestConvertDescriptor(t *testing.T) {
},
expected: metric.NewDescriptor(
"foo",
metric.SumObserverInstrumentKind,
sdkapi.SumObserverInstrumentKind,
number.Float64Kind,
metric.WithInstrumentationName("OpenCensus Bridge"),
metric.WithDescription("bar"),
Expand Down
43 changes: 22 additions & 21 deletions exporters/otlp/otlpmetric/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/resource"
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
Expand Down Expand Up @@ -98,7 +99,7 @@ func (m *checkpointSet) ForEach(_ metricsdk.ExportKindSelector, fn func(metricsd

type record struct {
name string
iKind metric.InstrumentKind
iKind sdkapi.InstrumentKind
nKind number.Kind
resource *resource.Resource
opts []metric.InstrumentOption
Expand Down Expand Up @@ -184,15 +185,15 @@ func TestNoGroupingExport(t *testing.T) {
[]record{
{
"int64-count",
metric.CounterInstrumentKind,
sdkapi.CounterInstrumentKind,
number.Int64Kind,
nil,
nil,
append(baseKeyValues, cpuKey.Int(1)),
},
{
"int64-count",
metric.CounterInstrumentKind,
sdkapi.CounterInstrumentKind,
number.Int64Kind,
nil,
nil,
Expand Down Expand Up @@ -239,7 +240,7 @@ func TestNoGroupingExport(t *testing.T) {
func TestValuerecorderMetricGroupingExport(t *testing.T) {
r := record{
"valuerecorder",
metric.ValueRecorderInstrumentKind,
sdkapi.ValueRecorderInstrumentKind,
number.Int64Kind,
nil,
nil,
Expand Down Expand Up @@ -290,7 +291,7 @@ func TestValuerecorderMetricGroupingExport(t *testing.T) {
func TestCountInt64MetricGroupingExport(t *testing.T) {
r := record{
"int64-count",
metric.CounterInstrumentKind,
sdkapi.CounterInstrumentKind,
number.Int64Kind,
nil,
nil,
Expand Down Expand Up @@ -340,7 +341,7 @@ func TestCountInt64MetricGroupingExport(t *testing.T) {
func TestCountFloat64MetricGroupingExport(t *testing.T) {
r := record{
"float64-count",
metric.CounterInstrumentKind,
sdkapi.CounterInstrumentKind,
number.Float64Kind,
nil,
nil,
Expand Down Expand Up @@ -394,31 +395,31 @@ func TestResourceMetricGroupingExport(t *testing.T) {
[]record{
{
"int64-count",
metric.CounterInstrumentKind,
sdkapi.CounterInstrumentKind,
number.Int64Kind,
testInstA,
nil,
append(baseKeyValues, cpuKey.Int(1)),
},
{
"int64-count",
metric.CounterInstrumentKind,
sdkapi.CounterInstrumentKind,
number.Int64Kind,
testInstA,
nil,
append(baseKeyValues, cpuKey.Int(1)),
},
{
"int64-count",
metric.CounterInstrumentKind,
sdkapi.CounterInstrumentKind,
number.Int64Kind,
testInstA,
nil,
append(baseKeyValues, cpuKey.Int(2)),
},
{
"int64-count",
metric.CounterInstrumentKind,
sdkapi.CounterInstrumentKind,
number.Int64Kind,
testInstB,
nil,
Expand Down Expand Up @@ -512,47 +513,47 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
[]record{
{
"int64-count",
metric.CounterInstrumentKind,
sdkapi.CounterInstrumentKind,
number.Int64Kind,
testInstA,
countingLib1,
append(baseKeyValues, cpuKey.Int(1)),
},
{
"int64-count",
metric.CounterInstrumentKind,
sdkapi.CounterInstrumentKind,
number.Int64Kind,
testInstA,
countingLib2,
append(baseKeyValues, cpuKey.Int(1)),
},
{
"int64-count",
metric.CounterInstrumentKind,
sdkapi.CounterInstrumentKind,
number.Int64Kind,
testInstA,
countingLib1,
append(baseKeyValues, cpuKey.Int(1)),
},
{
"int64-count",
metric.CounterInstrumentKind,
sdkapi.CounterInstrumentKind,
number.Int64Kind,
testInstA,
countingLib1,
append(baseKeyValues, cpuKey.Int(2)),
},
{
"int64-count",
metric.CounterInstrumentKind,
sdkapi.CounterInstrumentKind,
number.Int64Kind,
testInstA,
summingLib,
append(baseKeyValues, cpuKey.Int(1)),
},
{
"int64-count",
metric.CounterInstrumentKind,
sdkapi.CounterInstrumentKind,
number.Int64Kind,
testInstB,
countingLib1,
Expand Down Expand Up @@ -688,16 +689,16 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
func TestStatelessExportKind(t *testing.T) {
type testcase struct {
name string
instrumentKind metric.InstrumentKind
instrumentKind sdkapi.InstrumentKind
aggTemporality metricpb.AggregationTemporality
monotonic bool
}

for _, k := range []testcase{
{"counter", metric.CounterInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, true},
{"updowncounter", metric.UpDownCounterInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, false},
{"sumobserver", metric.SumObserverInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE, true},
{"updownsumobserver", metric.UpDownSumObserverInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE, false},
{"counter", sdkapi.CounterInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, true},
{"updowncounter", sdkapi.UpDownCounterInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA, false},
{"sumobserver", sdkapi.SumObserverInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE, true},
{"updownsumobserver", sdkapi.UpDownSumObserverInstrumentKind, metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE, false},
} {
t.Run(k.name, func(t *testing.T) {
runMetricExportTests(
Expand Down
19 changes: 10 additions & 9 deletions exporters/otlp/otlpmetric/internal/metrictransform/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
arrAgg "go.opentelemetry.io/otel/sdk/metric/aggregator/exact"
Expand Down Expand Up @@ -122,7 +123,7 @@ func TestMinMaxSumCountValue(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"))
mmscs := minmaxsumcount.New(2, &metric.Descriptor{})
mmsc, ckpt := &mmscs[0], &mmscs[1]
Expand Down Expand Up @@ -178,7 +179,7 @@ func TestMinMaxSumCountPropagatesErrors(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"))
sums := sumAgg.New(2)
s, ckpt := &sums[0], &sums[1]
Expand Down Expand Up @@ -218,7 +219,7 @@ func TestSumIntDataPoints(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"))
sums := sumAgg.New(2)
s, ckpt := &sums[0], &sums[1]
Expand Down Expand Up @@ -256,7 +257,7 @@ func TestSumFloatDataPoints(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"))
lvs := lvAgg.New(2)
lv, ckpt := &lvs[0], &lvs[1]
Expand Down Expand Up @@ -291,7 +292,7 @@ func TestLastValueIntDataPoints(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"))
arrs := arrAgg.New(2)
e, ckpt := &arrs[0], &arrs[1]
Expand Down Expand Up @@ -326,7 +327,7 @@ func TestExactIntDataPoints(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"))
arrs := arrAgg.New(2)
e, ckpt := &arrs[0], &arrs[1]
Expand Down Expand Up @@ -360,7 +361,7 @@ func TestExactFloatDataPoints(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()
s := &sumAgg.New(1)[0]
record := export.NewRecord(&desc, &labels, nil, s, intervalStart, intervalEnd)
Expand Down Expand Up @@ -445,7 +446,7 @@ var _ aggregation.MinMaxSumCount = &testErrMinMaxSumCount{}

func TestRecordAggregatorIncompatibleErrors(t *testing.T) {
makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) {
desc := metric.NewDescriptor("things", metric.CounterInstrumentKind, number.Int64Kind)
desc := metric.NewDescriptor("things", sdkapi.CounterInstrumentKind, number.Int64Kind)
labels := attribute.NewSet()
res := resource.Empty()
test := &testAgg{
Expand Down Expand Up @@ -482,7 +483,7 @@ func TestRecordAggregatorIncompatibleErrors(t *testing.T) {

func TestRecordAggregatorUnexpectedErrors(t *testing.T) {
makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) {
desc := metric.NewDescriptor("things", metric.CounterInstrumentKind, number.Int64Kind)
desc := metric.NewDescriptor("things", sdkapi.CounterInstrumentKind, number.Int64Kind)
labels := attribute.NewSet()
res := resource.Empty()
return Record(export.CumulativeExportKindSelector(), export.NewRecord(&desc, &labels, res, agg, intervalStart, intervalEnd))
Expand Down
3 changes: 2 additions & 1 deletion exporters/otlp/otlpmetric/internal/otlpmetrictest/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number"
"go.opentelemetry.io/otel/metric/sdkapi"
exportmetric "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregator/sum"
"go.opentelemetry.io/otel/sdk/resource"
Expand Down Expand Up @@ -59,7 +60,7 @@ var _ exportmetric.CheckpointSet = OneRecordCheckpointSet{}
func (OneRecordCheckpointSet) ForEach(kindSelector exportmetric.ExportKindSelector, recordFunc func(exportmetric.Record) error) error {
desc := metric.NewDescriptor(
"foo",
metric.CounterInstrumentKind,
sdkapi.CounterInstrumentKind,
number.Int64Kind,
)
res := resource.NewSchemaless(attribute.String("a", "b"))
Expand Down
Loading

0 comments on commit df384a9

Please sign in to comment.