2020-04-15 21:04:44 +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 otlp
import (
"context"
2020-05-19 03:37:41 +02:00
"sync"
2020-04-15 21:04:44 +02:00
"testing"
colmetricpb "github.com/open-telemetry/opentelemetry-proto/gen/go/collector/metrics/v1"
commonpb "github.com/open-telemetry/opentelemetry-proto/gen/go/common/v1"
metricpb "github.com/open-telemetry/opentelemetry-proto/gen/go/metrics/v1"
resourcepb "github.com/open-telemetry/opentelemetry-proto/gen/go/resource/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
2020-05-14 01:06:03 +02:00
"go.opentelemetry.io/otel/api/kv"
2020-04-23 21:10:58 +02:00
"go.opentelemetry.io/otel/api/label"
2020-04-15 21:04:44 +02:00
"go.opentelemetry.io/otel/api/metric"
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
"go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount"
"go.opentelemetry.io/otel/sdk/metric/aggregator/sum"
"go.opentelemetry.io/otel/sdk/resource"
"google.golang.org/grpc"
)
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-19 03:37:41 +02:00
sync . RWMutex
2020-04-15 21:04:44 +02:00
records [ ] metricsdk . Record
}
2020-05-19 03:37:41 +02:00
func ( m * checkpointSet ) ForEach ( fn func ( metricsdk . Record ) error ) error {
2020-04-15 21:04:44 +02:00
for _ , r := range m . records {
if err := fn ( r ) ; err != nil && err != aggregator . ErrNoData {
return err
}
}
return nil
}
type record struct {
2020-04-24 18:44:21 +02:00
name string
mKind metric . Kind
2020-05-11 08:44:42 +02:00
nKind metric . NumberKind
2020-04-24 18:44:21 +02:00
resource * resource . Resource
opts [ ] metric . Option
2020-05-14 01:06:03 +02:00
labels [ ] kv . KeyValue
2020-04-15 21:04:44 +02:00
}
var (
2020-05-14 01:06:03 +02:00
baseKeyValues = [ ] kv . KeyValue { kv . String ( "host" , "test.com" ) }
cpuKey = kv . Key ( "CPU" )
2020-04-15 21:04:44 +02:00
2020-05-14 01:06:03 +02:00
testInstA = resource . New ( kv . String ( "instance" , "tester-a" ) )
testInstB = resource . New ( kv . String ( "instance" , "tester-b" ) )
2020-04-15 21:04:44 +02:00
cpu1MD = & metricpb . MetricDescriptor {
Name : "int64-count" ,
Type : metricpb . MetricDescriptor_COUNTER_INT64 ,
Labels : [ ] * commonpb . StringKeyValue {
{
Key : "CPU" ,
Value : "1" ,
} ,
2020-04-23 21:10:58 +02:00
{
Key : "host" ,
Value : "test.com" ,
} ,
2020-04-15 21:04:44 +02:00
} ,
}
cpu2MD = & metricpb . MetricDescriptor {
Name : "int64-count" ,
Type : metricpb . MetricDescriptor_COUNTER_INT64 ,
Labels : [ ] * commonpb . StringKeyValue {
{
Key : "CPU" ,
Value : "2" ,
} ,
2020-04-23 21:10:58 +02:00
{
Key : "host" ,
Value : "test.com" ,
} ,
2020-04-15 21:04:44 +02:00
} ,
}
testerAResource = & resourcepb . Resource {
Attributes : [ ] * commonpb . AttributeKeyValue {
{
Key : "instance" ,
Type : commonpb . AttributeKeyValue_STRING ,
StringValue : "tester-a" ,
} ,
} ,
}
testerBResource = & resourcepb . Resource {
Attributes : [ ] * commonpb . AttributeKeyValue {
{
Key : "instance" ,
Type : commonpb . AttributeKeyValue_STRING ,
StringValue : "tester-b" ,
} ,
} ,
}
)
func TestNoGroupingExport ( t * testing . T ) {
runMetricExportTests (
t ,
[ ] record {
{
"int64-count" ,
metric . CounterKind ,
2020-05-11 08:44:42 +02:00
metric . Int64NumberKind ,
2020-04-24 18:44:21 +02:00
nil ,
nil ,
2020-04-15 21:04:44 +02:00
append ( baseKeyValues , cpuKey . Int ( 1 ) ) ,
} ,
{
"int64-count" ,
metric . CounterKind ,
2020-05-11 08:44:42 +02:00
metric . Int64NumberKind ,
2020-04-24 18:44:21 +02:00
nil ,
nil ,
2020-04-15 21:04:44 +02:00
append ( baseKeyValues , cpuKey . Int ( 2 ) ) ,
} ,
} ,
[ ] metricpb . ResourceMetrics {
{
2020-04-23 21:10:58 +02:00
Resource : nil ,
2020-04-15 21:04:44 +02:00
InstrumentationLibraryMetrics : [ ] * metricpb . InstrumentationLibraryMetrics {
{
Metrics : [ ] * metricpb . Metric {
{
MetricDescriptor : cpu1MD ,
Int64DataPoints : [ ] * metricpb . Int64DataPoint {
{
Value : 11 ,
} ,
} ,
} ,
{
MetricDescriptor : cpu2MD ,
Int64DataPoints : [ ] * metricpb . Int64DataPoint {
{
Value : 11 ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
)
}
2020-05-16 07:11:12 +02:00
func TestValuerecorderMetricGroupingExport ( t * testing . T ) {
2020-04-15 21:04:44 +02:00
r := record {
2020-05-16 07:11:12 +02:00
"valuerecorder" ,
metric . ValueRecorderKind ,
2020-05-11 08:44:42 +02:00
metric . Int64NumberKind ,
2020-04-24 18:44:21 +02:00
nil ,
nil ,
2020-04-15 21:04:44 +02:00
append ( baseKeyValues , cpuKey . Int ( 1 ) ) ,
}
expected := [ ] metricpb . ResourceMetrics {
{
2020-04-23 21:10:58 +02:00
Resource : nil ,
2020-04-15 21:04:44 +02:00
InstrumentationLibraryMetrics : [ ] * metricpb . InstrumentationLibraryMetrics {
{
Metrics : [ ] * metricpb . Metric {
{
MetricDescriptor : & metricpb . MetricDescriptor {
2020-05-16 07:11:12 +02:00
Name : "valuerecorder" ,
2020-04-15 21:04:44 +02:00
Type : metricpb . MetricDescriptor_SUMMARY ,
Labels : [ ] * commonpb . StringKeyValue {
{
Key : "CPU" ,
Value : "1" ,
} ,
2020-04-23 21:10:58 +02:00
{
Key : "host" ,
Value : "test.com" ,
} ,
2020-04-15 21:04:44 +02:00
} ,
} ,
SummaryDataPoints : [ ] * metricpb . SummaryDataPoint {
{
Count : 2 ,
Sum : 11 ,
PercentileValues : [ ] * metricpb . SummaryDataPoint_ValueAtPercentile {
{
Percentile : 0.0 ,
Value : 1.0 ,
} ,
{
Percentile : 100.0 ,
Value : 10.0 ,
} ,
} ,
} ,
{
Count : 2 ,
Sum : 11 ,
PercentileValues : [ ] * metricpb . SummaryDataPoint_ValueAtPercentile {
{
Percentile : 0.0 ,
Value : 1.0 ,
} ,
{
Percentile : 100.0 ,
Value : 10.0 ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
}
runMetricExportTests ( t , [ ] record { r , r } , expected )
//changing the number kind should make no difference.
2020-05-11 08:44:42 +02:00
r . nKind = metric . Uint64NumberKind
2020-04-15 21:04:44 +02:00
runMetricExportTests ( t , [ ] record { r , r } , expected )
2020-05-11 08:44:42 +02:00
r . nKind = metric . Float64NumberKind
2020-04-15 21:04:44 +02:00
runMetricExportTests ( t , [ ] record { r , r } , expected )
}
func TestCountInt64MetricGroupingExport ( t * testing . T ) {
r := record {
"int64-count" ,
metric . CounterKind ,
2020-05-11 08:44:42 +02:00
metric . Int64NumberKind ,
2020-04-24 18:44:21 +02:00
nil ,
nil ,
2020-04-15 21:04:44 +02:00
append ( baseKeyValues , cpuKey . Int ( 1 ) ) ,
}
runMetricExportTests (
t ,
[ ] record { r , r } ,
[ ] metricpb . ResourceMetrics {
{
2020-04-23 21:10:58 +02:00
Resource : nil ,
2020-04-15 21:04:44 +02:00
InstrumentationLibraryMetrics : [ ] * metricpb . InstrumentationLibraryMetrics {
{
Metrics : [ ] * metricpb . Metric {
{
MetricDescriptor : cpu1MD ,
Int64DataPoints : [ ] * metricpb . Int64DataPoint {
{
Value : 11 ,
} ,
{
Value : 11 ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
)
}
func TestCountUint64MetricGroupingExport ( t * testing . T ) {
r := record {
"uint64-count" ,
metric . CounterKind ,
2020-05-11 08:44:42 +02:00
metric . Uint64NumberKind ,
2020-04-24 18:44:21 +02:00
nil ,
nil ,
2020-04-15 21:04:44 +02:00
append ( baseKeyValues , cpuKey . Int ( 1 ) ) ,
}
runMetricExportTests (
t ,
[ ] record { r , r } ,
[ ] metricpb . ResourceMetrics {
{
2020-04-23 21:10:58 +02:00
Resource : nil ,
2020-04-15 21:04:44 +02:00
InstrumentationLibraryMetrics : [ ] * metricpb . InstrumentationLibraryMetrics {
{
Metrics : [ ] * metricpb . Metric {
{
MetricDescriptor : & metricpb . MetricDescriptor {
Name : "uint64-count" ,
Type : metricpb . MetricDescriptor_COUNTER_INT64 ,
Labels : [ ] * commonpb . StringKeyValue {
{
Key : "CPU" ,
Value : "1" ,
} ,
2020-04-23 21:10:58 +02:00
{
Key : "host" ,
Value : "test.com" ,
} ,
2020-04-15 21:04:44 +02:00
} ,
} ,
Int64DataPoints : [ ] * metricpb . Int64DataPoint {
{
Value : 11 ,
} ,
{
Value : 11 ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
)
}
func TestCountFloat64MetricGroupingExport ( t * testing . T ) {
r := record {
"float64-count" ,
metric . CounterKind ,
2020-05-11 08:44:42 +02:00
metric . Float64NumberKind ,
2020-04-24 18:44:21 +02:00
nil ,
nil ,
2020-04-15 21:04:44 +02:00
append ( baseKeyValues , cpuKey . Int ( 1 ) ) ,
}
runMetricExportTests (
t ,
[ ] record { r , r } ,
[ ] metricpb . ResourceMetrics {
{
2020-04-23 21:10:58 +02:00
Resource : nil ,
2020-04-15 21:04:44 +02:00
InstrumentationLibraryMetrics : [ ] * metricpb . InstrumentationLibraryMetrics {
{
Metrics : [ ] * metricpb . Metric {
{
MetricDescriptor : & metricpb . MetricDescriptor {
Name : "float64-count" ,
Type : metricpb . MetricDescriptor_COUNTER_DOUBLE ,
Labels : [ ] * commonpb . StringKeyValue {
{
Key : "CPU" ,
Value : "1" ,
} ,
2020-04-23 21:10:58 +02:00
{
Key : "host" ,
Value : "test.com" ,
} ,
2020-04-15 21:04:44 +02:00
} ,
} ,
DoubleDataPoints : [ ] * metricpb . DoubleDataPoint {
{
Value : 11 ,
} ,
{
Value : 11 ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
)
}
func TestResourceMetricGroupingExport ( t * testing . T ) {
runMetricExportTests (
t ,
[ ] record {
{
"int64-count" ,
metric . CounterKind ,
2020-05-11 08:44:42 +02:00
metric . Int64NumberKind ,
2020-04-24 18:44:21 +02:00
testInstA ,
nil ,
2020-04-15 21:04:44 +02:00
append ( baseKeyValues , cpuKey . Int ( 1 ) ) ,
} ,
{
"int64-count" ,
metric . CounterKind ,
2020-05-11 08:44:42 +02:00
metric . Int64NumberKind ,
2020-04-24 18:44:21 +02:00
testInstA ,
nil ,
2020-04-15 21:04:44 +02:00
append ( baseKeyValues , cpuKey . Int ( 1 ) ) ,
} ,
{
"int64-count" ,
metric . CounterKind ,
2020-05-11 08:44:42 +02:00
metric . Int64NumberKind ,
2020-04-24 18:44:21 +02:00
testInstA ,
nil ,
2020-04-15 21:04:44 +02:00
append ( baseKeyValues , cpuKey . Int ( 2 ) ) ,
} ,
{
"int64-count" ,
metric . CounterKind ,
2020-05-11 08:44:42 +02:00
metric . Int64NumberKind ,
2020-04-24 18:44:21 +02:00
testInstB ,
nil ,
2020-04-15 21:04:44 +02:00
append ( baseKeyValues , cpuKey . Int ( 1 ) ) ,
} ,
} ,
[ ] metricpb . ResourceMetrics {
{
Resource : testerAResource ,
InstrumentationLibraryMetrics : [ ] * metricpb . InstrumentationLibraryMetrics {
{
Metrics : [ ] * metricpb . Metric {
{
MetricDescriptor : cpu1MD ,
Int64DataPoints : [ ] * metricpb . Int64DataPoint {
{
Value : 11 ,
} ,
{
Value : 11 ,
} ,
} ,
} ,
{
MetricDescriptor : cpu2MD ,
Int64DataPoints : [ ] * metricpb . Int64DataPoint {
{
Value : 11 ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
{
Resource : testerBResource ,
InstrumentationLibraryMetrics : [ ] * metricpb . InstrumentationLibraryMetrics {
{
Metrics : [ ] * metricpb . Metric {
{
MetricDescriptor : cpu1MD ,
Int64DataPoints : [ ] * metricpb . Int64DataPoint {
{
Value : 11 ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
)
}
func TestResourceInstLibMetricGroupingExport ( t * testing . T ) {
runMetricExportTests (
t ,
[ ] record {
{
"int64-count" ,
metric . CounterKind ,
2020-05-11 08:44:42 +02:00
metric . Int64NumberKind ,
2020-04-24 18:44:21 +02:00
testInstA ,
2020-04-15 21:04:44 +02:00
[ ] metric . Option {
metric . WithLibraryName ( "couting-lib" ) ,
} ,
append ( baseKeyValues , cpuKey . Int ( 1 ) ) ,
} ,
{
"int64-count" ,
metric . CounterKind ,
2020-05-11 08:44:42 +02:00
metric . Int64NumberKind ,
2020-04-24 18:44:21 +02:00
testInstA ,
2020-04-15 21:04:44 +02:00
[ ] metric . Option {
metric . WithLibraryName ( "couting-lib" ) ,
} ,
append ( baseKeyValues , cpuKey . Int ( 1 ) ) ,
} ,
{
"int64-count" ,
metric . CounterKind ,
2020-05-11 08:44:42 +02:00
metric . Int64NumberKind ,
2020-04-24 18:44:21 +02:00
testInstA ,
2020-04-15 21:04:44 +02:00
[ ] metric . Option {
metric . WithLibraryName ( "couting-lib" ) ,
} ,
append ( baseKeyValues , cpuKey . Int ( 2 ) ) ,
} ,
{
"int64-count" ,
metric . CounterKind ,
2020-05-11 08:44:42 +02:00
metric . Int64NumberKind ,
2020-04-24 18:44:21 +02:00
testInstA ,
2020-04-15 21:04:44 +02:00
[ ] metric . Option {
metric . WithLibraryName ( "summing-lib" ) ,
} ,
append ( baseKeyValues , cpuKey . Int ( 1 ) ) ,
} ,
{
"int64-count" ,
metric . CounterKind ,
2020-05-11 08:44:42 +02:00
metric . Int64NumberKind ,
2020-04-24 18:44:21 +02:00
testInstB ,
2020-04-15 21:04:44 +02:00
[ ] metric . Option {
metric . WithLibraryName ( "couting-lib" ) ,
} ,
append ( baseKeyValues , cpuKey . Int ( 1 ) ) ,
} ,
} ,
[ ] metricpb . ResourceMetrics {
{
Resource : testerAResource ,
InstrumentationLibraryMetrics : [ ] * metricpb . InstrumentationLibraryMetrics {
{
InstrumentationLibrary : & commonpb . InstrumentationLibrary {
Name : "couting-lib" ,
} ,
Metrics : [ ] * metricpb . Metric {
{
MetricDescriptor : cpu1MD ,
Int64DataPoints : [ ] * metricpb . Int64DataPoint {
{
Value : 11 ,
} ,
{
Value : 11 ,
} ,
} ,
} ,
{
MetricDescriptor : cpu2MD ,
Int64DataPoints : [ ] * metricpb . Int64DataPoint {
{
Value : 11 ,
} ,
} ,
} ,
} ,
} ,
{
InstrumentationLibrary : & commonpb . InstrumentationLibrary {
Name : "summing-lib" ,
} ,
Metrics : [ ] * metricpb . Metric {
{
MetricDescriptor : cpu1MD ,
Int64DataPoints : [ ] * metricpb . Int64DataPoint {
{
Value : 11 ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
{
Resource : testerBResource ,
InstrumentationLibraryMetrics : [ ] * metricpb . InstrumentationLibraryMetrics {
{
InstrumentationLibrary : & commonpb . InstrumentationLibrary {
Name : "couting-lib" ,
} ,
Metrics : [ ] * metricpb . Metric {
{
MetricDescriptor : cpu1MD ,
Int64DataPoints : [ ] * metricpb . Int64DataPoint {
{
Value : 11 ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
)
}
// What works single-threaded should work multi-threaded
func runMetricExportTests ( t * testing . T , rs [ ] record , expected [ ] metricpb . ResourceMetrics ) {
t . Run ( "1 goroutine" , func ( t * testing . T ) {
runMetricExportTest ( t , NewUnstartedExporter ( WorkerCount ( 1 ) ) , rs , expected )
} )
t . Run ( "20 goroutines" , func ( t * testing . T ) {
runMetricExportTest ( t , NewUnstartedExporter ( WorkerCount ( 20 ) ) , rs , expected )
} )
}
func runMetricExportTest ( t * testing . T , exp * Exporter , rs [ ] record , expected [ ] metricpb . ResourceMetrics ) {
msc := & metricsServiceClientStub { }
exp . metricExporter = msc
exp . started = true
2020-04-24 18:44:21 +02:00
recs := map [ label . Distinct ] [ ] metricsdk . Record { }
resources := map [ label . Distinct ] * resource . Resource { }
2020-04-15 21:04:44 +02:00
for _ , r := range rs {
desc := metric . NewDescriptor ( r . name , r . mKind , r . nKind , r . opts ... )
2020-04-23 21:10:58 +02:00
labs := label . NewSet ( r . labels ... )
2020-04-15 21:04:44 +02:00
var agg metricsdk . Aggregator
switch r . mKind {
case metric . CounterKind :
agg = sum . New ( )
default :
agg = minmaxsumcount . New ( & desc )
}
ctx := context . Background ( )
switch r . nKind {
2020-05-11 08:44:42 +02:00
case metric . Uint64NumberKind :
require . NoError ( t , agg . Update ( ctx , metric . NewUint64Number ( 1 ) , & desc ) )
require . NoError ( t , agg . Update ( ctx , metric . NewUint64Number ( 10 ) , & desc ) )
case metric . Int64NumberKind :
require . NoError ( t , agg . Update ( ctx , metric . NewInt64Number ( 1 ) , & desc ) )
require . NoError ( t , agg . Update ( ctx , metric . NewInt64Number ( 10 ) , & desc ) )
case metric . Float64NumberKind :
require . NoError ( t , agg . Update ( ctx , metric . NewFloat64Number ( 1 ) , & desc ) )
require . NoError ( t , agg . Update ( ctx , metric . NewFloat64Number ( 10 ) , & desc ) )
2020-04-15 21:04:44 +02:00
default :
t . Fatalf ( "invalid number kind: %v" , r . nKind )
}
agg . Checkpoint ( ctx , & desc )
2020-04-24 18:44:21 +02:00
equiv := r . resource . Equivalent ( )
resources [ equiv ] = r . resource
2020-05-19 02:44:28 +02:00
recs [ equiv ] = append ( recs [ equiv ] , metricsdk . NewRecord ( & desc , & labs , r . resource , agg ) )
2020-04-24 18:44:21 +02:00
}
2020-05-19 02:44:28 +02:00
for _ , records := range recs {
2020-05-19 03:37:41 +02:00
assert . NoError ( t , exp . Export ( context . Background ( ) , & checkpointSet { records : records } ) )
2020-04-15 21:04:44 +02: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
}
assert . ElementsMatch ( t , ilm . GetMetrics ( ) , g , "metrics did not match for:\n\tResource: %s\n\tInstrumentationLibrary: %s\n" , k . resource , k . instrumentationLibrary )
}
}
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-19 03:37:41 +02:00
require . NoError ( t , exp . Export ( context . Background ( ) , & checkpointSet { records : test . records } ) )
2020-04-15 21:04:44 +02:00
assert . Equal ( t , test . want , msc . ResourceMetrics ( ) )
}
}