From 9523d65ed1be99ee83a871c7f4cf9cd7864b1817 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Wed, 16 Mar 2022 02:42:29 +0000 Subject: [PATCH 1/5] prometheusremotewriteexporter: translate resource to target info --- CHANGELOG.md | 1 + .../exporter_test.go | 2 +- pkg/translator/prometheusremotewrite/go.mod | 1 + pkg/translator/prometheusremotewrite/go.sum | 2 + .../prometheusremotewrite/helper.go | 133 +++++++++++---- .../prometheusremotewrite/helper_test.go | 153 +++++++++++++++++- .../prometheusremotewrite/metrics_to_prw.go | 6 +- 7 files changed, 260 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8873c98c98c..31c8cd5b3451 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - `cmd/mdatagen`: Add resource attributes definition to metadata.yaml and move `pdata.Metrics` creation to the generated code (#5270) - Add `make crosslink` target to ensure replace statements are included in `go.mod` for all transitive dependencies within repository (#8822) +- `prometheusremotewriteexporter`: Translate resource attributes to the target info metric (#8493) ### 🛑 Breaking changes 🛑 diff --git a/exporter/prometheusremotewriteexporter/exporter_test.go b/exporter/prometheusremotewriteexporter/exporter_test.go index 7037c7a14bcd..0d14b3ed69f1 100644 --- a/exporter/prometheusremotewriteexporter/exporter_test.go +++ b/exporter/prometheusremotewriteexporter/exporter_test.go @@ -441,7 +441,7 @@ func Test_PushMetrics(t *testing.T) { "intSum_case", &intSumBatch, checkFunc, - 2, + 3, http.StatusAccepted, false, false, diff --git a/pkg/translator/prometheusremotewrite/go.mod b/pkg/translator/prometheusremotewrite/go.mod index fe76d36d4228..215a6655467d 100644 --- a/pkg/translator/prometheusremotewrite/go.mod +++ b/pkg/translator/prometheusremotewrite/go.mod @@ -15,6 +15,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/kr/pretty v0.3.0 // indirect + github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.46.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect go.uber.org/atomic v1.9.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect diff --git a/pkg/translator/prometheusremotewrite/go.sum b/pkg/translator/prometheusremotewrite/go.sum index 84922e9d04bc..1fd2bdc29b6d 100644 --- a/pkg/translator/prometheusremotewrite/go.sum +++ b/pkg/translator/prometheusremotewrite/go.sum @@ -949,6 +949,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= +github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.46.0 h1:y7D6FmP4aJSkj3xdwlvlLMHFEX7tr9ZY7XtRZAWP9k0= +github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.46.0/go.mod h1:wFgFElwA1P+441Aqxbwn2xafbKQGh2NB2AX/Ilap27o= github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= diff --git a/pkg/translator/prometheusremotewrite/helper.go b/pkg/translator/prometheusremotewrite/helper.go index 24eca679db6d..2a252af4e823 100644 --- a/pkg/translator/prometheusremotewrite/helper.go +++ b/pkg/translator/prometheusremotewrite/helper.go @@ -48,8 +48,10 @@ const ( maxExemplarRunes = 128 // Trace and Span id keys are defined as part of the spec: // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification%2Fmetrics%2Fdatamodel.md#exemplars-2 - traceIDKey = "trace_id" - spanIDKey = "span_id" + traceIDKey = "trace_id" + spanIDKey = "span_id" + infoType = "info" + targetMetricName = "target" ) type bucketBoundsData struct { @@ -75,13 +77,13 @@ func (a ByLabelName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // creates a new TimeSeries in the map if not found and returns the time series signature. // tsMap will be unmodified if either labels or sample is nil, but can still be modified if the exemplar is nil. func addSample(tsMap map[string]*prompb.TimeSeries, sample *prompb.Sample, labels []prompb.Label, - metric pdata.Metric) string { + datatype string) string { if sample == nil || labels == nil || tsMap == nil { return "" } - sig := timeSeriesSignature(metric, &labels) + sig := timeSeriesSignature(datatype, &labels) ts, ok := tsMap[sig] if ok { @@ -137,9 +139,9 @@ func addExemplar(tsMap map[string]*prompb.TimeSeries, bucketBounds []bucketBound // TYPE-label1-value1- ... -labelN-valueN // the label slice should not contain duplicate label names; this method sorts the slice by label name before creating // the signature. -func timeSeriesSignature(metric pdata.Metric, labels *[]prompb.Label) string { +func timeSeriesSignature(datatype string, labels *[]prompb.Label) string { b := strings.Builder{} - b.WriteString(metric.DataType().String()) + b.WriteString(datatype) sort.Sort(ByLabelName(*labels)) @@ -160,6 +162,23 @@ func createAttributes(resource pdata.Resource, attributes pdata.Map, externalLab // map ensures no duplicate label name l := map[string]prompb.Label{} + // Ensure attributes are sorted by key for consistent merging of keys which + // collide when sanitized. + attributes.Sort() + attributes.Range(func(key string, value pdata.AttributeValue) bool { + if existingLabel, alreadyExists := l[sanitize(key)]; alreadyExists { + existingLabel.Value = existingLabel.Value + ";" + value.AsString() + l[sanitize(key)] = existingLabel + } else { + l[sanitize(key)] = prompb.Label{ + Name: sanitize(key), + Value: value.AsString(), + } + } + + return true + }) + // Map service.name + service.namespace to job if serviceName, ok := resource.Attributes().Get(conventions.AttributeServiceName); ok { val := serviceName.AsString() @@ -178,24 +197,6 @@ func createAttributes(resource pdata.Resource, attributes pdata.Map, externalLab Value: instance.AsString(), } } - - // Ensure attributes are sorted by key for consistent merging of keys which - // collide when sanitized. - attributes.Sort() - attributes.Range(func(key string, value pdata.Value) bool { - if existingLabel, alreadyExists := l[sanitize(key)]; alreadyExists { - existingLabel.Value = existingLabel.Value + ";" + value.AsString() - l[sanitize(key)] = existingLabel - } else { - l[sanitize(key)] = prompb.Label{ - Name: sanitize(key), - Value: value.AsString(), - } - } - - return true - }) - for key, value := range externalLabels { // External labels have already been sanitized if _, alreadyExists := l[key]; alreadyExists { @@ -280,7 +281,7 @@ func addSingleNumberDataPoint(pt pdata.NumberDataPoint, resource pdata.Resource, if pt.Flags().HasFlag(pdata.MetricDataPointFlagNoRecordedValue) { sample.Value = math.Float64frombits(value.StaleNaN) } - addSample(tsMap, sample, labels, metric) + addSample(tsMap, sample, labels, metric.DataType().String()) } // addSingleHistogramDataPoint converts pt to 2 + min(len(ExplicitBounds), len(BucketCount)) + 1 samples. It @@ -299,7 +300,7 @@ func addSingleHistogramDataPoint(pt pdata.HistogramDataPoint, resource pdata.Res } sumlabels := createAttributes(resource, pt.Attributes(), settings.ExternalLabels, nameStr, baseName+sumStr) - addSample(tsMap, sum, sumlabels, metric) + addSample(tsMap, sum, sumlabels, metric.DataType().String()) // treat count as a sample in an individual TimeSeries count := &prompb.Sample{ @@ -311,7 +312,7 @@ func addSingleHistogramDataPoint(pt pdata.HistogramDataPoint, resource pdata.Res } countlabels := createAttributes(resource, pt.Attributes(), settings.ExternalLabels, nameStr, baseName+countStr) - addSample(tsMap, count, countlabels, metric) + addSample(tsMap, count, countlabels, metric.DataType().String()) // cumulative count for conversion to cumulative histogram var cumulativeCount uint64 @@ -335,7 +336,7 @@ func addSingleHistogramDataPoint(pt pdata.HistogramDataPoint, resource pdata.Res } boundStr := strconv.FormatFloat(bound, 'f', -1, 64) labels := createAttributes(resource, pt.Attributes(), settings.ExternalLabels, nameStr, baseName+bucketStr, leStr, boundStr) - sig := addSample(tsMap, bucket, labels, metric) + sig := addSample(tsMap, bucket, labels, metric.DataType().String()) bucketBounds = append(bucketBounds, bucketBoundsData{sig: sig, bound: bound}) } @@ -350,7 +351,7 @@ func addSingleHistogramDataPoint(pt pdata.HistogramDataPoint, resource pdata.Res infBucket.Value = float64(cumulativeCount) } infLabels := createAttributes(resource, pt.Attributes(), settings.ExternalLabels, nameStr, baseName+bucketStr, leStr, pInfStr) - sig := addSample(tsMap, infBucket, infLabels, metric) + sig := addSample(tsMap, infBucket, infLabels, metric.DataType().String()) bucketBounds = append(bucketBounds, bucketBoundsData{sig: sig, bound: math.Inf(1)}) addExemplars(tsMap, promExemplars, bucketBounds) @@ -411,6 +412,42 @@ func getPromExemplars(pt pdata.HistogramDataPoint) []prompb.Exemplar { return promExemplars } +// mostRecentTimestampInMetric returns the latest timestamp in a batch of metrics +func mostRecentTimestampInMetric(metric pdata.Metric) pdata.Timestamp { + var ts pdata.Timestamp + // handle individual metric based on type + switch metric.DataType() { + case pdata.MetricDataTypeGauge: + dataPoints := metric.Gauge().DataPoints() + for x := 0; x < dataPoints.Len(); x++ { + ts = maxTimestamp(ts, dataPoints.At(x).Timestamp()) + } + case pdata.MetricDataTypeSum: + dataPoints := metric.Sum().DataPoints() + for x := 0; x < dataPoints.Len(); x++ { + ts = maxTimestamp(ts, dataPoints.At(x).Timestamp()) + } + case pdata.MetricDataTypeHistogram: + dataPoints := metric.Histogram().DataPoints() + for x := 0; x < dataPoints.Len(); x++ { + ts = maxTimestamp(ts, dataPoints.At(x).Timestamp()) + } + case pdata.MetricDataTypeSummary: + dataPoints := metric.Summary().DataPoints() + for x := 0; x < dataPoints.Len(); x++ { + ts = maxTimestamp(ts, dataPoints.At(x).Timestamp()) + } + } + return ts +} + +func maxTimestamp(a, b pdata.Timestamp) pdata.Timestamp { + if a > b { + return a + } + return b +} + // addSingleSummaryDataPoint converts pt to len(QuantileValues) + 2 samples. func addSingleSummaryDataPoint(pt pdata.SummaryDataPoint, resource pdata.Resource, metric pdata.Metric, settings Settings, tsMap map[string]*prompb.TimeSeries) { @@ -426,7 +463,7 @@ func addSingleSummaryDataPoint(pt pdata.SummaryDataPoint, resource pdata.Resourc sum.Value = math.Float64frombits(value.StaleNaN) } sumlabels := createAttributes(resource, pt.Attributes(), settings.ExternalLabels, nameStr, baseName+sumStr) - addSample(tsMap, sum, sumlabels, metric) + addSample(tsMap, sum, sumlabels, metric.DataType().String()) // treat count as a sample in an individual TimeSeries count := &prompb.Sample{ @@ -437,7 +474,7 @@ func addSingleSummaryDataPoint(pt pdata.SummaryDataPoint, resource pdata.Resourc count.Value = math.Float64frombits(value.StaleNaN) } countlabels := createAttributes(resource, pt.Attributes(), settings.ExternalLabels, nameStr, baseName+countStr) - addSample(tsMap, count, countlabels, metric) + addSample(tsMap, count, countlabels, metric.DataType().String()) // process each percentile/quantile for i := 0; i < pt.QuantileValues().Len(); i++ { @@ -451,8 +488,40 @@ func addSingleSummaryDataPoint(pt pdata.SummaryDataPoint, resource pdata.Resourc } percentileStr := strconv.FormatFloat(qt.Quantile(), 'f', -1, 64) qtlabels := createAttributes(resource, pt.Attributes(), settings.ExternalLabels, nameStr, baseName, quantileStr, percentileStr) - addSample(tsMap, quantile, qtlabels, metric) + addSample(tsMap, quantile, qtlabels, metric.DataType().String()) + } +} + +// addResourceTargetInfo converts the resource to the target info metric +func addResourceTargetInfo(resource pdata.Resource, settings Settings, timestamp pdata.Timestamp, tsMap map[string]*prompb.TimeSeries) { + if resource.Attributes().Len() == 0 { + return + } + // create parameters for addSample + name := targetMetricName + if len(settings.Namespace) > 0 { + name = settings.Namespace + "_" + name + } + // Use resource attributes (other than those used for job+instance) as the + // metric labels for the target info metric + attributes := pdata.NewAttributeMap() + resource.Attributes().CopyTo(attributes) + attributes.RemoveIf(func(k string, _ pdata.AttributeValue) bool { + switch k { + case conventions.AttributeServiceName, conventions.AttributeServiceNamespace, conventions.AttributeServiceInstanceID: + // Remove resource attributes used for job + instance + return true + default: + return false + } + }) + labels := createAttributes(resource, attributes, settings.ExternalLabels, nameStr, name) + sample := &prompb.Sample{ + Value: float64(1), + // convert ns to ms + Timestamp: convertTimeStamp(timestamp), } + addSample(tsMap, sample, labels, infoType) } // copied from prometheus-go-metric-exporter diff --git a/pkg/translator/prometheusremotewrite/helper_test.go b/pkg/translator/prometheusremotewrite/helper_test.go index 77d789b6cc6c..1e0a468cc71c 100644 --- a/pkg/translator/prometheusremotewrite/helper_test.go +++ b/pkg/translator/prometheusremotewrite/helper_test.go @@ -23,6 +23,9 @@ import ( "github.com/prometheus/prometheus/prompb" "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/model/pdata" + conventions "go.opentelemetry.io/collector/model/semconv/v1.6.1" + + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/testdata" ) // Test_validateMetrics checks validateMetrics return true if a type and temporality combination is valid, false @@ -119,14 +122,14 @@ func Test_addSample(t *testing.T) { } t.Run("empty_case", func(t *testing.T) { tsMap := map[string]*prompb.TimeSeries{} - addSample(tsMap, nil, nil, pdata.NewMetric()) + addSample(tsMap, nil, nil, "") assert.Exactly(t, tsMap, map[string]*prompb.TimeSeries{}) }) // run tests for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - addSample(tt.orig, &tt.testCase[0].sample, tt.testCase[0].labels, tt.testCase[0].metric) - addSample(tt.orig, &tt.testCase[1].sample, tt.testCase[1].labels, tt.testCase[1].metric) + addSample(tt.orig, &tt.testCase[0].sample, tt.testCase[0].labels, tt.testCase[0].metric.DataType().String()) + addSample(tt.orig, &tt.testCase[1].sample, tt.testCase[1].labels, tt.testCase[1].metric.DataType().String()) assert.Exactly(t, tt.want, tt.orig) }) } @@ -171,7 +174,7 @@ func Test_timeSeriesSignature(t *testing.T) { // run tests for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - assert.EqualValues(t, tt.want, timeSeriesSignature(tt.metric, &tt.lbs)) + assert.EqualValues(t, tt.want, timeSeriesSignature(tt.metric.DataType().String(), &tt.lbs)) }) } } @@ -490,3 +493,145 @@ func Test_getPromExemplars(t *testing.T) { }) } } + +func TestAddResourceTargetInfo(t *testing.T) { + resourceAttrMap := map[string]pdata.AttributeValue{ + conventions.AttributeServiceName: pdata.NewAttributeValueString("service-name"), + conventions.AttributeServiceNamespace: pdata.NewAttributeValueString("service-namespace"), + conventions.AttributeServiceInstanceID: pdata.NewAttributeValueString("service-instance-id"), + "resource_attr": pdata.NewAttributeValueString("resource-attr-val-1"), + } + resourceWithServiceAttrs := pdata.NewResource() + pdata.NewAttributeMapFromMap(resourceAttrMap).CopyTo(resourceWithServiceAttrs.Attributes()) + for _, tc := range []struct { + desc string + resource pdata.Resource + settings Settings + timestamp pdata.Timestamp + expected map[string]*prompb.TimeSeries + }{ + { + desc: "empty resource", + resource: pdata.NewResource(), + expected: map[string]*prompb.TimeSeries{}, + }, + { + desc: "with resource", + resource: testdata.GenerateMetricsNoLibraries().ResourceMetrics().At(0).Resource(), + timestamp: testdata.TestMetricStartTimestamp, + expected: map[string]*prompb.TimeSeries{ + "info-__name__-target-resource_attr-resource-attr-val-1": { + Labels: []prompb.Label{ + { + Name: "__name__", + Value: "target", + }, + { + Name: "resource_attr", + Value: "resource-attr-val-1", + }, + }, + Samples: []prompb.Sample{ + { + Value: 1, + Timestamp: 1581452772000, + }, + }, + }, + }, + }, + { + desc: "with resource, with namespace", + resource: testdata.GenerateMetricsNoLibraries().ResourceMetrics().At(0).Resource(), + timestamp: testdata.TestMetricStartTimestamp, + settings: Settings{Namespace: "foo"}, + expected: map[string]*prompb.TimeSeries{ + "info-__name__-foo_target-resource_attr-resource-attr-val-1": { + Labels: []prompb.Label{ + { + Name: "__name__", + Value: "foo_target", + }, + { + Name: "resource_attr", + Value: "resource-attr-val-1", + }, + }, + Samples: []prompb.Sample{ + { + Value: 1, + Timestamp: 1581452772000, + }, + }, + }, + }, + }, + { + desc: "with resource, with service attributes", + resource: resourceWithServiceAttrs, + timestamp: testdata.TestMetricStartTimestamp, + expected: map[string]*prompb.TimeSeries{ + "info-__name__-target-instance-service-instance-id-job-service-namespace/service-name-resource_attr-resource-attr-val-1": { + Labels: []prompb.Label{ + { + Name: "__name__", + Value: "target", + }, + { + Name: "instance", + Value: "service-instance-id", + }, + { + Name: "job", + Value: "service-namespace/service-name", + }, + { + Name: "resource_attr", + Value: "resource-attr-val-1", + }, + }, + Samples: []prompb.Sample{ + { + Value: 1, + Timestamp: 1581452772000, + }, + }, + }, + }, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + tsMap := map[string]*prompb.TimeSeries{} + addResourceTargetInfo(tc.resource, tc.settings, tc.timestamp, tsMap) + assert.Exactly(t, tc.expected, tsMap) + }) + } +} + +func TestMostRecentTimestampInMetric(t *testing.T) { + laterTimestamp := pdata.NewTimestampFromTime(testdata.TestMetricTime.Add(1 * time.Minute)) + metricMultipleTimestamps := testdata.GenerateMetricsOneMetric().ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0) + // the first datapoint timestamp is at testdata.TestMetricTime + metricMultipleTimestamps.Sum().DataPoints().At(1).SetTimestamp(laterTimestamp) + for _, tc := range []struct { + desc string + input pdata.Metric + expected pdata.Timestamp + }{ + { + desc: "empty", + input: pdata.NewMetric(), + expected: pdata.Timestamp(0), + }, + { + desc: "multiple timestamps", + input: metricMultipleTimestamps, + expected: laterTimestamp, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + got := mostRecentTimestampInMetric(tc.input) + assert.Exactly(t, tc.expected, got) + }) + } +} diff --git a/pkg/translator/prometheusremotewrite/metrics_to_prw.go b/pkg/translator/prometheusremotewrite/metrics_to_prw.go index 01ba9ff79e67..80899f59cca3 100644 --- a/pkg/translator/prometheusremotewrite/metrics_to_prw.go +++ b/pkg/translator/prometheusremotewrite/metrics_to_prw.go @@ -47,7 +47,9 @@ func FromMetrics(md pdata.Metrics, settings Settings) (tsMap map[string]*prompb. resourceMetrics := resourceMetricsSlice.At(i) resource := resourceMetrics.Resource() scopeMetricsSlice := resourceMetrics.ScopeMetrics() - // TODO: add resource attributes as labels, probably in next PR + // keep track of the most recent timestamp in the ResourceMetrics for + // use with the "target" info metric + var mostRecentTimestamp pdata.Timestamp for j := 0; j < scopeMetricsSlice.Len(); j++ { scopeMetrics := scopeMetricsSlice.At(j) metricSlice := scopeMetrics.Metrics() @@ -55,6 +57,7 @@ func FromMetrics(md pdata.Metrics, settings Settings) (tsMap map[string]*prompb. // TODO: decide if instrumentation library information should be exported as labels for k := 0; k < metricSlice.Len(); k++ { metric := metricSlice.At(k) + mostRecentTimestamp = maxTimestamp(mostRecentTimestamp, mostRecentTimestampInMetric(metric)) // check for valid type and temporality combination and for matching data field and type if ok := validateMetrics(metric); !ok { @@ -96,6 +99,7 @@ func FromMetrics(md pdata.Metrics, settings Settings) (tsMap map[string]*prompb. } } } + addResourceTargetInfo(resource, settings, mostRecentTimestamp, tsMap) } return From e3778c957af8003ba9432c0c7be4ac33cb07bace Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Sun, 20 Mar 2022 14:43:54 +0000 Subject: [PATCH 2/5] fix go mod and changelog --- pkg/translator/prometheusremotewrite/go.mod | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/translator/prometheusremotewrite/go.mod b/pkg/translator/prometheusremotewrite/go.mod index 215a6655467d..af671b8227a2 100644 --- a/pkg/translator/prometheusremotewrite/go.mod +++ b/pkg/translator/prometheusremotewrite/go.mod @@ -15,9 +15,11 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/kr/pretty v0.3.0 // indirect - github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.46.0 // indirect + github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.47.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect go.uber.org/atomic v1.9.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) + +replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal => ../../../internal/coreinternal From bd51e467442959c4ea5c84ec3a2e2ed4bfaec270 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Mon, 21 Mar 2022 13:50:24 +0000 Subject: [PATCH 3/5] fix deprecation warnings --- pkg/translator/prometheusremotewrite/helper.go | 4 ++-- pkg/translator/prometheusremotewrite/helper_test.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/translator/prometheusremotewrite/helper.go b/pkg/translator/prometheusremotewrite/helper.go index 2a252af4e823..0f08b26d4d4b 100644 --- a/pkg/translator/prometheusremotewrite/helper.go +++ b/pkg/translator/prometheusremotewrite/helper.go @@ -165,7 +165,7 @@ func createAttributes(resource pdata.Resource, attributes pdata.Map, externalLab // Ensure attributes are sorted by key for consistent merging of keys which // collide when sanitized. attributes.Sort() - attributes.Range(func(key string, value pdata.AttributeValue) bool { + attributes.Range(func(key string, value pdata.Value) bool { if existingLabel, alreadyExists := l[sanitize(key)]; alreadyExists { existingLabel.Value = existingLabel.Value + ";" + value.AsString() l[sanitize(key)] = existingLabel @@ -506,7 +506,7 @@ func addResourceTargetInfo(resource pdata.Resource, settings Settings, timestamp // metric labels for the target info metric attributes := pdata.NewAttributeMap() resource.Attributes().CopyTo(attributes) - attributes.RemoveIf(func(k string, _ pdata.AttributeValue) bool { + attributes.RemoveIf(func(k string, _ pdata.Value) bool { switch k { case conventions.AttributeServiceName, conventions.AttributeServiceNamespace, conventions.AttributeServiceInstanceID: // Remove resource attributes used for job + instance diff --git a/pkg/translator/prometheusremotewrite/helper_test.go b/pkg/translator/prometheusremotewrite/helper_test.go index 1e0a468cc71c..56471b361e4a 100644 --- a/pkg/translator/prometheusremotewrite/helper_test.go +++ b/pkg/translator/prometheusremotewrite/helper_test.go @@ -495,11 +495,11 @@ func Test_getPromExemplars(t *testing.T) { } func TestAddResourceTargetInfo(t *testing.T) { - resourceAttrMap := map[string]pdata.AttributeValue{ - conventions.AttributeServiceName: pdata.NewAttributeValueString("service-name"), - conventions.AttributeServiceNamespace: pdata.NewAttributeValueString("service-namespace"), - conventions.AttributeServiceInstanceID: pdata.NewAttributeValueString("service-instance-id"), - "resource_attr": pdata.NewAttributeValueString("resource-attr-val-1"), + resourceAttrMap := map[string]pdata.Value{ + conventions.AttributeServiceName: pdata.NewValueString("service-name"), + conventions.AttributeServiceNamespace: pdata.NewValueString("service-namespace"), + conventions.AttributeServiceInstanceID: pdata.NewValueString("service-instance-id"), + "resource_attr": pdata.NewValueString("resource-attr-val-1"), } resourceWithServiceAttrs := pdata.NewResource() pdata.NewAttributeMapFromMap(resourceAttrMap).CopyTo(resourceWithServiceAttrs.Attributes()) From bb788ba469a6189a9a40356a266adcc95bee492a Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Tue, 5 Apr 2022 10:26:26 -0400 Subject: [PATCH 4/5] Update pkg/translator/prometheusremotewrite/go.mod Co-authored-by: Anthony Mirabella --- pkg/translator/prometheusremotewrite/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/translator/prometheusremotewrite/go.mod b/pkg/translator/prometheusremotewrite/go.mod index af671b8227a2..1c8c1f892c65 100644 --- a/pkg/translator/prometheusremotewrite/go.mod +++ b/pkg/translator/prometheusremotewrite/go.mod @@ -15,7 +15,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/kr/pretty v0.3.0 // indirect - github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.47.0 // indirect + github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.48.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect go.uber.org/atomic v1.9.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect From 7703c88464759548effca7bd43779fa649a7bec2 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Tue, 5 Apr 2022 15:35:01 +0000 Subject: [PATCH 5/5] fix linter errors --- pkg/translator/prometheusremotewrite/helper.go | 2 +- pkg/translator/prometheusremotewrite/helper_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/translator/prometheusremotewrite/helper.go b/pkg/translator/prometheusremotewrite/helper.go index 0f08b26d4d4b..1ecd0cf07c26 100644 --- a/pkg/translator/prometheusremotewrite/helper.go +++ b/pkg/translator/prometheusremotewrite/helper.go @@ -504,7 +504,7 @@ func addResourceTargetInfo(resource pdata.Resource, settings Settings, timestamp } // Use resource attributes (other than those used for job+instance) as the // metric labels for the target info metric - attributes := pdata.NewAttributeMap() + attributes := pdata.NewMap() resource.Attributes().CopyTo(attributes) attributes.RemoveIf(func(k string, _ pdata.Value) bool { switch k { diff --git a/pkg/translator/prometheusremotewrite/helper_test.go b/pkg/translator/prometheusremotewrite/helper_test.go index 56471b361e4a..a5034bfdf226 100644 --- a/pkg/translator/prometheusremotewrite/helper_test.go +++ b/pkg/translator/prometheusremotewrite/helper_test.go @@ -495,14 +495,14 @@ func Test_getPromExemplars(t *testing.T) { } func TestAddResourceTargetInfo(t *testing.T) { - resourceAttrMap := map[string]pdata.Value{ - conventions.AttributeServiceName: pdata.NewValueString("service-name"), - conventions.AttributeServiceNamespace: pdata.NewValueString("service-namespace"), - conventions.AttributeServiceInstanceID: pdata.NewValueString("service-instance-id"), - "resource_attr": pdata.NewValueString("resource-attr-val-1"), + resourceAttrMap := map[string]interface{}{ + conventions.AttributeServiceName: "service-name", + conventions.AttributeServiceNamespace: "service-namespace", + conventions.AttributeServiceInstanceID: "service-instance-id", + "resource_attr": "resource-attr-val-1", } resourceWithServiceAttrs := pdata.NewResource() - pdata.NewAttributeMapFromMap(resourceAttrMap).CopyTo(resourceWithServiceAttrs.Attributes()) + pdata.NewMapFromRaw(resourceAttrMap).CopyTo(resourceWithServiceAttrs.Attributes()) for _, tc := range []struct { desc string resource pdata.Resource