Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Resources in the SDK #552

Merged
merged 16 commits into from
Mar 20, 2020
Merged
3 changes: 1 addition & 2 deletions exporters/metric/dogstatsd/dogstatsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
export "go.opentelemetry.io/otel/sdk/export/metric"
sdk "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregator/sum"
"go.opentelemetry.io/otel/sdk/resource"
)

// TestDogstatsLabels that labels are formatted in the correct style,
Expand All @@ -45,7 +44,7 @@ func TestDogstatsLabels(t *testing.T) {
ctx := context.Background()
checkpointSet := test.NewCheckpointSet(encoder)

desc := export.NewDescriptor("test.name", export.CounterKind, nil, "", "", core.Int64NumberKind, resource.Resource{})
desc := export.NewDescriptor("test.name", export.CounterKind, core.Int64NumberKind)
cagg := sum.New()
_ = cagg.Update(ctx, core.NewInt64Number(123), desc)
cagg.Checkpoint(ctx, desc)
Expand Down
15 changes: 5 additions & 10 deletions exporters/metric/internal/statsd/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"go.opentelemetry.io/otel/exporters/metric/test"
export "go.opentelemetry.io/otel/sdk/export/metric"
sdk "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
)

// withTagsAdapter tests a dogstatsd-style statsd exporter.
Expand Down Expand Up @@ -124,14 +123,10 @@ timer.B.D:%s|ms
}

checkpointSet := test.NewCheckpointSet(sdk.NewDefaultLabelEncoder())
cdesc := export.NewDescriptor(
"counter", export.CounterKind, nil, "", "", nkind, resource.Resource{})
gdesc := export.NewDescriptor(
"observer", export.ObserverKind, nil, "", "", nkind, resource.Resource{})
mdesc := export.NewDescriptor(
"measure", export.MeasureKind, nil, "", "", nkind, resource.Resource{})
tdesc := export.NewDescriptor(
"timer", export.MeasureKind, nil, "", unit.Milliseconds, nkind, resource.Resource{})
cdesc := export.NewDescriptor("counter", export.CounterKind, nkind)
gdesc := export.NewDescriptor("observer", export.ObserverKind, nkind)
mdesc := export.NewDescriptor("measure", export.MeasureKind, nkind)
tdesc := export.NewDescriptor("timer", export.MeasureKind, nkind, export.WithUnit(unit.Milliseconds))

labels := []core.KeyValue{
key.New("A").String("B"),
Expand Down Expand Up @@ -286,7 +281,7 @@ func TestPacketSplit(t *testing.T) {
}

checkpointSet := test.NewCheckpointSet(adapter.LabelEncoder)
desc := export.NewDescriptor("counter", export.CounterKind, nil, "", "", core.Int64NumberKind, resource.Resource{})
desc := export.NewDescriptor("counter", export.CounterKind, core.Int64NumberKind)

var expected []string

Expand Down
10 changes: 3 additions & 7 deletions exporters/metric/prometheus/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"go.opentelemetry.io/otel/exporters/metric/test"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
)

