2021-03-11 19:49:20 +02:00
|
|
|
// 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 opencensus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"go.opencensus.io/metric/metricdata"
|
|
|
|
ocresource "go.opencensus.io/resource"
|
|
|
|
|
2021-11-13 18:35:04 +02:00
|
|
|
"go.opentelemetry.io/otel"
|
2021-03-11 19:49:20 +02:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
2022-03-02 17:50:29 +02:00
|
|
|
"go.opentelemetry.io/otel/metric/instrument"
|
2021-05-12 20:51:26 +02:00
|
|
|
"go.opentelemetry.io/otel/metric/unit"
|
2021-09-27 17:51:47 +02:00
|
|
|
"go.opentelemetry.io/otel/sdk/instrumentation"
|
|
|
|
"go.opentelemetry.io/otel/sdk/metric/controller/controllertest"
|
2021-12-13 22:13:03 +02:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/export"
|
|
|
|
"go.opentelemetry.io/otel/sdk/metric/export/aggregation"
|
2022-03-02 17:50:29 +02:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/metrictest"
|
|
|
|
"go.opentelemetry.io/otel/sdk/metric/number"
|
|
|
|
"go.opentelemetry.io/otel/sdk/metric/sdkapi"
|
2021-03-11 19:49:20 +02:00
|
|
|
"go.opentelemetry.io/otel/sdk/resource"
|
|
|
|
)
|
|
|
|
|
|
|
|
type fakeExporter struct {
|
|
|
|
export.Exporter
|
2021-08-13 00:44:58 +02:00
|
|
|
records []export.Record
|
|
|
|
resource *resource.Resource
|
|
|
|
err error
|
2021-03-11 19:49:20 +02:00
|
|
|
}
|
|
|
|
|
2021-12-13 22:13:03 +02:00
|
|
|
func (f *fakeExporter) Export(ctx context.Context, res *resource.Resource, ilr export.InstrumentationLibraryReader) error {
|
2021-10-15 20:18:36 +02:00
|
|
|
return controllertest.ReadAll(ilr, aggregation.StatelessTemporalitySelector(),
|
2021-12-13 22:13:03 +02:00
|
|
|
func(_ instrumentation.Library, record export.Record) error {
|
2021-09-27 17:51:47 +02:00
|
|
|
f.resource = res
|
|
|
|
f.records = append(f.records, record)
|
|
|
|
return f.err
|
|
|
|
})
|
2021-03-11 19:49:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type fakeErrorHandler struct {
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fakeErrorHandler) Handle(err error) {
|
|
|
|
f.err = err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fakeErrorHandler) matches(err error) error {
|
|
|
|
// make sure err is cleared for the next test
|
|
|
|
defer func() { f.err = nil }()
|
|
|
|
if !errors.Is(f.err, err) {
|
|
|
|
return fmt.Errorf("err(%v), want err(%v)", f.err, err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestExportMetrics(t *testing.T) {
|
|
|
|
now := time.Now()
|
2021-09-27 17:51:47 +02:00
|
|
|
basicDesc := metrictest.NewDescriptor(
|
2021-03-11 19:49:20 +02:00
|
|
|
"",
|
2021-09-01 22:38:37 +02:00
|
|
|
sdkapi.GaugeObserverInstrumentKind,
|
2021-03-11 19:49:20 +02:00
|
|
|
number.Int64Kind,
|
|
|
|
)
|
|
|
|
fakeErrorHandler := &fakeErrorHandler{}
|
|
|
|
otel.SetErrorHandler(fakeErrorHandler)
|
|
|
|
for _, tc := range []struct {
|
|
|
|
desc string
|
|
|
|
input []*metricdata.Metric
|
|
|
|
exportErr error
|
|
|
|
expected []export.Record
|
2021-08-13 00:44:58 +02:00
|
|
|
expectedResource *resource.Resource
|
2021-03-11 19:49:20 +02:00
|
|
|
expectedHandledError error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "no metrics",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "metric without points is dropped",
|
|
|
|
input: []*metricdata.Metric{
|
|
|
|
{
|
|
|
|
TimeSeries: []*metricdata.TimeSeries{
|
|
|
|
{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "descriptor conversion error",
|
|
|
|
input: []*metricdata.Metric{
|
|
|
|
// TypeGaugeDistribution isn't supported
|
|
|
|
{Descriptor: metricdata.Descriptor{Type: metricdata.TypeGaugeDistribution}},
|
|
|
|
},
|
|
|
|
expectedHandledError: errConversion,
|
|
|
|
},
|
|
|
|
{
|
2022-04-18 16:31:31 +02:00
|
|
|
desc: "attrs conversion error",
|
2021-03-11 19:49:20 +02:00
|
|
|
input: []*metricdata.Metric{
|
|
|
|
{
|
2022-04-18 16:31:31 +02:00
|
|
|
// No descriptor with attribute keys.
|
2021-03-11 19:49:20 +02:00
|
|
|
TimeSeries: []*metricdata.TimeSeries{
|
2022-04-18 16:31:31 +02:00
|
|
|
// 1 attribute value, which doens't exist in keys.
|
2021-03-11 19:49:20 +02:00
|
|
|
{
|
|
|
|
LabelValues: []metricdata.LabelValue{{Value: "foo", Present: true}},
|
|
|
|
Points: []metricdata.Point{
|
|
|
|
{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedHandledError: errConversion,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "unsupported summary point type",
|
|
|
|
input: []*metricdata.Metric{
|
|
|
|
{
|
|
|
|
TimeSeries: []*metricdata.TimeSeries{
|
|
|
|
{
|
|
|
|
Points: []metricdata.Point{
|
|
|
|
{Value: &metricdata.Summary{}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-11-15 20:05:14 +02:00
|
|
|
exportErr: errIncompatibleType,
|
2021-03-11 19:49:20 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "success",
|
|
|
|
input: []*metricdata.Metric{
|
|
|
|
{
|
2021-08-13 00:44:58 +02:00
|
|
|
Resource: &ocresource.Resource{
|
|
|
|
Labels: map[string]string{
|
|
|
|
"R1": "V1",
|
|
|
|
"R2": "V2",
|
|
|
|
},
|
|
|
|
},
|
2021-03-11 19:49:20 +02:00
|
|
|
TimeSeries: []*metricdata.TimeSeries{
|
|
|
|
{
|
|
|
|
StartTime: now,
|
|
|
|
Points: []metricdata.Point{
|
|
|
|
{Value: int64(123), Time: now},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-08-13 00:44:58 +02:00
|
|
|
expectedResource: resource.NewSchemaless(
|
|
|
|
attribute.String("R1", "V1"),
|
|
|
|
attribute.String("R2", "V2"),
|
|
|
|
),
|
2021-03-11 19:49:20 +02:00
|
|
|
expected: []export.Record{
|
|
|
|
export.NewRecord(
|
|
|
|
&basicDesc,
|
|
|
|
attribute.EmptySet(),
|
2021-11-15 20:05:14 +02:00
|
|
|
&ocRawAggregator{
|
|
|
|
value: number.NewInt64Number(123),
|
|
|
|
time: now,
|
2021-03-11 19:49:20 +02:00
|
|
|
},
|
|
|
|
now,
|
|
|
|
now,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "export error after success",
|
|
|
|
input: []*metricdata.Metric{
|
|
|
|
{
|
|
|
|
TimeSeries: []*metricdata.TimeSeries{
|
|
|
|
{
|
|
|
|
StartTime: now,
|
|
|
|
Points: []metricdata.Point{
|
|
|
|
{Value: int64(123), Time: now},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: []export.Record{
|
|
|
|
export.NewRecord(
|
|
|
|
&basicDesc,
|
|
|
|
attribute.EmptySet(),
|
2021-11-15 20:05:14 +02:00
|
|
|
&ocRawAggregator{
|
|
|
|
value: number.NewInt64Number(123),
|
|
|
|
time: now,
|
2021-03-11 19:49:20 +02:00
|
|
|
},
|
|
|
|
now,
|
|
|
|
now,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
exportErr: errors.New("failed to export"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "partial success sends correct metrics and drops incorrect metrics with handled err",
|
|
|
|
input: []*metricdata.Metric{
|
|
|
|
{
|
|
|
|
TimeSeries: []*metricdata.TimeSeries{
|
|
|
|
{
|
|
|
|
StartTime: now,
|
|
|
|
Points: []metricdata.Point{
|
|
|
|
{Value: int64(123), Time: now},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// TypeGaugeDistribution isn't supported
|
|
|
|
{Descriptor: metricdata.Descriptor{Type: metricdata.TypeGaugeDistribution}},
|
|
|
|
},
|
|
|
|
expected: []export.Record{
|
|
|
|
export.NewRecord(
|
|
|
|
&basicDesc,
|
|
|
|
attribute.EmptySet(),
|
2021-11-15 20:05:14 +02:00
|
|
|
&ocRawAggregator{
|
|
|
|
value: number.NewInt64Number(123),
|
|
|
|
time: now,
|
2021-03-11 19:49:20 +02:00
|
|
|
},
|
|
|
|
now,
|
|
|
|
now,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
expectedHandledError: errConversion,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(tc.desc, func(t *testing.T) {
|
|
|
|
fakeExporter := &fakeExporter{err: tc.exportErr}
|
|
|
|
err := NewMetricExporter(fakeExporter).ExportMetrics(context.Background(), tc.input)
|
|
|
|
if !errors.Is(err, tc.exportErr) {
|
|
|
|
t.Errorf("NewMetricExporter(%+v) = err(%v), want err(%v)", tc.input, err, tc.exportErr)
|
|
|
|
}
|
|
|
|
// Check the global error handler, since we don't return errors
|
|
|
|
// which occur during conversion.
|
|
|
|
err = fakeErrorHandler.matches(tc.expectedHandledError)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("ExportMetrics(%+v) = %v", tc.input, err)
|
|
|
|
}
|
|
|
|
output := fakeExporter.records
|
|
|
|
if len(tc.expected) != len(output) {
|
|
|
|
t.Fatalf("ExportMetrics(%+v) = %d records, want %d records", tc.input, len(output), len(tc.expected))
|
|
|
|
}
|
2021-08-13 00:44:58 +02:00
|
|
|
if fakeExporter.resource.String() != tc.expectedResource.String() {
|
|
|
|
t.Errorf("ExportMetrics(%+v)[i].Resource() = %+v, want %+v", tc.input, fakeExporter.resource.String(), tc.expectedResource.String())
|
|
|
|
}
|
2021-03-11 19:49:20 +02:00
|
|
|
for i, expected := range tc.expected {
|
|
|
|
if output[i].StartTime() != expected.StartTime() {
|
|
|
|
t.Errorf("ExportMetrics(%+v)[i].StartTime() = %+v, want %+v", tc.input, output[i].StartTime(), expected.StartTime())
|
|
|
|
}
|
|
|
|
if output[i].EndTime() != expected.EndTime() {
|
|
|
|
t.Errorf("ExportMetrics(%+v)[i].EndTime() = %+v, want %+v", tc.input, output[i].EndTime(), expected.EndTime())
|
|
|
|
}
|
|
|
|
if output[i].Descriptor().Name() != expected.Descriptor().Name() {
|
|
|
|
t.Errorf("ExportMetrics(%+v)[i].Descriptor() = %+v, want %+v", tc.input, output[i].Descriptor().Name(), expected.Descriptor().Name())
|
|
|
|
}
|
|
|
|
// Don't bother with a complete check of the descriptor.
|
|
|
|
// That is checked as part of descriptor conversion tests below.
|
2022-04-18 16:31:31 +02:00
|
|
|
if !output[i].Attributes().Equals(expected.Attributes()) {
|
|
|
|
t.Errorf("ExportMetrics(%+v)[i].Attributes() = %+v, want %+v", tc.input, output[i].Attributes(), expected.Attributes())
|
2021-03-11 19:49:20 +02:00
|
|
|
}
|
|
|
|
if output[i].Aggregation().Kind() != expected.Aggregation().Kind() {
|
|
|
|
t.Errorf("ExportMetrics(%+v)[i].Aggregation() = %+v, want %+v", tc.input, output[i].Aggregation().Kind(), expected.Aggregation().Kind())
|
|
|
|
}
|
|
|
|
// Don't bother checking the contents of the points aggregation.
|
|
|
|
// Those tests are done with the aggregations themselves
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-18 16:31:31 +02:00
|
|
|
func TestConvertAttributes(t *testing.T) {
|
2021-03-11 19:49:20 +02:00
|
|
|
setWithMultipleKeys := attribute.NewSet(
|
|
|
|
attribute.KeyValue{Key: attribute.Key("first"), Value: attribute.StringValue("1")},
|
|
|
|
attribute.KeyValue{Key: attribute.Key("second"), Value: attribute.StringValue("2")},
|
|
|
|
)
|
|
|
|
for _, tc := range []struct {
|
|
|
|
desc string
|
|
|
|
inputKeys []metricdata.LabelKey
|
|
|
|
inputValues []metricdata.LabelValue
|
|
|
|
expected *attribute.Set
|
|
|
|
expectedErr error
|
|
|
|
}{
|
|
|
|
{
|
2022-04-18 16:31:31 +02:00
|
|
|
desc: "no attributes",
|
2021-03-11 19:49:20 +02:00
|
|
|
expected: attribute.EmptySet(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "different numbers of keys and values",
|
|
|
|
inputKeys: []metricdata.LabelKey{{Key: "foo"}},
|
|
|
|
expected: attribute.EmptySet(),
|
|
|
|
expectedErr: errConversion,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "multiple keys and values",
|
|
|
|
inputKeys: []metricdata.LabelKey{{Key: "first"}, {Key: "second"}},
|
|
|
|
inputValues: []metricdata.LabelValue{
|
|
|
|
{Value: "1", Present: true},
|
|
|
|
{Value: "2", Present: true},
|
|
|
|
},
|
|
|
|
expected: &setWithMultipleKeys,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "multiple keys and values with some not present",
|
|
|
|
inputKeys: []metricdata.LabelKey{{Key: "first"}, {Key: "second"}, {Key: "third"}},
|
|
|
|
inputValues: []metricdata.LabelValue{
|
|
|
|
{Value: "1", Present: true},
|
|
|
|
{Value: "2", Present: true},
|
|
|
|
{Present: false},
|
|
|
|
},
|
|
|
|
expected: &setWithMultipleKeys,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(tc.desc, func(t *testing.T) {
|
2022-04-18 16:31:31 +02:00
|
|
|
output, err := convertAttrs(tc.inputKeys, tc.inputValues)
|
2021-03-11 19:49:20 +02:00
|
|
|
if !errors.Is(err, tc.expectedErr) {
|
2022-04-18 16:31:31 +02:00
|
|
|
t.Errorf("convertAttrs(keys: %v, values: %v) = err(%v), want err(%v)", tc.inputKeys, tc.inputValues, err, tc.expectedErr)
|
2021-03-11 19:49:20 +02:00
|
|
|
}
|
|
|
|
if !output.Equals(tc.expected) {
|
2022-04-18 16:31:31 +02:00
|
|
|
t.Errorf("convertAttrs(keys: %v, values: %v) = %+v, want %+v", tc.inputKeys, tc.inputValues, output.ToSlice(), tc.expected.ToSlice())
|
2021-03-11 19:49:20 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func TestConvertResource(t *testing.T) {
|
|
|
|
for _, tc := range []struct {
|
|
|
|
desc string
|
|
|
|
input *ocresource.Resource
|
|
|
|
expected *resource.Resource
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "nil resource",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "empty resource",
|
|
|
|
input: &ocresource.Resource{
|
|
|
|
Labels: map[string]string{},
|
|
|
|
},
|
2021-06-08 18:46:42 +02:00
|
|
|
expected: resource.NewSchemaless(),
|
2021-03-11 19:49:20 +02:00
|
|
|
},
|
|
|
|
{
|
2022-04-18 16:31:31 +02:00
|
|
|
desc: "resource with attributes",
|
2021-03-11 19:49:20 +02:00
|
|
|
input: &ocresource.Resource{
|
|
|
|
Labels: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"tick": "tock",
|
|
|
|
},
|
|
|
|
},
|
2021-06-08 18:46:42 +02:00
|
|
|
expected: resource.NewSchemaless(
|
2021-03-11 19:49:20 +02:00
|
|
|
attribute.KeyValue{Key: attribute.Key("foo"), Value: attribute.StringValue("bar")},
|
|
|
|
attribute.KeyValue{Key: attribute.Key("tick"), Value: attribute.StringValue("tock")},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(tc.desc, func(t *testing.T) {
|
|
|
|
output := convertResource(tc.input)
|
|
|
|
if !output.Equal(tc.expected) {
|
|
|
|
t.Errorf("convertResource(%v) = %+v, want %+v", tc.input, output, tc.expected)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func TestConvertDescriptor(t *testing.T) {
|
|
|
|
for _, tc := range []struct {
|
|
|
|
desc string
|
|
|
|
input metricdata.Descriptor
|
2021-10-14 18:06:22 +02:00
|
|
|
expected sdkapi.Descriptor
|
2021-03-11 19:49:20 +02:00
|
|
|
expectedErr error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "empty descriptor",
|
2021-09-27 17:51:47 +02:00
|
|
|
expected: metrictest.NewDescriptor(
|
2021-03-11 19:49:20 +02:00
|
|
|
"",
|
2021-09-01 22:38:37 +02:00
|
|
|
sdkapi.GaugeObserverInstrumentKind,
|
2021-03-11 19:49:20 +02:00
|
|
|
number.Int64Kind,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "gauge int64 bytes",
|
|
|
|
input: metricdata.Descriptor{
|
|
|
|
Name: "foo",
|
|
|
|
Description: "bar",
|
|
|
|
Unit: metricdata.UnitBytes,
|
|
|
|
Type: metricdata.TypeGaugeInt64,
|
|
|
|
},
|
2021-09-27 17:51:47 +02:00
|
|
|
expected: metrictest.NewDescriptor(
|
2021-03-11 19:49:20 +02:00
|
|
|
"foo",
|
2021-09-01 22:38:37 +02:00
|
|
|
sdkapi.GaugeObserverInstrumentKind,
|
2021-03-11 19:49:20 +02:00
|
|
|
number.Int64Kind,
|
2022-03-02 17:50:29 +02:00
|
|
|
instrument.WithDescription("bar"),
|
|
|
|
instrument.WithUnit(unit.Bytes),
|
2021-03-11 19:49:20 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "gauge float64 ms",
|
|
|
|
input: metricdata.Descriptor{
|
|
|
|
Name: "foo",
|
|
|
|
Description: "bar",
|
|
|
|
Unit: metricdata.UnitMilliseconds,
|
|
|
|
Type: metricdata.TypeGaugeFloat64,
|
|
|
|
},
|
2021-09-27 17:51:47 +02:00
|
|
|
expected: metrictest.NewDescriptor(
|
2021-03-11 19:49:20 +02:00
|
|
|
"foo",
|
2021-09-01 22:38:37 +02:00
|
|
|
sdkapi.GaugeObserverInstrumentKind,
|
2021-03-11 19:49:20 +02:00
|
|
|
number.Float64Kind,
|
2022-03-02 17:50:29 +02:00
|
|
|
instrument.WithDescription("bar"),
|
|
|
|
instrument.WithUnit(unit.Milliseconds),
|
2021-03-11 19:49:20 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "cumulative int64 dimensionless",
|
|
|
|
input: metricdata.Descriptor{
|
|
|
|
Name: "foo",
|
|
|
|
Description: "bar",
|
|
|
|
Unit: metricdata.UnitDimensionless,
|
|
|
|
Type: metricdata.TypeCumulativeInt64,
|
|
|
|
},
|
2021-09-27 17:51:47 +02:00
|
|
|
expected: metrictest.NewDescriptor(
|
2021-03-11 19:49:20 +02:00
|
|
|
"foo",
|
2021-09-01 22:38:37 +02:00
|
|
|
sdkapi.CounterObserverInstrumentKind,
|
2021-03-11 19:49:20 +02:00
|
|
|
number.Int64Kind,
|
2022-03-02 17:50:29 +02:00
|
|
|
instrument.WithDescription("bar"),
|
|
|
|
instrument.WithUnit(unit.Dimensionless),
|
2021-03-11 19:49:20 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "cumulative float64 dimensionless",
|
|
|
|
input: metricdata.Descriptor{
|
|
|
|
Name: "foo",
|
|
|
|
Description: "bar",
|
|
|
|
Unit: metricdata.UnitDimensionless,
|
|
|
|
Type: metricdata.TypeCumulativeFloat64,
|
|
|
|
},
|
2021-09-27 17:51:47 +02:00
|
|
|
expected: metrictest.NewDescriptor(
|
2021-03-11 19:49:20 +02:00
|
|
|
"foo",
|
2021-09-01 22:38:37 +02:00
|
|
|
sdkapi.CounterObserverInstrumentKind,
|
2021-03-11 19:49:20 +02:00
|
|
|
number.Float64Kind,
|
2022-03-02 17:50:29 +02:00
|
|
|
instrument.WithDescription("bar"),
|
|
|
|
instrument.WithUnit(unit.Dimensionless),
|
2021-03-11 19:49:20 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "incompatible TypeCumulativeDistribution",
|
|
|
|
input: metricdata.Descriptor{
|
|
|
|
Name: "foo",
|
|
|
|
Description: "bar",
|
|
|
|
Type: metricdata.TypeCumulativeDistribution,
|
|
|
|
},
|
|
|
|
expectedErr: errConversion,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(tc.desc, func(t *testing.T) {
|
|
|
|
output, err := convertDescriptor(tc.input)
|
|
|
|
if !errors.Is(err, tc.expectedErr) {
|
|
|
|
t.Errorf("convertDescriptor(%v) = err(%v), want err(%v)", tc.input, err, tc.expectedErr)
|
|
|
|
}
|
|
|
|
if output != tc.expected {
|
|
|
|
t.Errorf("convertDescriptor(%v) = %+v, want %+v", tc.input, output, tc.expected)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|