2020-04-15 12:04:44 -07: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 otlp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-05-18 18:37:41 -07:00
|
|
|
"sync"
|
2020-04-15 12:04:44 -07:00
|
|
|
"testing"
|
2020-06-18 10:16:33 -07:00
|
|
|
"time"
|
2020-04-15 12:04:44 -07:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-08-10 19:55:52 -07:00
|
|
|
colmetricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/collector/metrics/v1"
|
|
|
|
commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
|
|
|
|
metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1"
|
|
|
|
resourcepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/resource/v1"
|
2020-08-17 20:25:03 -07:00
|
|
|
"go.opentelemetry.io/otel/label"
|
2020-11-12 16:28:32 +01:00
|
|
|
"go.opentelemetry.io/otel/metric"
|
2020-11-11 16:24:12 +01:00
|
|
|
"go.opentelemetry.io/otel/metric/number"
|
2020-04-15 12:04:44 -07:00
|
|
|
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
|
2020-06-09 22:53:30 -07:00
|
|
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
2020-07-24 20:32:52 -07:00
|
|
|
"go.opentelemetry.io/otel/sdk/export/metric/metrictest"
|
2020-09-28 17:58:15 -07:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
|
2020-04-15 12:04:44 -07:00
|
|
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/sum"
|
|
|
|
"go.opentelemetry.io/otel/sdk/resource"
|
|
|
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
2020-06-18 10:16:33 -07:00
|
|
|
var (
|
|
|
|
// Timestamps used in this test:
|
|
|
|
|
|
|
|
intervalStart = time.Now()
|
|
|
|
intervalEnd = intervalStart.Add(time.Hour)
|
|
|
|
)
|
|
|
|
|
|
|
|
func startTime() uint64 {
|
|
|
|
return uint64(intervalStart.UnixNano())
|
|
|
|
}
|
|
|
|
|
|
|
|
func pointTime() uint64 {
|
|
|
|
return uint64(intervalEnd.UnixNano())
|
|
|
|
}
|
|
|
|
|
2020-04-15 12:04:44 -07:00
|
|
|
type metricsServiceClientStub struct {
|
|
|
|
rm []metricpb.ResourceMetrics
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *metricsServiceClientStub) Export(ctx context.Context, in *colmetricpb.ExportMetricsServiceRequest, opts ...grpc.CallOption) (*colmetricpb.ExportMetricsServiceResponse, error) {
|
|
|
|
for _, rm := range in.GetResourceMetrics() {
|
|
|
|
if rm == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
m.rm = append(m.rm, *rm)
|
|
|
|
}
|
|
|
|
return &colmetricpb.ExportMetricsServiceResponse{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *metricsServiceClientStub) ResourceMetrics() []metricpb.ResourceMetrics {
|
|
|
|
return m.rm
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *metricsServiceClientStub) Reset() {
|
|
|
|
m.rm = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type checkpointSet struct {
|
2020-05-18 18:37:41 -07:00
|
|
|
sync.RWMutex
|
2020-04-15 12:04:44 -07:00
|
|
|
records []metricsdk.Record
|
|
|
|
}
|
|
|
|
|
2020-06-22 22:59:51 -07:00
|
|
|
func (m *checkpointSet) ForEach(_ metricsdk.ExportKindSelector, fn func(metricsdk.Record) error) error {
|
2020-04-15 12:04:44 -07:00
|
|
|
for _, r := range m.records {
|
2020-06-09 22:53:30 -07:00
|
|
|
if err := fn(r); err != nil && err != aggregation.ErrNoData {
|
2020-04-15 12:04:44 -07:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type record struct {
|
2020-04-24 09:44:21 -07:00
|
|
|
name string
|
2020-11-12 16:28:32 +01:00
|
|
|
iKind metric.InstrumentKind
|
2020-11-11 16:24:12 +01:00
|
|
|
nKind number.Kind
|
2020-04-24 09:44:21 -07:00
|
|
|
resource *resource.Resource
|
2020-11-12 16:28:32 +01:00
|
|
|
opts []metric.InstrumentOption
|
2020-08-17 20:25:03 -07:00
|
|
|
labels []label.KeyValue
|
2020-04-15 12:04:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2020-08-17 20:25:03 -07:00
|
|
|
baseKeyValues = []label.KeyValue{label.String("host", "test.com")}
|
|
|
|
cpuKey = label.Key("CPU")
|
2020-04-15 12:04:44 -07:00
|
|
|
|
2020-10-31 11:16:55 -07:00
|
|
|
testInstA = resource.NewWithAttributes(label.String("instance", "tester-a"))
|
|
|
|
testInstB = resource.NewWithAttributes(label.String("instance", "tester-b"))
|
2020-04-15 12:04:44 -07:00
|
|
|
|
2020-09-28 17:58:15 -07:00
|
|
|
testHistogramBoundaries = []float64{2.0, 4.0, 8.0}
|
|
|
|
|
2020-06-24 14:02:13 -07:00
|
|
|
cpu1Labels = []*commonpb.StringKeyValue{
|
|
|
|
{
|
|
|
|
Key: "CPU",
|
|
|
|
Value: "1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "host",
|
|
|
|
Value: "test.com",
|
2020-04-15 12:04:44 -07:00
|
|
|
},
|
|
|
|
}
|
2020-06-24 14:02:13 -07:00
|
|
|
cpu2Labels = []*commonpb.StringKeyValue{
|
|
|
|
{
|
|
|
|
Key: "CPU",
|
|
|
|
Value: "2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "host",
|
|
|
|
Value: "test.com",
|
2020-04-15 12:04:44 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
testerAResource = &resourcepb.Resource{
|
2020-06-24 14:02:13 -07:00
|
|
|
Attributes: []*commonpb.KeyValue{
|
2020-04-15 12:04:44 -07:00
|
|
|
{
|
2020-06-24 14:02:13 -07:00
|
|
|
Key: "instance",
|
|
|
|
Value: &commonpb.AnyValue{
|
|
|
|
Value: &commonpb.AnyValue_StringValue{
|
|
|
|
StringValue: "tester-a",
|
|
|
|
},
|
|
|
|
},
|
2020-04-15 12:04:44 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
testerBResource = &resourcepb.Resource{
|
2020-06-24 14:02:13 -07:00
|
|
|
Attributes: []*commonpb.KeyValue{
|
2020-04-15 12:04:44 -07:00
|
|
|
{
|
2020-06-24 14:02:13 -07:00
|
|
|
Key: "instance",
|
|
|
|
Value: &commonpb.AnyValue{
|
|
|
|
Value: &commonpb.AnyValue_StringValue{
|
|
|
|
StringValue: "tester-b",
|
|
|
|
},
|
|
|
|
},
|
2020-04-15 12:04:44 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNoGroupingExport(t *testing.T) {
|
|
|
|
runMetricExportTests(
|
|
|
|
t,
|
2020-11-10 07:44:42 -08:00
|
|
|
nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
[]record{
|
|
|
|
{
|
|
|
|
"int64-count",
|
2020-11-12 16:28:32 +01:00
|
|
|
metric.CounterInstrumentKind,
|
2020-11-11 16:24:12 +01:00
|
|
|
number.Int64Kind,
|
2020-04-24 09:44:21 -07:00
|
|
|
nil,
|
|
|
|
nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
append(baseKeyValues, cpuKey.Int(1)),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"int64-count",
|
2020-11-12 16:28:32 +01:00
|
|
|
metric.CounterInstrumentKind,
|
2020-11-11 16:24:12 +01:00
|
|
|
number.Int64Kind,
|
2020-04-24 09:44:21 -07:00
|
|
|
nil,
|
|
|
|
nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
append(baseKeyValues, cpuKey.Int(2)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[]metricpb.ResourceMetrics{
|
|
|
|
{
|
2020-04-23 12:10:58 -07:00
|
|
|
Resource: nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
InstrumentationLibraryMetrics: []*metricpb.InstrumentationLibraryMetrics{
|
|
|
|
{
|
|
|
|
Metrics: []*metricpb.Metric{
|
|
|
|
{
|
2020-10-08 20:07:39 -07:00
|
|
|
Name: "int64-count",
|
|
|
|
Data: &metricpb.Metric_IntSum{
|
|
|
|
IntSum: &metricpb.IntSum{
|
|
|
|
IsMonotonic: true,
|
|
|
|
AggregationTemporality: metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
|
|
|
|
DataPoints: []*metricpb.IntDataPoint{
|
|
|
|
{
|
|
|
|
Value: 11,
|
|
|
|
Labels: cpu1Labels,
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 11,
|
|
|
|
Labels: cpu2Labels,
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
|
|
|
},
|
|
|
|
},
|
2020-04-15 12:04:44 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:11:12 -07:00
|
|
|
func TestValuerecorderMetricGroupingExport(t *testing.T) {
|
2020-04-15 12:04:44 -07:00
|
|
|
r := record{
|
2020-05-15 22:11:12 -07:00
|
|
|
"valuerecorder",
|
2020-11-12 16:28:32 +01:00
|
|
|
metric.ValueRecorderInstrumentKind,
|
2020-11-11 16:24:12 +01:00
|
|
|
number.Int64Kind,
|
2020-04-24 09:44:21 -07:00
|
|
|
nil,
|
|
|
|
nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
append(baseKeyValues, cpuKey.Int(1)),
|
|
|
|
}
|
|
|
|
expected := []metricpb.ResourceMetrics{
|
|
|
|
{
|
2020-04-23 12:10:58 -07:00
|
|
|
Resource: nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
InstrumentationLibraryMetrics: []*metricpb.InstrumentationLibraryMetrics{
|
|
|
|
{
|
|
|
|
Metrics: []*metricpb.Metric{
|
|
|
|
{
|
2020-10-08 20:07:39 -07:00
|
|
|
Name: "valuerecorder",
|
|
|
|
Data: &metricpb.Metric_IntHistogram{
|
|
|
|
IntHistogram: &metricpb.IntHistogram{
|
|
|
|
AggregationTemporality: metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
|
|
|
|
DataPoints: []*metricpb.IntHistogramDataPoint{
|
2020-06-24 14:02:13 -07:00
|
|
|
{
|
2020-10-08 20:07:39 -07:00
|
|
|
Labels: []*commonpb.StringKeyValue{
|
|
|
|
{
|
|
|
|
Key: "CPU",
|
|
|
|
Value: "1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "host",
|
|
|
|
Value: "test.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
|
|
|
Count: 2,
|
|
|
|
Sum: 11,
|
|
|
|
ExplicitBounds: testHistogramBoundaries,
|
|
|
|
BucketCounts: []uint64{1, 0, 0, 1},
|
2020-06-24 14:02:13 -07:00
|
|
|
},
|
|
|
|
{
|
2020-10-08 20:07:39 -07:00
|
|
|
Labels: []*commonpb.StringKeyValue{
|
|
|
|
{
|
|
|
|
Key: "CPU",
|
|
|
|
Value: "1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "host",
|
|
|
|
Value: "test.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Count: 2,
|
|
|
|
Sum: 11,
|
|
|
|
ExplicitBounds: testHistogramBoundaries,
|
|
|
|
BucketCounts: []uint64{1, 0, 0, 1},
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
2020-06-24 14:02:13 -07:00
|
|
|
},
|
|
|
|
},
|
2020-04-15 12:04:44 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-11-10 07:44:42 -08:00
|
|
|
runMetricExportTests(t, nil, []record{r, r}, expected)
|
2020-04-15 12:04:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCountInt64MetricGroupingExport(t *testing.T) {
|
|
|
|
r := record{
|
|
|
|
"int64-count",
|
2020-11-12 16:28:32 +01:00
|
|
|
metric.CounterInstrumentKind,
|
2020-11-11 16:24:12 +01:00
|
|
|
number.Int64Kind,
|
2020-04-24 09:44:21 -07:00
|
|
|
nil,
|
|
|
|
nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
append(baseKeyValues, cpuKey.Int(1)),
|
|
|
|
}
|
|
|
|
runMetricExportTests(
|
|
|
|
t,
|
2020-11-10 07:44:42 -08:00
|
|
|
nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
[]record{r, r},
|
|
|
|
[]metricpb.ResourceMetrics{
|
|
|
|
{
|
2020-04-23 12:10:58 -07:00
|
|
|
Resource: nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
InstrumentationLibraryMetrics: []*metricpb.InstrumentationLibraryMetrics{
|
|
|
|
{
|
|
|
|
Metrics: []*metricpb.Metric{
|
|
|
|
{
|
2020-10-08 20:07:39 -07:00
|
|
|
Name: "int64-count",
|
|
|
|
Data: &metricpb.Metric_IntSum{
|
|
|
|
IntSum: &metricpb.IntSum{
|
|
|
|
IsMonotonic: true,
|
|
|
|
AggregationTemporality: metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
|
|
|
|
DataPoints: []*metricpb.IntDataPoint{
|
|
|
|
{
|
|
|
|
Value: 11,
|
|
|
|
Labels: cpu1Labels,
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 11,
|
|
|
|
Labels: cpu1Labels,
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
|
|
|
},
|
|
|
|
},
|
2020-04-15 12:04:44 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCountFloat64MetricGroupingExport(t *testing.T) {
|
|
|
|
r := record{
|
|
|
|
"float64-count",
|
2020-11-12 16:28:32 +01:00
|
|
|
metric.CounterInstrumentKind,
|
2020-11-11 16:24:12 +01:00
|
|
|
number.Float64Kind,
|
2020-04-24 09:44:21 -07:00
|
|
|
nil,
|
|
|
|
nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
append(baseKeyValues, cpuKey.Int(1)),
|
|
|
|
}
|
|
|
|
runMetricExportTests(
|
|
|
|
t,
|
2020-11-10 07:44:42 -08:00
|
|
|
nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
[]record{r, r},
|
|
|
|
[]metricpb.ResourceMetrics{
|
|
|
|
{
|
2020-04-23 12:10:58 -07:00
|
|
|
Resource: nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
InstrumentationLibraryMetrics: []*metricpb.InstrumentationLibraryMetrics{
|
|
|
|
{
|
|
|
|
Metrics: []*metricpb.Metric{
|
|
|
|
{
|
2020-10-08 20:07:39 -07:00
|
|
|
Name: "float64-count",
|
|
|
|
Data: &metricpb.Metric_DoubleSum{
|
|
|
|
DoubleSum: &metricpb.DoubleSum{
|
|
|
|
IsMonotonic: true,
|
|
|
|
AggregationTemporality: metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
|
|
|
|
DataPoints: []*metricpb.DoubleDataPoint{
|
2020-06-24 14:02:13 -07:00
|
|
|
{
|
2020-10-08 20:07:39 -07:00
|
|
|
Value: 11,
|
|
|
|
Labels: []*commonpb.StringKeyValue{
|
|
|
|
{
|
|
|
|
Key: "CPU",
|
|
|
|
Value: "1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "host",
|
|
|
|
Value: "test.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
2020-06-24 14:02:13 -07:00
|
|
|
},
|
|
|
|
{
|
2020-10-08 20:07:39 -07:00
|
|
|
Value: 11,
|
|
|
|
Labels: []*commonpb.StringKeyValue{
|
|
|
|
{
|
|
|
|
Key: "CPU",
|
|
|
|
Value: "1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "host",
|
|
|
|
Value: "test.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
2020-06-24 14:02:13 -07:00
|
|
|
},
|
|
|
|
},
|
2020-04-15 12:04:44 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestResourceMetricGroupingExport(t *testing.T) {
|
|
|
|
runMetricExportTests(
|
|
|
|
t,
|
2020-11-10 07:44:42 -08:00
|
|
|
nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
[]record{
|
|
|
|
{
|
|
|
|
"int64-count",
|
2020-11-12 16:28:32 +01:00
|
|
|
metric.CounterInstrumentKind,
|
2020-11-11 16:24:12 +01:00
|
|
|
number.Int64Kind,
|
2020-04-24 09:44:21 -07:00
|
|
|
testInstA,
|
|
|
|
nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
append(baseKeyValues, cpuKey.Int(1)),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"int64-count",
|
2020-11-12 16:28:32 +01:00
|
|
|
metric.CounterInstrumentKind,
|
2020-11-11 16:24:12 +01:00
|
|
|
number.Int64Kind,
|
2020-04-24 09:44:21 -07:00
|
|
|
testInstA,
|
|
|
|
nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
append(baseKeyValues, cpuKey.Int(1)),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"int64-count",
|
2020-11-12 16:28:32 +01:00
|
|
|
metric.CounterInstrumentKind,
|
2020-11-11 16:24:12 +01:00
|
|
|
number.Int64Kind,
|
2020-04-24 09:44:21 -07:00
|
|
|
testInstA,
|
|
|
|
nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
append(baseKeyValues, cpuKey.Int(2)),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"int64-count",
|
2020-11-12 16:28:32 +01:00
|
|
|
metric.CounterInstrumentKind,
|
2020-11-11 16:24:12 +01:00
|
|
|
number.Int64Kind,
|
2020-04-24 09:44:21 -07:00
|
|
|
testInstB,
|
|
|
|
nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
append(baseKeyValues, cpuKey.Int(1)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[]metricpb.ResourceMetrics{
|
|
|
|
{
|
|
|
|
Resource: testerAResource,
|
|
|
|
InstrumentationLibraryMetrics: []*metricpb.InstrumentationLibraryMetrics{
|
|
|
|
{
|
|
|
|
Metrics: []*metricpb.Metric{
|
|
|
|
{
|
2020-10-08 20:07:39 -07:00
|
|
|
Name: "int64-count",
|
|
|
|
Data: &metricpb.Metric_IntSum{
|
|
|
|
IntSum: &metricpb.IntSum{
|
|
|
|
IsMonotonic: true,
|
|
|
|
AggregationTemporality: metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
|
|
|
|
DataPoints: []*metricpb.IntDataPoint{
|
|
|
|
{
|
|
|
|
Value: 11,
|
|
|
|
Labels: cpu1Labels,
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 11,
|
|
|
|
Labels: cpu1Labels,
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 11,
|
|
|
|
Labels: cpu2Labels,
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
|
|
|
},
|
|
|
|
},
|
2020-04-15 12:04:44 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Resource: testerBResource,
|
|
|
|
InstrumentationLibraryMetrics: []*metricpb.InstrumentationLibraryMetrics{
|
|
|
|
{
|
|
|
|
Metrics: []*metricpb.Metric{
|
|
|
|
{
|
2020-10-08 20:07:39 -07:00
|
|
|
Name: "int64-count",
|
|
|
|
Data: &metricpb.Metric_IntSum{
|
|
|
|
IntSum: &metricpb.IntSum{
|
|
|
|
IsMonotonic: true,
|
|
|
|
AggregationTemporality: metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
|
|
|
|
DataPoints: []*metricpb.IntDataPoint{
|
|
|
|
{
|
|
|
|
Value: 11,
|
|
|
|
Labels: cpu1Labels,
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
|
|
|
},
|
|
|
|
},
|
2020-04-15 12:04:44 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestResourceInstLibMetricGroupingExport(t *testing.T) {
|
2020-11-12 16:28:32 +01:00
|
|
|
countingLib1 := []metric.InstrumentOption{
|
|
|
|
metric.WithInstrumentationName("counting-lib"),
|
|
|
|
metric.WithInstrumentationVersion("v1"),
|
2020-06-12 09:11:17 -07:00
|
|
|
}
|
2020-11-12 16:28:32 +01:00
|
|
|
countingLib2 := []metric.InstrumentOption{
|
|
|
|
metric.WithInstrumentationName("counting-lib"),
|
|
|
|
metric.WithInstrumentationVersion("v2"),
|
2020-06-12 09:11:17 -07:00
|
|
|
}
|
2020-11-12 16:28:32 +01:00
|
|
|
summingLib := []metric.InstrumentOption{
|
|
|
|
metric.WithInstrumentationName("summing-lib"),
|
2020-06-12 09:11:17 -07:00
|
|
|
}
|
2020-04-15 12:04:44 -07:00
|
|
|
runMetricExportTests(
|
|
|
|
t,
|
2020-11-10 07:44:42 -08:00
|
|
|
nil,
|
2020-04-15 12:04:44 -07:00
|
|
|
[]record{
|
|
|
|
{
|
|
|
|
"int64-count",
|
2020-11-12 16:28:32 +01:00
|
|
|
metric.CounterInstrumentKind,
|
2020-11-11 16:24:12 +01:00
|
|
|
number.Int64Kind,
|
2020-04-24 09:44:21 -07:00
|
|
|
testInstA,
|
2020-06-12 09:11:17 -07:00
|
|
|
countingLib1,
|
2020-04-15 12:04:44 -07:00
|
|
|
append(baseKeyValues, cpuKey.Int(1)),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"int64-count",
|
2020-11-12 16:28:32 +01:00
|
|
|
metric.CounterInstrumentKind,
|
2020-11-11 16:24:12 +01:00
|
|
|
number.Int64Kind,
|
2020-04-24 09:44:21 -07:00
|
|
|
testInstA,
|
2020-06-12 09:11:17 -07:00
|
|
|
countingLib2,
|
2020-04-15 12:04:44 -07:00
|
|
|
append(baseKeyValues, cpuKey.Int(1)),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"int64-count",
|
2020-11-12 16:28:32 +01:00
|
|
|
metric.CounterInstrumentKind,
|
2020-11-11 16:24:12 +01:00
|
|
|
number.Int64Kind,
|
2020-04-24 09:44:21 -07:00
|
|
|
testInstA,
|
2020-06-12 09:11:17 -07:00
|
|
|
countingLib1,
|
|
|
|
append(baseKeyValues, cpuKey.Int(1)),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"int64-count",
|
2020-11-12 16:28:32 +01:00
|
|
|
metric.CounterInstrumentKind,
|
2020-11-11 16:24:12 +01:00
|
|
|
number.Int64Kind,
|
2020-06-12 09:11:17 -07:00
|
|
|
testInstA,
|
|
|
|
countingLib1,
|
2020-04-15 12:04:44 -07:00
|
|
|
append(baseKeyValues, cpuKey.Int(2)),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"int64-count",
|
2020-11-12 16:28:32 +01:00
|
|
|
metric.CounterInstrumentKind,
|
2020-11-11 16:24:12 +01:00
|
|
|
number.Int64Kind,
|
2020-04-24 09:44:21 -07:00
|
|
|
testInstA,
|
2020-06-12 09:11:17 -07:00
|
|
|
summingLib,
|
2020-04-15 12:04:44 -07:00
|
|
|
append(baseKeyValues, cpuKey.Int(1)),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"int64-count",
|
2020-11-12 16:28:32 +01:00
|
|
|
metric.CounterInstrumentKind,
|
2020-11-11 16:24:12 +01:00
|
|
|
number.Int64Kind,
|
2020-04-24 09:44:21 -07:00
|
|
|
testInstB,
|
2020-06-12 09:11:17 -07:00
|
|
|
countingLib1,
|
2020-04-15 12:04:44 -07:00
|
|
|
append(baseKeyValues, cpuKey.Int(1)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[]metricpb.ResourceMetrics{
|
|
|
|
{
|
|
|
|
Resource: testerAResource,
|
|
|
|
InstrumentationLibraryMetrics: []*metricpb.InstrumentationLibraryMetrics{
|
|
|
|
{
|
|
|
|
InstrumentationLibrary: &commonpb.InstrumentationLibrary{
|
2020-06-12 09:11:17 -07:00
|
|
|
Name: "counting-lib",
|
|
|
|
Version: "v1",
|
2020-04-15 12:04:44 -07:00
|
|
|
},
|
|
|
|
Metrics: []*metricpb.Metric{
|
|
|
|
{
|
2020-10-08 20:07:39 -07:00
|
|
|
Name: "int64-count",
|
|
|
|
Data: &metricpb.Metric_IntSum{
|
|
|
|
IntSum: &metricpb.IntSum{
|
|
|
|
IsMonotonic: true,
|
|
|
|
AggregationTemporality: metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
|
|
|
|
DataPoints: []*metricpb.IntDataPoint{
|
|
|
|
{
|
|
|
|
Value: 11,
|
|
|
|
Labels: cpu1Labels,
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 11,
|
|
|
|
Labels: cpu1Labels,
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 11,
|
|
|
|
Labels: cpu2Labels,
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
|
|
|
},
|
|
|
|
},
|
2020-04-15 12:04:44 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-06-12 09:11:17 -07:00
|
|
|
{
|
|
|
|
InstrumentationLibrary: &commonpb.InstrumentationLibrary{
|
|
|
|
Name: "counting-lib",
|
|
|
|
Version: "v2",
|
|
|
|
},
|
|
|
|
Metrics: []*metricpb.Metric{
|
|
|
|
{
|
2020-10-08 20:07:39 -07:00
|
|
|
Name: "int64-count",
|
|
|
|
Data: &metricpb.Metric_IntSum{
|
|
|
|
IntSum: &metricpb.IntSum{
|
|
|
|
IsMonotonic: true,
|
|
|
|
AggregationTemporality: metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
|
|
|
|
DataPoints: []*metricpb.IntDataPoint{
|
|
|
|
{
|
|
|
|
Value: 11,
|
|
|
|
Labels: cpu1Labels,
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
|
|
|
},
|
|
|
|
},
|
2020-06-12 09:11:17 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-04-15 12:04:44 -07:00
|
|
|
{
|
|
|
|
InstrumentationLibrary: &commonpb.InstrumentationLibrary{
|
|
|
|
Name: "summing-lib",
|
|
|
|
},
|
|
|
|
Metrics: []*metricpb.Metric{
|
|
|
|
{
|
2020-10-08 20:07:39 -07:00
|
|
|
Name: "int64-count",
|
|
|
|
Data: &metricpb.Metric_IntSum{
|
|
|
|
IntSum: &metricpb.IntSum{
|
|
|
|
IsMonotonic: true,
|
|
|
|
AggregationTemporality: metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
|
|
|
|
DataPoints: []*metricpb.IntDataPoint{
|
|
|
|
{
|
|
|
|
Value: 11,
|
|
|
|
Labels: cpu1Labels,
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
|
|
|
},
|
|
|
|
},
|
2020-04-15 12:04:44 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Resource: testerBResource,
|
|
|
|
InstrumentationLibraryMetrics: []*metricpb.InstrumentationLibraryMetrics{
|
|
|
|
{
|
|
|
|
InstrumentationLibrary: &commonpb.InstrumentationLibrary{
|
2020-06-12 09:11:17 -07:00
|
|
|
Name: "counting-lib",
|
|
|
|
Version: "v1",
|
2020-04-15 12:04:44 -07:00
|
|
|
},
|
|
|
|
Metrics: []*metricpb.Metric{
|
|
|
|
{
|
2020-10-08 20:07:39 -07:00
|
|
|
Name: "int64-count",
|
|
|
|
Data: &metricpb.Metric_IntSum{
|
|
|
|
IntSum: &metricpb.IntSum{
|
|
|
|
IsMonotonic: true,
|
|
|
|
AggregationTemporality: metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
|
|
|
|
DataPoints: []*metricpb.IntDataPoint{
|
|
|
|
{
|
|
|
|
Value: 11,
|
|
|
|
Labels: cpu1Labels,
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
|
|
|
},
|
|
|
|
},
|
2020-04-15 12:04:44 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-10 07:44:42 -08:00
|
|
|
func TestStatelessExportKind(t *testing.T) {
|
|
|
|
type testcase struct {
|
|
|
|
name string
|
2020-11-12 16:28:32 +01:00
|
|
|
instrumentKind metric.InstrumentKind
|
2020-11-10 07:44:42 -08:00
|
|
|
aggTemporality metricpb.AggregationTemporality
|
|
|
|
monotonic bool
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, k := range []testcase{
|
2020-11-12 16:28:32 +01:00
|
|
|
{"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},
|
2020-11-10 07:44:42 -08:00
|
|
|
} {
|
|
|
|
t.Run(k.name, func(t *testing.T) {
|
|
|
|
runMetricExportTests(
|
|
|
|
t,
|
|
|
|
[]ExporterOption{
|
|
|
|
WithMetricExportKindSelector(
|
|
|
|
metricsdk.StatelessExportKindSelector(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
[]record{
|
|
|
|
{
|
|
|
|
"instrument",
|
|
|
|
k.instrumentKind,
|
2020-11-11 16:24:12 +01:00
|
|
|
number.Int64Kind,
|
2020-11-10 07:44:42 -08:00
|
|
|
testInstA,
|
|
|
|
nil,
|
|
|
|
append(baseKeyValues, cpuKey.Int(1)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[]metricpb.ResourceMetrics{
|
|
|
|
{
|
|
|
|
Resource: testerAResource,
|
|
|
|
InstrumentationLibraryMetrics: []*metricpb.InstrumentationLibraryMetrics{
|
|
|
|
{
|
|
|
|
Metrics: []*metricpb.Metric{
|
|
|
|
{
|
|
|
|
Name: "instrument",
|
|
|
|
Data: &metricpb.Metric_IntSum{
|
|
|
|
IntSum: &metricpb.IntSum{
|
|
|
|
IsMonotonic: k.monotonic,
|
|
|
|
AggregationTemporality: k.aggTemporality,
|
|
|
|
DataPoints: []*metricpb.IntDataPoint{
|
|
|
|
{
|
|
|
|
Value: 11,
|
|
|
|
Labels: cpu1Labels,
|
|
|
|
StartTimeUnixNano: startTime(),
|
|
|
|
TimeUnixNano: pointTime(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-15 12:04:44 -07:00
|
|
|
// What works single-threaded should work multi-threaded
|
2020-11-10 07:44:42 -08:00
|
|
|
func runMetricExportTests(t *testing.T, opts []ExporterOption, rs []record, expected []metricpb.ResourceMetrics) {
|
Some cleanups in otlp exporter (#1350)
* Drop WorkerCount option
This is not a good option - the user isn't likely to know how many
worker goroutines is optimal. This should be something that an
exporter should figure out itself. The second problem with the option
is that it is specific to the metric transformation from SDK export
format into protobuf. When the exporter starts supporting other
protocols (HTTP/JSON for example), this option may be of no use. So
the option should rather belong to the protocol, not to the
exporter. Currently both mean the same, but later they will be
separated, and this option breaks the separation.
* Make stop channel a typical signalling channel
Signalling channels are idiomatically defined as chan struct{}, so
let's make it so, to avoid confusion about the meaning of the bool
type.
* Close a race when grpc connection is closed multiple times
If several goroutines call Shutdown at the same time, then the
following scenario is possible:
goroutine A locks a mutex, reads a started member, unlocks the mutex
and gets preempted
goroutine B locks a mutex, reads a started member, unlocks the mutex
and gets preempted
goroutine A does not return early in the "if !started" conditional and
continues to close the connection and execute the rest of the function
(where it finally sets the started member to false), gets preempted
goroutine B also does not return early, because it got a copy of
started before goroutine A set it to false, so it tries to close the
connection again.
* Update changelog
2020-11-20 03:03:25 +01:00
|
|
|
exp := NewUnstartedExporter(opts...)
|
2020-04-15 12:04:44 -07:00
|
|
|
msc := &metricsServiceClientStub{}
|
|
|
|
exp.metricExporter = msc
|
|
|
|
exp.started = true
|
|
|
|
|
2020-04-24 09:44:21 -07:00
|
|
|
recs := map[label.Distinct][]metricsdk.Record{}
|
|
|
|
resources := map[label.Distinct]*resource.Resource{}
|
2020-04-15 12:04:44 -07:00
|
|
|
for _, r := range rs {
|
2020-11-10 07:44:42 -08:00
|
|
|
lcopy := make([]label.KeyValue, len(r.labels))
|
|
|
|
copy(lcopy, r.labels)
|
2020-11-12 16:28:32 +01:00
|
|
|
desc := metric.NewDescriptor(r.name, r.iKind, r.nKind, r.opts...)
|
2020-11-10 07:44:42 -08:00
|
|
|
labs := label.NewSet(lcopy...)
|
2020-04-15 12:04:44 -07:00
|
|
|
|
2020-06-13 00:55:01 -07:00
|
|
|
var agg, ckpt metricsdk.Aggregator
|
2020-11-10 07:44:42 -08:00
|
|
|
if r.iKind.Adding() {
|
2020-07-24 20:32:52 -07:00
|
|
|
agg, ckpt = metrictest.Unslice2(sum.New(2))
|
2020-11-10 07:44:42 -08:00
|
|
|
} else {
|
2020-09-28 17:58:15 -07:00
|
|
|
agg, ckpt = metrictest.Unslice2(histogram.New(2, &desc, testHistogramBoundaries))
|
2020-04-15 12:04:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx := context.Background()
|
2020-11-10 07:44:42 -08:00
|
|
|
if r.iKind.Synchronous() {
|
|
|
|
// For synchronous instruments, perform two updates: 1 and 10
|
|
|
|
switch r.nKind {
|
2020-11-11 16:24:12 +01:00
|
|
|
case number.Int64Kind:
|
|
|
|
require.NoError(t, agg.Update(ctx, number.NewInt64Number(1), &desc))
|
|
|
|
require.NoError(t, agg.Update(ctx, number.NewInt64Number(10), &desc))
|
|
|
|
case number.Float64Kind:
|
|
|
|
require.NoError(t, agg.Update(ctx, number.NewFloat64Number(1), &desc))
|
|
|
|
require.NoError(t, agg.Update(ctx, number.NewFloat64Number(10), &desc))
|
2020-11-10 07:44:42 -08:00
|
|
|
default:
|
|
|
|
t.Fatalf("invalid number kind: %v", r.nKind)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// For asynchronous instruments, perform a single update: 11
|
|
|
|
switch r.nKind {
|
2020-11-11 16:24:12 +01:00
|
|
|
case number.Int64Kind:
|
|
|
|
require.NoError(t, agg.Update(ctx, number.NewInt64Number(11), &desc))
|
|
|
|
case number.Float64Kind:
|
|
|
|
require.NoError(t, agg.Update(ctx, number.NewFloat64Number(11), &desc))
|
2020-11-10 07:44:42 -08:00
|
|
|
default:
|
|
|
|
t.Fatalf("invalid number kind: %v", r.nKind)
|
|
|
|
}
|
2020-04-15 12:04:44 -07:00
|
|
|
}
|
2020-06-23 10:41:11 -07:00
|
|
|
require.NoError(t, agg.SynchronizedMove(ckpt, &desc))
|
2020-04-15 12:04:44 -07:00
|
|
|
|
2020-04-24 09:44:21 -07:00
|
|
|
equiv := r.resource.Equivalent()
|
|
|
|
resources[equiv] = r.resource
|
2020-06-18 10:16:33 -07:00
|
|
|
recs[equiv] = append(recs[equiv], metricsdk.NewRecord(&desc, &labs, r.resource, ckpt.Aggregation(), intervalStart, intervalEnd))
|
2020-04-24 09:44:21 -07:00
|
|
|
}
|
2020-05-18 17:44:28 -07:00
|
|
|
for _, records := range recs {
|
2020-05-18 18:37:41 -07:00
|
|
|
assert.NoError(t, exp.Export(context.Background(), &checkpointSet{records: records}))
|
2020-04-15 12:04:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// assert.ElementsMatch does not equate nested slices of different order,
|
|
|
|
// therefore this requires the top level slice to be broken down.
|
|
|
|
// Build a map of Resource/InstrumentationLibrary pairs to Metrics, from
|
|
|
|
// that validate the metric elements match for all expected pairs. Finally,
|
|
|
|
// make we saw all expected pairs.
|
|
|
|
type key struct {
|
|
|
|
resource, instrumentationLibrary string
|
|
|
|
}
|
|
|
|
got := map[key][]*metricpb.Metric{}
|
|
|
|
for _, rm := range msc.ResourceMetrics() {
|
|
|
|
for _, ilm := range rm.InstrumentationLibraryMetrics {
|
|
|
|
k := key{
|
|
|
|
resource: rm.GetResource().String(),
|
|
|
|
instrumentationLibrary: ilm.GetInstrumentationLibrary().String(),
|
|
|
|
}
|
|
|
|
got[k] = ilm.GetMetrics()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
seen := map[key]struct{}{}
|
|
|
|
for _, rm := range expected {
|
|
|
|
for _, ilm := range rm.InstrumentationLibraryMetrics {
|
|
|
|
k := key{
|
|
|
|
resource: rm.GetResource().String(),
|
|
|
|
instrumentationLibrary: ilm.GetInstrumentationLibrary().String(),
|
|
|
|
}
|
|
|
|
seen[k] = struct{}{}
|
|
|
|
g, ok := got[k]
|
|
|
|
if !ok {
|
|
|
|
t.Errorf("missing metrics for:\n\tResource: %s\n\tInstrumentationLibrary: %s\n", k.resource, k.instrumentationLibrary)
|
|
|
|
continue
|
|
|
|
}
|
2020-06-24 14:02:13 -07:00
|
|
|
if !assert.Len(t, g, len(ilm.GetMetrics())) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for i, expected := range ilm.GetMetrics() {
|
2020-10-08 20:07:39 -07:00
|
|
|
assert.Equal(t, expected.Name, g[i].Name)
|
|
|
|
assert.Equal(t, expected.Unit, g[i].Unit)
|
|
|
|
assert.Equal(t, expected.Description, g[i].Description)
|
|
|
|
switch g[i].Data.(type) {
|
|
|
|
case *metricpb.Metric_IntGauge:
|
|
|
|
assert.ElementsMatch(t, expected.GetIntGauge().DataPoints, g[i].GetIntGauge().DataPoints)
|
|
|
|
case *metricpb.Metric_IntHistogram:
|
2020-11-10 07:44:42 -08:00
|
|
|
assert.Equal(t,
|
|
|
|
expected.GetIntHistogram().GetAggregationTemporality(),
|
|
|
|
g[i].GetIntHistogram().GetAggregationTemporality(),
|
|
|
|
)
|
2020-10-08 20:07:39 -07:00
|
|
|
assert.ElementsMatch(t, expected.GetIntHistogram().DataPoints, g[i].GetIntHistogram().DataPoints)
|
|
|
|
case *metricpb.Metric_IntSum:
|
2020-11-10 07:44:42 -08:00
|
|
|
assert.Equal(t,
|
|
|
|
expected.GetIntSum().GetAggregationTemporality(),
|
|
|
|
g[i].GetIntSum().GetAggregationTemporality(),
|
|
|
|
)
|
|
|
|
assert.Equal(t,
|
|
|
|
expected.GetIntSum().GetIsMonotonic(),
|
|
|
|
g[i].GetIntSum().GetIsMonotonic(),
|
|
|
|
)
|
2020-10-08 20:07:39 -07:00
|
|
|
assert.ElementsMatch(t, expected.GetIntSum().DataPoints, g[i].GetIntSum().DataPoints)
|
|
|
|
case *metricpb.Metric_DoubleGauge:
|
|
|
|
assert.ElementsMatch(t, expected.GetDoubleGauge().DataPoints, g[i].GetDoubleGauge().DataPoints)
|
|
|
|
case *metricpb.Metric_DoubleHistogram:
|
2020-11-10 07:44:42 -08:00
|
|
|
assert.Equal(t,
|
|
|
|
expected.GetDoubleHistogram().GetAggregationTemporality(),
|
|
|
|
g[i].GetDoubleHistogram().GetAggregationTemporality(),
|
|
|
|
)
|
2020-10-08 20:07:39 -07:00
|
|
|
assert.ElementsMatch(t, expected.GetDoubleHistogram().DataPoints, g[i].GetDoubleHistogram().DataPoints)
|
|
|
|
case *metricpb.Metric_DoubleSum:
|
2020-11-10 07:44:42 -08:00
|
|
|
assert.Equal(t,
|
|
|
|
expected.GetDoubleSum().GetAggregationTemporality(),
|
|
|
|
g[i].GetDoubleSum().GetAggregationTemporality(),
|
|
|
|
)
|
|
|
|
assert.Equal(t,
|
|
|
|
expected.GetDoubleSum().GetIsMonotonic(),
|
|
|
|
g[i].GetDoubleSum().GetIsMonotonic(),
|
|
|
|
)
|
2020-10-08 20:07:39 -07:00
|
|
|
assert.ElementsMatch(t, expected.GetDoubleSum().DataPoints, g[i].GetDoubleSum().DataPoints)
|
|
|
|
default:
|
|
|
|
assert.Failf(t, "unknown data type", g[i].Name)
|
|
|
|
}
|
2020-06-24 14:02:13 -07:00
|
|
|
}
|
2020-04-15 12:04:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for k := range got {
|
|
|
|
if _, ok := seen[k]; !ok {
|
|
|
|
t.Errorf("did not expect metrics for:\n\tResource: %s\n\tInstrumentationLibrary: %s\n", k.resource, k.instrumentationLibrary)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEmptyMetricExport(t *testing.T) {
|
|
|
|
msc := &metricsServiceClientStub{}
|
|
|
|
exp := NewUnstartedExporter()
|
|
|
|
exp.metricExporter = msc
|
|
|
|
exp.started = true
|
|
|
|
|
|
|
|
for _, test := range []struct {
|
|
|
|
records []metricsdk.Record
|
|
|
|
want []metricpb.ResourceMetrics
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
[]metricsdk.Record(nil),
|
|
|
|
[]metricpb.ResourceMetrics(nil),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[]metricsdk.Record{},
|
|
|
|
[]metricpb.ResourceMetrics(nil),
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
msc.Reset()
|
2020-05-18 18:37:41 -07:00
|
|
|
require.NoError(t, exp.Export(context.Background(), &checkpointSet{records: test.records}))
|
2020-04-15 12:04:44 -07:00
|
|
|
assert.Equal(t, test.want, msc.ResourceMetrics())
|
|
|
|
}
|
|
|
|
}
|