func TestPrometheusExporter(t *testing.T) {
Expand All @@ -30,12 +29,9 @@ func TestPrometheusExporter(t *testing.T) {
var expected []string
checkpointSet := test.NewCheckpointSet(metric.NewDefaultLabelEncoder())

counter := export.NewDescriptor(
"counter", export.CounterKind, nil, "", "", core.Float64NumberKind, resource.Resource{})
lastValue := export.NewDescriptor(
"lastvalue", export.ObserverKind, nil, "", "", core.Float64NumberKind, resource.Resource{})
measure := export.NewDescriptor(
"measure", export.MeasureKind, nil, "", "", core.Float64NumberKind, resource.Resource{})
counter := export.NewDescriptor("counter", export.CounterKind, core.Float64NumberKind)
lastValue := export.NewDescriptor("lastvalue", export.ObserverKind, core.Float64NumberKind)
measure := export.NewDescriptor("measure", export.MeasureKind, core.Float64NumberKind)

labels := []core.KeyValue{
key.New("A").String("B"),
Expand Down
17 changes: 8 additions & 9 deletions exporters/metric/stdout/stdout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount"
"go.opentelemetry.io/otel/sdk/metric/aggregator/sum"
aggtest "go.opentelemetry.io/otel/sdk/metric/aggregator/test"
"go.opentelemetry.io/otel/sdk/resource"
)

type testFixture struct {
Expand Down Expand Up @@ -83,7 +82,7 @@ func TestStdoutTimestamp(t *testing.T) {
checkpointSet := test.NewCheckpointSet(sdk.NewDefaultLabelEncoder())

ctx := context.Background()
desc := export.NewDescriptor("test.name", export.ObserverKind, nil, "", "", core.Int64NumberKind, resource.Resource{})
desc := export.NewDescriptor("test.name", export.ObserverKind, core.Int64NumberKind)
lvagg := lastvalue.New()
aggtest.CheckedUpdate(t, lvagg, core.NewInt64Number(321), desc)
lvagg.Checkpoint(ctx, desc)
Expand Down Expand Up @@ -128,7 +127,7 @@ func TestStdoutCounterFormat(t *testing.T) {

checkpointSet := test.NewCheckpointSet(sdk.NewDefaultLabelEncoder())

desc := export.NewDescriptor("test.name", export.CounterKind, nil, "", "", core.Int64NumberKind, resource.Resource{})
desc := export.NewDescriptor("test.name", export.CounterKind, core.Int64NumberKind)
cagg := sum.New()
aggtest.CheckedUpdate(fix.t, cagg, core.NewInt64Number(123), desc)
cagg.Checkpoint(fix.ctx, desc)
Expand All @@ -145,7 +144,7 @@ func TestStdoutLastValueFormat(t *testing.T) {

checkpointSet := test.NewCheckpointSet(sdk.NewDefaultLabelEncoder())

desc := export.NewDescriptor("test.name", export.ObserverKind, nil, "", "", core.Float64NumberKind, resource.Resource{})
desc := export.NewDescriptor("test.name", export.ObserverKind, core.Float64NumberKind)
lvagg := lastvalue.New()
aggtest.CheckedUpdate(fix.t, lvagg, core.NewFloat64Number(123.456), desc)
lvagg.Checkpoint(fix.ctx, desc)
Expand All @@ -162,7 +161,7 @@ func TestStdoutMinMaxSumCount(t *testing.T) {

checkpointSet := test.NewCheckpointSet(sdk.NewDefaultLabelEncoder())

desc := export.NewDescriptor("test.name", export.MeasureKind, nil, "", "", core.Float64NumberKind, resource.Resource{})
desc := export.NewDescriptor("test.name", export.MeasureKind, core.Float64NumberKind)
magg := minmaxsumcount.New(desc)
aggtest.CheckedUpdate(fix.t, magg, core.NewFloat64Number(123.456), desc)
aggtest.CheckedUpdate(fix.t, magg, core.NewFloat64Number(876.543), desc)
Expand All @@ -182,7 +181,7 @@ func TestStdoutMeasureFormat(t *testing.T) {

checkpointSet := test.NewCheckpointSet(sdk.NewDefaultLabelEncoder())

desc := export.NewDescriptor("test.name", export.MeasureKind, nil, "", "", core.Float64NumberKind, resource.Resource{})
desc := export.NewDescriptor("test.name", export.MeasureKind, core.Float64NumberKind)
magg := array.New()

for i := 0; i < 1000; i++ {
Expand Down Expand Up @@ -223,7 +222,7 @@ func TestStdoutMeasureFormat(t *testing.T) {
}

func TestStdoutEmptyDataSet(t *testing.T) {
desc := export.NewDescriptor("test.name", export.MeasureKind, nil, "", "", core.Float64NumberKind, resource.Resource{})
desc := export.NewDescriptor("test.name", export.MeasureKind, core.Float64NumberKind)
for name, tc := range map[string]export.Aggregator{
"ddsketch": ddsketch.New(ddsketch.NewDefaultConfig(), desc),
"minmaxsumcount": minmaxsumcount.New(desc),
Expand Down Expand Up @@ -253,7 +252,7 @@ func TestStdoutLastValueNotSet(t *testing.T) {

checkpointSet := test.NewCheckpointSet(sdk.NewDefaultLabelEncoder())

desc := export.NewDescriptor("test.name", export.ObserverKind, nil, "", "", core.Float64NumberKind, resource.Resource{})
desc := export.NewDescriptor("test.name", export.ObserverKind, core.Float64NumberKind)
lvagg := lastvalue.New()
lvagg.Checkpoint(fix.ctx, desc)

Expand All @@ -271,7 +270,7 @@ func TestStdoutCounterWithUnspecifiedKeys(t *testing.T) {

keys := []core.Key{key.New("C"), key.New("D")}

desc := export.NewDescriptor("test.name", export.CounterKind, keys, "", "", core.Int64NumberKind, resource.Resource{})
desc := export.NewDescriptor("test.name", export.CounterKind, core.Int64NumberKind, export.WithKeys(keys...))
cagg := sum.New()
aggtest.CheckedUpdate(fix.t, cagg, core.NewInt64Number(10), desc)
cagg.Checkpoint(fix.ctx, desc)
Expand Down
21 changes: 15 additions & 6 deletions exporters/otlp/internal/transform/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
"go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount"
sumAgg "go.opentelemetry.io/otel/sdk/metric/aggregator/sum"
"go.opentelemetry.io/otel/sdk/resource"
)

func TestStringKeyValues(t *testing.T) {
Expand Down Expand Up @@ -145,7 +144,12 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) {
}
mmsc.Checkpoint(ctx, &metricsdk.Descriptor{})
for _, test := range tests {
desc := metricsdk.NewDescriptor(test.name, test.metricKind, test.keys, test.description, test.unit, test.numberKind, resource.Resource{})
opts := []metricsdk.DescriptorOption{
metricsdk.WithUnit(test.unit),
metricsdk.WithDescription(test.description),
metricsdk.WithKeys(test.keys...),
}
desc := metricsdk.NewDescriptor(test.name, test.metricKind, test.numberKind, opts...)
labels := metricsdk.NewLabels(test.labels, "", nil)
got, err := minMaxSumCount(desc, labels, mmsc)
if assert.NoError(t, err) {
Expand All @@ -155,7 +159,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) {
}

func TestMinMaxSumCountDatapoints(t *testing.T) {
desc := metricsdk.NewDescriptor("", metricsdk.MeasureKind, []core.Key{}, "", unit.Dimensionless, core.Int64NumberKind, resource.Resource{})
desc := metricsdk.NewDescriptor("", metricsdk.MeasureKind, core.Int64NumberKind)
labels := metricsdk.NewLabels([]core.KeyValue{}, "", nil)
mmsc := minmaxsumcount.New(desc)
assert.NoError(t, mmsc.Update(context.Background(), 1, desc))
Expand Down Expand Up @@ -242,7 +246,12 @@ func TestSumMetricDescriptor(t *testing.T) {
}

for _, test := range tests {
desc := metricsdk.NewDescriptor(test.name, test.metricKind, test.keys, test.description, test.unit, test.numberKind, resource.Resource{})
opts := []metricsdk.DescriptorOption{
metricsdk.WithUnit(test.unit),
metricsdk.WithDescription(test.description),
metricsdk.WithKeys(test.keys...),
}
desc := metricsdk.NewDescriptor(test.name, test.metricKind, test.numberKind, opts...)
labels := metricsdk.NewLabels(test.labels, "", nil)
got, err := sum(desc, labels, sumAgg.New())
if assert.NoError(t, err) {
Expand All @@ -252,7 +261,7 @@ func TestSumMetricDescriptor(t *testing.T) {
}

func TestSumInt64DataPoints(t *testing.T) {
desc := metricsdk.NewDescriptor("", metricsdk.MeasureKind, []core.Key{}, "", unit.Dimensionless, core.Int64NumberKind, resource.Resource{})
desc := metricsdk.NewDescriptor("", metricsdk.CounterKind, core.Int64NumberKind)
labels := metricsdk.NewLabels([]core.KeyValue{}, "", nil)
s := sumAgg.New()
assert.NoError(t, s.Update(context.Background(), core.Number(1), desc))
Expand All @@ -266,7 +275,7 @@ func TestSumInt64DataPoints(t *testing.T) {
}

func TestSumFloat64Datapoints(t *testing.T) {
desc := metricsdk.NewDescriptor("", metricsdk.MeasureKind, []core.Key{}, "", unit.Dimensionless, core.Float64NumberKind, resource.Resource{})
desc := metricsdk.NewDescriptor("", metricsdk.CounterKind, core.Float64NumberKind)
labels := metricsdk.NewLabels([]core.KeyValue{}, "", nil)
s := sumAgg.New()
assert.NoError(t, s.Update(context.Background(), core.NewFloat64Number(1), desc))
Expand Down
23 changes: 2 additions & 21 deletions sdk/export/metric/aggregator/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
"go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue"
"go.opentelemetry.io/otel/sdk/metric/aggregator/sum"
"go.opentelemetry.io/otel/sdk/resource"
)

func TestInconsistentMergeErr(t *testing.T) {
Expand Down Expand Up @@ -73,16 +72,7 @@ func TestRangeTest(t *testing.T) {
// Only Counters implement a range test.
for _, nkind := range []core.NumberKind{core.Float64NumberKind, core.Int64NumberKind} {
t.Run(nkind.String(), func(t *testing.T) {
desc := export.NewDescriptor(
"name",
export.CounterKind,
nil,
"",
"",
nkind,
resource.Resource{},
)
testRangeNegative(t, desc)
testRangeNegative(t, export.NewDescriptor("name", export.CounterKind, nkind))
})
}
}
Expand All @@ -95,16 +85,7 @@ func TestNaNTest(t *testing.T) {
export.MeasureKind,
export.ObserverKind,
} {
desc := export.NewDescriptor(
"name",
mkind,
nil,
"",
"",
nkind,
resource.Resource{},
)
testRangeNaN(t, desc)
testRangeNaN(t, export.NewDescriptor("name", mkind, nkind))
}
})
}
Expand Down
Loading