From 62bbea0a5048a5caa92ba551ed18919d46ddef9c Mon Sep 17 00:00:00 2001 From: JBD Date: Wed, 21 Apr 2021 11:56:41 -0700 Subject: [PATCH] Don't drop instance and job labels in the Prometheus Remote Write Exporter This is a follow up to #2897. Fixes #575 Fixes #2499 Fixes #2363 Fixes open-telemetry/wg-prometheus#37 Fixes open-telemetry/wg-prometheus#39 Fixes open-telemetry/wg-prometheus#44 Passing compliance tests: $ go test --tags=compliance -run "TestRemoteWrite/otelcollector/Job.+" -v ./ === RUN TestRemoteWrite === RUN TestRemoteWrite/otelcollector === RUN TestRemoteWrite/otelcollector/JobLabel === PAUSE TestRemoteWrite/otelcollector/JobLabel === CONT TestRemoteWrite/otelcollector/JobLabel --- PASS: TestRemoteWrite (10.02s) --- PASS: TestRemoteWrite/otelcollector (0.00s) --- PASS: TestRemoteWrite/otelcollector/JobLabel (10.02s) PASS ok github.com/prometheus/compliance/remote_write 10.382s $ go test --tags=compliance -run "TestRemoteWrite/otelcollector/Instance.+" -v ./ === RUN TestRemoteWrite === RUN TestRemoteWrite/otelcollector === RUN TestRemoteWrite/otelcollector/InstanceLabel === PAUSE TestRemoteWrite/otelcollector/InstanceLabel === CONT TestRemoteWrite/otelcollector/InstanceLabel --- PASS: TestRemoteWrite (10.01s) --- PASS: TestRemoteWrite/otelcollector (0.00s) --- PASS: TestRemoteWrite/otelcollector/InstanceLabel (10.01s) PASS ok github.com/prometheus/compliance/remote_write 10.291s $ go test --tags=compliance -run "TestRemoteWrite/otelcollector/RepeatedLabels.+" -v ./ === RUN TestRemoteWrite === RUN TestRemoteWrite/otelcollector --- PASS: TestRemoteWrite (0.00s) --- PASS: TestRemoteWrite/otelcollector (0.00s) testing: warning: no tests to run PASS --- .../prometheusremotewriteexporter/exporter.go | 30 +++++---- .../prometheusremotewriteexporter/helper.go | 63 +++++++++++++------ .../helper_test.go | 47 +++++++++++++- 3 files changed, 107 insertions(+), 33 deletions(-) diff --git a/exporter/prometheusremotewriteexporter/exporter.go b/exporter/prometheusremotewriteexporter/exporter.go index 770e1f2e730..2838e97fe63 100644 --- a/exporter/prometheusremotewriteexporter/exporter.go +++ b/exporter/prometheusremotewriteexporter/exporter.go @@ -35,6 +35,7 @@ import ( "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/internal" otlp "go.opentelemetry.io/collector/internal/data/protogen/metrics/v1" + resourcev1 "go.opentelemetry.io/collector/internal/data/protogen/resource/v1" "go.opentelemetry.io/collector/internal/version" ) @@ -107,6 +108,8 @@ func (prwe *PrwExporter) PushMetrics(ctx context.Context, md pdata.Metrics) erro if resourceMetric == nil { continue } + + resource := resourceMetric.Resource // TODO: add resource attributes as labels, probably in next PR for _, instrumentationMetrics := range resourceMetric.InstrumentationLibraryMetrics { if instrumentationMetrics == nil { @@ -124,20 +127,21 @@ func (prwe *PrwExporter) PushMetrics(ctx context.Context, md pdata.Metrics) erro errs = append(errs, consumererror.Permanent(errors.New("invalid temporality and type combination"))) continue } + // handle individual metric based on type switch metric.Data.(type) { case *otlp.Metric_DoubleSum, *otlp.Metric_IntSum, *otlp.Metric_DoubleGauge, *otlp.Metric_IntGauge: - if err := prwe.handleScalarMetric(tsMap, metric); err != nil { + if err := prwe.handleScalarMetric(tsMap, resource, metric); err != nil { dropped++ errs = append(errs, consumererror.Permanent(err)) } case *otlp.Metric_DoubleHistogram, *otlp.Metric_IntHistogram: - if err := prwe.handleHistogramMetric(tsMap, metric); err != nil { + if err := prwe.handleHistogramMetric(tsMap, resource, metric); err != nil { dropped++ errs = append(errs, consumererror.Permanent(err)) } case *otlp.Metric_DoubleSummary: - if err := prwe.handleSummaryMetric(tsMap, metric); err != nil { + if err := prwe.handleSummaryMetric(tsMap, resource, metric); err != nil { dropped++ errs = append(errs, consumererror.Permanent(err)) } @@ -184,7 +188,7 @@ func validateAndSanitizeExternalLabels(externalLabels map[string]string) (map[st // handleScalarMetric processes data points in a single OTLP scalar metric by adding the each point as a Sample into // its corresponding TimeSeries in tsMap. // tsMap and metric cannot be nil, and metric must have a non-nil descriptor -func (prwe *PrwExporter) handleScalarMetric(tsMap map[string]*prompb.TimeSeries, metric *otlp.Metric) error { +func (prwe *PrwExporter) handleScalarMetric(tsMap map[string]*prompb.TimeSeries, resource resourcev1.Resource, metric *otlp.Metric) error { switch metric.Data.(type) { // int points case *otlp.Metric_DoubleGauge: @@ -192,28 +196,28 @@ func (prwe *PrwExporter) handleScalarMetric(tsMap map[string]*prompb.TimeSeries, return fmt.Errorf("nil data point. %s is dropped", metric.GetName()) } for _, pt := range metric.GetDoubleGauge().GetDataPoints() { - addSingleDoubleDataPoint(pt, metric, prwe.namespace, tsMap, prwe.externalLabels) + addSingleDoubleDataPoint(pt, resource, metric, prwe.namespace, tsMap, prwe.externalLabels) } case *otlp.Metric_IntGauge: if metric.GetIntGauge().GetDataPoints() == nil { return fmt.Errorf("nil data point. %s is dropped", metric.GetName()) } for _, pt := range metric.GetIntGauge().GetDataPoints() { - addSingleIntDataPoint(pt, metric, prwe.namespace, tsMap, prwe.externalLabels) + addSingleIntDataPoint(pt, resource, metric, prwe.namespace, tsMap, prwe.externalLabels) } case *otlp.Metric_DoubleSum: if metric.GetDoubleSum().GetDataPoints() == nil { return fmt.Errorf("nil data point. %s is dropped", metric.GetName()) } for _, pt := range metric.GetDoubleSum().GetDataPoints() { - addSingleDoubleDataPoint(pt, metric, prwe.namespace, tsMap, prwe.externalLabels) + addSingleDoubleDataPoint(pt, resource, metric, prwe.namespace, tsMap, prwe.externalLabels) } case *otlp.Metric_IntSum: if metric.GetIntSum().GetDataPoints() == nil { return fmt.Errorf("nil data point. %s is dropped", metric.GetName()) } for _, pt := range metric.GetIntSum().GetDataPoints() { - addSingleIntDataPoint(pt, metric, prwe.namespace, tsMap, prwe.externalLabels) + addSingleIntDataPoint(pt, resource, metric, prwe.namespace, tsMap, prwe.externalLabels) } } return nil @@ -222,21 +226,21 @@ func (prwe *PrwExporter) handleScalarMetric(tsMap map[string]*prompb.TimeSeries, // handleHistogramMetric processes data points in a single OTLP histogram metric by mapping the sum, count and each // bucket of every data point as a Sample, and adding each Sample to its corresponding TimeSeries. // tsMap and metric cannot be nil. -func (prwe *PrwExporter) handleHistogramMetric(tsMap map[string]*prompb.TimeSeries, metric *otlp.Metric) error { +func (prwe *PrwExporter) handleHistogramMetric(tsMap map[string]*prompb.TimeSeries, resource resourcev1.Resource, metric *otlp.Metric) error { switch metric.Data.(type) { case *otlp.Metric_IntHistogram: if metric.GetIntHistogram().GetDataPoints() == nil { return fmt.Errorf("nil data point. %s is dropped", metric.GetName()) } for _, pt := range metric.GetIntHistogram().GetDataPoints() { - addSingleIntHistogramDataPoint(pt, metric, prwe.namespace, tsMap, prwe.externalLabels) + addSingleIntHistogramDataPoint(pt, resource, metric, prwe.namespace, tsMap, prwe.externalLabels) } case *otlp.Metric_DoubleHistogram: if metric.GetDoubleHistogram().GetDataPoints() == nil { return fmt.Errorf("nil data point. %s is dropped", metric.GetName()) } for _, pt := range metric.GetDoubleHistogram().GetDataPoints() { - addSingleDoubleHistogramDataPoint(pt, metric, prwe.namespace, tsMap, prwe.externalLabels) + addSingleDoubleHistogramDataPoint(pt, resource, metric, prwe.namespace, tsMap, prwe.externalLabels) } } return nil @@ -245,12 +249,12 @@ func (prwe *PrwExporter) handleHistogramMetric(tsMap map[string]*prompb.TimeSeri // handleSummaryMetric processes data points in a single OTLP summary metric by mapping the sum, count and each // quantile of every data point as a Sample, and adding each Sample to its corresponding TimeSeries. // tsMap and metric cannot be nil. -func (prwe *PrwExporter) handleSummaryMetric(tsMap map[string]*prompb.TimeSeries, metric *otlp.Metric) error { +func (prwe *PrwExporter) handleSummaryMetric(tsMap map[string]*prompb.TimeSeries, resource resourcev1.Resource, metric *otlp.Metric) error { if metric.GetDoubleSummary().GetDataPoints() == nil { return fmt.Errorf("nil data point. %s is dropped", metric.GetName()) } for _, pt := range metric.GetDoubleSummary().GetDataPoints() { - addSingleDoubleSummaryDataPoint(pt, metric, prwe.namespace, tsMap, prwe.externalLabels) + addSingleDoubleSummaryDataPoint(pt, resource, metric, prwe.namespace, tsMap, prwe.externalLabels) } return nil } diff --git a/exporter/prometheusremotewriteexporter/helper.go b/exporter/prometheusremotewriteexporter/helper.go index 43e6632515b..2a5df623a11 100644 --- a/exporter/prometheusremotewriteexporter/helper.go +++ b/exporter/prometheusremotewriteexporter/helper.go @@ -23,11 +23,13 @@ import ( "time" "unicode" + "github.com/prometheus/common/model" "github.com/prometheus/prometheus/prompb" "go.opentelemetry.io/collector/consumer/pdata" common "go.opentelemetry.io/collector/internal/data/protogen/common/v1" otlp "go.opentelemetry.io/collector/internal/data/protogen/metrics/v1" + resourcev1 "go.opentelemetry.io/collector/internal/data/protogen/resource/v1" ) const ( @@ -125,7 +127,7 @@ func timeSeriesSignature(metric *otlp.Metric, labels *[]prompb.Label) string { // createLabelSet creates a slice of Cortex Label with OTLP labels and paris of string values. // Unpaired string value is ignored. String pairs overwrites OTLP labels if collision happens, and the overwrite is // logged. Resultant label names are sanitized. -func createLabelSet(labels []common.StringKeyValue, externalLabels map[string]string, extras ...string) []prompb.Label { +func createLabelSet(resource resourcev1.Resource, labels []common.StringKeyValue, externalLabels map[string]string, extras ...string) []prompb.Label { // map ensures no duplicate label name l := map[string]prompb.Label{} @@ -137,6 +139,15 @@ func createLabelSet(labels []common.StringKeyValue, externalLabels map[string]st } } + for _, attr := range resource.Attributes { + if isUsefulResourceAttribute(attr) { + l[attr.Key] = prompb.Label{ + Name: sanitize(attr.Key), + Value: attr.Value.GetStringValue(), // TODO(jbd): Decide what to do with non-string attributes. + } + } + } + for _, lb := range labels { l[lb.Key] = prompb.Label{ Name: sanitize(lb.Key), @@ -171,6 +182,20 @@ func createLabelSet(labels []common.StringKeyValue, externalLabels map[string]st return s } +func isUsefulResourceAttribute(attr common.KeyValue) bool { + // TODO(jbd): Allow users to configure what other resource + // attributes to be included. + // Decide what to do with non-string attributes. + // We should always output "job" and "instance". + switch attr.Key { + case model.InstanceLabel: + return true + case model.JobLabel: + return true + } + return false +} + // getPromMetricName creates a Prometheus metric name by attaching namespace prefix, and _total suffix for Monotonic // metrics. func getPromMetricName(metric *otlp.Metric, ns string) string { @@ -296,14 +321,14 @@ func getTypeString(metric *otlp.Metric) string { // addSingleDoubleDataPoint converts the metric value stored in pt to a Prometheus sample, and add the sample // to its corresponding time series in tsMap -func addSingleDoubleDataPoint(pt *otlp.DoubleDataPoint, metric *otlp.Metric, namespace string, +func addSingleDoubleDataPoint(pt *otlp.DoubleDataPoint, resource resourcev1.Resource, metric *otlp.Metric, namespace string, tsMap map[string]*prompb.TimeSeries, externalLabels map[string]string) { if pt == nil { return } // create parameters for addSample name := getPromMetricName(metric, namespace) - labels := createLabelSet(pt.GetLabels(), externalLabels, nameStr, name) + labels := createLabelSet(resource, pt.GetLabels(), externalLabels, nameStr, name) sample := &prompb.Sample{ Value: pt.Value, // convert ns to ms @@ -314,14 +339,14 @@ func addSingleDoubleDataPoint(pt *otlp.DoubleDataPoint, metric *otlp.Metric, nam // addSingleIntDataPoint converts the metric value stored in pt to a Prometheus sample, and add the sample // to its corresponding time series in tsMap -func addSingleIntDataPoint(pt *otlp.IntDataPoint, metric *otlp.Metric, namespace string, +func addSingleIntDataPoint(pt *otlp.IntDataPoint, resource resourcev1.Resource, metric *otlp.Metric, namespace string, tsMap map[string]*prompb.TimeSeries, externalLabels map[string]string) { if pt == nil { return } // create parameters for addSample name := getPromMetricName(metric, namespace) - labels := createLabelSet(pt.GetLabels(), externalLabels, nameStr, name) + labels := createLabelSet(resource, pt.GetLabels(), externalLabels, nameStr, name) sample := &prompb.Sample{ Value: float64(pt.Value), // convert ns to ms @@ -332,7 +357,7 @@ func addSingleIntDataPoint(pt *otlp.IntDataPoint, metric *otlp.Metric, namespace // addSingleIntHistogramDataPoint converts pt to 2 + min(len(ExplicitBounds), len(BucketCount)) + 1 samples. It // ignore extra buckets if len(ExplicitBounds) > len(BucketCounts) -func addSingleIntHistogramDataPoint(pt *otlp.IntHistogramDataPoint, metric *otlp.Metric, namespace string, +func addSingleIntHistogramDataPoint(pt *otlp.IntHistogramDataPoint, resource resourcev1.Resource, metric *otlp.Metric, namespace string, tsMap map[string]*prompb.TimeSeries, externalLabels map[string]string) { if pt == nil { return @@ -346,7 +371,7 @@ func addSingleIntHistogramDataPoint(pt *otlp.IntHistogramDataPoint, metric *otlp Timestamp: time, } - sumlabels := createLabelSet(pt.GetLabels(), externalLabels, nameStr, baseName+sumStr) + sumlabels := createLabelSet(resource, pt.GetLabels(), externalLabels, nameStr, baseName+sumStr) addSample(tsMap, sum, sumlabels, metric) // treat count as a sample in an individual TimeSeries @@ -354,7 +379,7 @@ func addSingleIntHistogramDataPoint(pt *otlp.IntHistogramDataPoint, metric *otlp Value: float64(pt.GetCount()), Timestamp: time, } - countlabels := createLabelSet(pt.GetLabels(), externalLabels, nameStr, baseName+countStr) + countlabels := createLabelSet(resource, pt.GetLabels(), externalLabels, nameStr, baseName+countStr) addSample(tsMap, count, countlabels, metric) // cumulative count for conversion to cumulative histogram @@ -371,7 +396,7 @@ func addSingleIntHistogramDataPoint(pt *otlp.IntHistogramDataPoint, metric *otlp Timestamp: time, } boundStr := strconv.FormatFloat(bound, 'f', -1, 64) - labels := createLabelSet(pt.GetLabels(), externalLabels, nameStr, baseName+bucketStr, leStr, boundStr) + labels := createLabelSet(resource, pt.GetLabels(), externalLabels, nameStr, baseName+bucketStr, leStr, boundStr) addSample(tsMap, bucket, labels, metric) } // add le=+Inf bucket @@ -380,13 +405,13 @@ func addSingleIntHistogramDataPoint(pt *otlp.IntHistogramDataPoint, metric *otlp Value: float64(cumulativeCount), Timestamp: time, } - infLabels := createLabelSet(pt.GetLabels(), externalLabels, nameStr, baseName+bucketStr, leStr, pInfStr) + infLabels := createLabelSet(resource, pt.GetLabels(), externalLabels, nameStr, baseName+bucketStr, leStr, pInfStr) addSample(tsMap, infBucket, infLabels, metric) } // addSingleDoubleHistogramDataPoint converts pt to 2 + min(len(ExplicitBounds), len(BucketCount)) + 1 samples. It // ignore extra buckets if len(ExplicitBounds) > len(BucketCounts) -func addSingleDoubleHistogramDataPoint(pt *otlp.DoubleHistogramDataPoint, metric *otlp.Metric, namespace string, +func addSingleDoubleHistogramDataPoint(pt *otlp.DoubleHistogramDataPoint, resource resourcev1.Resource, metric *otlp.Metric, namespace string, tsMap map[string]*prompb.TimeSeries, externalLabels map[string]string) { if pt == nil { return @@ -400,7 +425,7 @@ func addSingleDoubleHistogramDataPoint(pt *otlp.DoubleHistogramDataPoint, metric Timestamp: time, } - sumlabels := createLabelSet(pt.GetLabels(), externalLabels, nameStr, baseName+sumStr) + sumlabels := createLabelSet(resource, pt.GetLabels(), externalLabels, nameStr, baseName+sumStr) addSample(tsMap, sum, sumlabels, metric) // treat count as a sample in an individual TimeSeries @@ -408,7 +433,7 @@ func addSingleDoubleHistogramDataPoint(pt *otlp.DoubleHistogramDataPoint, metric Value: float64(pt.GetCount()), Timestamp: time, } - countlabels := createLabelSet(pt.GetLabels(), externalLabels, nameStr, baseName+countStr) + countlabels := createLabelSet(resource, pt.GetLabels(), externalLabels, nameStr, baseName+countStr) addSample(tsMap, count, countlabels, metric) // cumulative count for conversion to cumulative histogram @@ -425,7 +450,7 @@ func addSingleDoubleHistogramDataPoint(pt *otlp.DoubleHistogramDataPoint, metric Timestamp: time, } boundStr := strconv.FormatFloat(bound, 'f', -1, 64) - labels := createLabelSet(pt.GetLabels(), externalLabels, nameStr, baseName+bucketStr, leStr, boundStr) + labels := createLabelSet(resource, pt.GetLabels(), externalLabels, nameStr, baseName+bucketStr, leStr, boundStr) addSample(tsMap, bucket, labels, metric) } // add le=+Inf bucket @@ -434,12 +459,12 @@ func addSingleDoubleHistogramDataPoint(pt *otlp.DoubleHistogramDataPoint, metric Value: float64(cumulativeCount), Timestamp: time, } - infLabels := createLabelSet(pt.GetLabels(), externalLabels, nameStr, baseName+bucketStr, leStr, pInfStr) + infLabels := createLabelSet(resource, pt.GetLabels(), externalLabels, nameStr, baseName+bucketStr, leStr, pInfStr) addSample(tsMap, infBucket, infLabels, metric) } // addSingleDoubleSummaryDataPoint converts pt to len(QuantileValues) + 2 samples. -func addSingleDoubleSummaryDataPoint(pt *otlp.DoubleSummaryDataPoint, metric *otlp.Metric, namespace string, +func addSingleDoubleSummaryDataPoint(pt *otlp.DoubleSummaryDataPoint, resource resourcev1.Resource, metric *otlp.Metric, namespace string, tsMap map[string]*prompb.TimeSeries, externalLabels map[string]string) { if pt == nil { return @@ -453,7 +478,7 @@ func addSingleDoubleSummaryDataPoint(pt *otlp.DoubleSummaryDataPoint, metric *ot Timestamp: time, } - sumlabels := createLabelSet(pt.GetLabels(), externalLabels, nameStr, baseName+sumStr) + sumlabels := createLabelSet(resource, pt.GetLabels(), externalLabels, nameStr, baseName+sumStr) addSample(tsMap, sum, sumlabels, metric) // treat count as a sample in an individual TimeSeries @@ -461,7 +486,7 @@ func addSingleDoubleSummaryDataPoint(pt *otlp.DoubleSummaryDataPoint, metric *ot Value: float64(pt.GetCount()), Timestamp: time, } - countlabels := createLabelSet(pt.GetLabels(), externalLabels, nameStr, baseName+countStr) + countlabels := createLabelSet(resource, pt.GetLabels(), externalLabels, nameStr, baseName+countStr) addSample(tsMap, count, countlabels, metric) // process each percentile/quantile @@ -471,7 +496,7 @@ func addSingleDoubleSummaryDataPoint(pt *otlp.DoubleSummaryDataPoint, metric *ot Timestamp: time, } percentileStr := strconv.FormatFloat(qt.GetQuantile(), 'f', -1, 64) - qtlabels := createLabelSet(pt.GetLabels(), externalLabels, nameStr, baseName, quantileStr, percentileStr) + qtlabels := createLabelSet(resource, pt.GetLabels(), externalLabels, nameStr, baseName, quantileStr, percentileStr) addSample(tsMap, quantile, qtlabels, metric) } } diff --git a/exporter/prometheusremotewriteexporter/helper_test.go b/exporter/prometheusremotewriteexporter/helper_test.go index 4ed96c0a73d..ffb365a47ea 100644 --- a/exporter/prometheusremotewriteexporter/helper_test.go +++ b/exporter/prometheusremotewriteexporter/helper_test.go @@ -24,6 +24,7 @@ import ( "go.opentelemetry.io/collector/consumer/pdata" common "go.opentelemetry.io/collector/internal/data/protogen/common/v1" otlp "go.opentelemetry.io/collector/internal/data/protogen/metrics/v1" + resourcev1 "go.opentelemetry.io/collector/internal/data/protogen/resource/v1" ) // Test_validateMetrics checks validateMetrics return true if a type and temporality combination is valid, false @@ -185,6 +186,7 @@ func Test_timeSeriesSignature(t *testing.T) { func Test_createLabelSet(t *testing.T) { tests := []struct { name string + resource resourcev1.Resource orig []common.StringKeyValue externalLabels map[string]string extras []string @@ -192,13 +194,38 @@ func Test_createLabelSet(t *testing.T) { }{ { "labels_clean", + resourcev1.Resource{ + Attributes: []common.KeyValue{}, + }, lbs1, map[string]string{}, []string{label31, value31, label32, value32}, getPromLabels(label11, value11, label12, value12, label31, value31, label32, value32), }, + { + "labels_with_resource", + resourcev1.Resource{ + Attributes: []common.KeyValue{ + { + Key: "job", + Value: common.AnyValue{Value: &common.AnyValue_StringValue{StringValue: "prometheus"}}, + }, + { + Key: "instance", + Value: common.AnyValue{Value: &common.AnyValue_StringValue{StringValue: "127.0.0.1:8080"}}, + }, + }, + }, + lbs1, + map[string]string{}, + []string{label31, value31, label32, value32}, + getPromLabels(label11, value11, label12, value12, label31, value31, label32, value32, "job", "prometheus", "instance", "127.0.0.1:8080"), + }, { "labels_duplicate_in_extras", + resourcev1.Resource{ + Attributes: []common.KeyValue{}, + }, lbs1, map[string]string{}, []string{label11, value31}, @@ -206,6 +233,9 @@ func Test_createLabelSet(t *testing.T) { }, { "labels_dirty", + resourcev1.Resource{ + Attributes: []common.KeyValue{}, + }, lbs1Dirty, map[string]string{}, []string{label31 + dirty1, value31, label32, value32}, @@ -213,6 +243,9 @@ func Test_createLabelSet(t *testing.T) { }, { "no_original_case", + resourcev1.Resource{ + Attributes: []common.KeyValue{}, + }, nil, nil, []string{label31, value31, label32, value32}, @@ -220,6 +253,9 @@ func Test_createLabelSet(t *testing.T) { }, { "empty_extra_case", + resourcev1.Resource{ + Attributes: []common.KeyValue{}, + }, lbs1, map[string]string{}, []string{"", ""}, @@ -227,6 +263,9 @@ func Test_createLabelSet(t *testing.T) { }, { "single_left_over_case", + resourcev1.Resource{ + Attributes: []common.KeyValue{}, + }, lbs1, map[string]string{}, []string{label31, value31, label32}, @@ -234,6 +273,9 @@ func Test_createLabelSet(t *testing.T) { }, { "valid_external_labels", + resourcev1.Resource{ + Attributes: []common.KeyValue{}, + }, lbs1, exlbs1, []string{label31, value31, label32, value32}, @@ -241,6 +283,9 @@ func Test_createLabelSet(t *testing.T) { }, { "overwritten_external_labels", + resourcev1.Resource{ + Attributes: []common.KeyValue{}, + }, lbs1, exlbs2, []string{label31, value31, label32, value32}, @@ -250,7 +295,7 @@ func Test_createLabelSet(t *testing.T) { // run tests for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - assert.ElementsMatch(t, tt.want, createLabelSet(tt.orig, tt.externalLabels, tt.extras...)) + assert.ElementsMatch(t, tt.want, createLabelSet(tt.resource, tt.orig, tt.externalLabels, tt.extras...)) }) } }