Skip to content

Commit

Permalink
[chore] Replace usage of deprecated Map.PutString (#14739)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryax authored Oct 6, 2022
1 parent dd45b2f commit 3a4ec38
Show file tree
Hide file tree
Showing 278 changed files with 2,672 additions and 2,669 deletions.
6 changes: 5 additions & 1 deletion cmd/mdatagen/metrics.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (m *metric{{ $name.Render }}) recordDataPoint(start pcommon.Timestamp, ts p
{{- else if eq (attributeInfo .).Type.Primitive "[]byte" }}
dp.Attributes().PutEmptyBytes("{{ attributeKey .}}").FromRaw({{ .RenderUnexported }}AttributeValue)
{{- else }}
dp.Attributes().PutString("{{ attributeKey .}}", {{ .RenderUnexported }}AttributeValue)
dp.Attributes().PutStr("{{ attributeKey .}}", {{ .RenderUnexported }}AttributeValue)
{{- end }}
{{- end }}
}
Expand Down Expand Up @@ -202,7 +202,11 @@ type ResourceMetricsOption func(pmetric.ResourceMetrics)
// With{{ $name.Render }} sets provided value as "{{ $name }}" attribute for current resource.
func With{{ $name.Render }}(val {{ $attr.Type.Primitive }}) ResourceMetricsOption {
return func(rm pmetric.ResourceMetrics) {
{{- if eq $attr.Type.Primitive "string" }}
rm.Resource().Attributes().PutStr("{{ $name }}", val)
{{- else }}
rm.Resource().Attributes().Put{{ $attr.Type }}("{{ $name }}", val)
{{- end }}
}
}
{{ end }}
Expand Down
8 changes: 4 additions & 4 deletions exporter/alibabacloudlogserviceexporter/logs_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func createSimpleLogData(numberOfLogs int) plog.Logs {
ts := pcommon.Timestamp(int64(i) * time.Millisecond.Nanoseconds())
logRecord := sl.LogRecords().AppendEmpty()
logRecord.Body().SetStr("mylog")
logRecord.Attributes().PutString(conventions.AttributeServiceName, "myapp")
logRecord.Attributes().PutString("my-label", "myapp-type")
logRecord.Attributes().PutString(conventions.AttributeHostName, "myhost")
logRecord.Attributes().PutString("custom", "custom")
logRecord.Attributes().PutStr(conventions.AttributeServiceName, "myapp")
logRecord.Attributes().PutStr("my-label", "myapp-type")
logRecord.Attributes().PutStr(conventions.AttributeHostName, "myhost")
logRecord.Attributes().PutStr("custom", "custom")
logRecord.SetTimestamp(ts)
}
sl.LogRecords().AppendEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ import (

func fillComplexAttributeValueMap(m pcommon.Map) {
m.PutBool("result", true)
m.PutString("status", "ok")
m.PutStr("status", "ok")
m.PutDouble("value", 1.3)
m.PutInt("code", 200)
m.PutEmpty("null")
m.PutEmptySlice("array").AppendEmpty().SetStr("array")
m.PutEmptyMap("map").PutString("data", "hello world")
m.PutString("status", "ok")
m.PutEmptyMap("map").PutStr("data", "hello world")
m.PutStr("status", "ok")
}

func createLogData(numberOfLogs int) plog.Logs {
logs := plog.NewLogs()
logs.ResourceLogs().AppendEmpty() // Add an empty ResourceLogs
rl := logs.ResourceLogs().AppendEmpty()
rl.Resource().Attributes().PutString("resouceKey", "resourceValue")
rl.Resource().Attributes().PutString(conventions.AttributeServiceName, "test-log-service-exporter")
rl.Resource().Attributes().PutString(conventions.AttributeHostName, "test-host")
rl.Resource().Attributes().PutStr("resouceKey", "resourceValue")
rl.Resource().Attributes().PutStr(conventions.AttributeServiceName, "test-log-service-exporter")
rl.Resource().Attributes().PutStr(conventions.AttributeHostName, "test-host")
sl := rl.ScopeLogs().AppendEmpty()
sl.Scope().SetName("collector")
sl.Scope().SetVersion("v0.1.0")
Expand Down Expand Up @@ -71,10 +71,10 @@ func createLogData(numberOfLogs int) plog.Logs {
default:
logRecord.Body().SetStr("log contents")
}
logRecord.Attributes().PutString(conventions.AttributeServiceName, "myapp")
logRecord.Attributes().PutString("my-label", "myapp-type")
logRecord.Attributes().PutString(conventions.AttributeHostName, "myhost")
logRecord.Attributes().PutString("custom", "custom")
logRecord.Attributes().PutStr(conventions.AttributeServiceName, "myapp")
logRecord.Attributes().PutStr("my-label", "myapp-type")
logRecord.Attributes().PutStr(conventions.AttributeHostName, "myhost")
logRecord.Attributes().PutStr("custom", "custom")
logRecord.Attributes().PutEmpty("null-value")

logRecord.SetTimestamp(ts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func TestMetricDataToLogService(t *testing.T) {
md.ResourceMetrics().AppendEmpty() // Add an empty ResourceMetrics
rm := md.ResourceMetrics().AppendEmpty()

rm.Resource().Attributes().PutString("labelB", "valueB")
rm.Resource().Attributes().PutString("labelA", "valueA")
rm.Resource().Attributes().PutString("service.name", "unknown-service")
rm.Resource().Attributes().PutString("a", "b")
rm.Resource().Attributes().PutStr("labelB", "valueB")
rm.Resource().Attributes().PutStr("labelA", "valueA")
rm.Resource().Attributes().PutStr("service.name", "unknown-service")
rm.Resource().Attributes().PutStr("a", "b")
sms := rm.ScopeMetrics()
sms.AppendEmpty() // Add an empty ScopeMetrics
sm := sms.AppendEmpty()
Expand All @@ -53,7 +53,7 @@ func TestMetricDataToLogService(t *testing.T) {
intGauge := intGaugeMetric.SetEmptyGauge()
intGaugeDataPoints := intGauge.DataPoints()
intGaugeDataPoint := intGaugeDataPoints.AppendEmpty()
intGaugeDataPoint.Attributes().PutString("innerLabel", "innerValue")
intGaugeDataPoint.Attributes().PutStr("innerLabel", "innerValue")
intGaugeDataPoint.SetIntValue(10)
intGaugeDataPoint.SetTimestamp(pcommon.Timestamp(100_000_000))

Expand All @@ -62,7 +62,7 @@ func TestMetricDataToLogService(t *testing.T) {
doubleGauge := doubleGaugeMetric.SetEmptyGauge()
doubleGaugeDataPoints := doubleGauge.DataPoints()
doubleGaugeDataPoint := doubleGaugeDataPoints.AppendEmpty()
doubleGaugeDataPoint.Attributes().PutString("innerLabel", "innerValue")
doubleGaugeDataPoint.Attributes().PutStr("innerLabel", "innerValue")
doubleGaugeDataPoint.SetDoubleValue(10.1)
doubleGaugeDataPoint.SetTimestamp(pcommon.Timestamp(100_000_000))

Expand All @@ -71,7 +71,7 @@ func TestMetricDataToLogService(t *testing.T) {
intSum := intSumMetric.SetEmptySum()
intSumDataPoints := intSum.DataPoints()
intSumDataPoint := intSumDataPoints.AppendEmpty()
intSumDataPoint.Attributes().PutString("innerLabel", "innerValue")
intSumDataPoint.Attributes().PutStr("innerLabel", "innerValue")
intSumDataPoint.SetIntValue(11)
intSumDataPoint.SetTimestamp(pcommon.Timestamp(100_000_000))

Expand All @@ -80,7 +80,7 @@ func TestMetricDataToLogService(t *testing.T) {
doubleSum := doubleSumMetric.SetEmptySum()
doubleSumDataPoints := doubleSum.DataPoints()
doubleSumDataPoint := doubleSumDataPoints.AppendEmpty()
doubleSumDataPoint.Attributes().PutString("innerLabel", "innerValue")
doubleSumDataPoint.Attributes().PutStr("innerLabel", "innerValue")
doubleSumDataPoint.SetDoubleValue(10.1)
doubleSumDataPoint.SetTimestamp(pcommon.Timestamp(100_000_000))

Expand All @@ -89,7 +89,7 @@ func TestMetricDataToLogService(t *testing.T) {
doubleHistogram := doubleHistogramMetric.SetEmptyHistogram()
doubleHistogramDataPoints := doubleHistogram.DataPoints()
doubleHistogramDataPoint := doubleHistogramDataPoints.AppendEmpty()
doubleHistogramDataPoint.Attributes().PutString("innerLabel", "innerValue")
doubleHistogramDataPoint.Attributes().PutStr("innerLabel", "innerValue")
doubleHistogramDataPoint.SetCount(2)
doubleHistogramDataPoint.SetSum(10.1)
doubleHistogramDataPoint.SetTimestamp(pcommon.Timestamp(100_000_000))
Expand All @@ -104,7 +104,7 @@ func TestMetricDataToLogService(t *testing.T) {
doubleSummaryDataPoint.SetCount(2)
doubleSummaryDataPoint.SetSum(10.1)
doubleSummaryDataPoint.SetTimestamp(pcommon.Timestamp(100_000_000))
doubleSummaryDataPoint.Attributes().PutString("innerLabel", "innerValue")
doubleSummaryDataPoint.Attributes().PutStr("innerLabel", "innerValue")
quantileVal := doubleSummaryDataPoint.QuantileValues().AppendEmpty()
quantileVal.SetValue(10.2)
quantileVal.SetQuantile(0.9)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ func constructSpanData() ptrace.Traces {

func fillResource(resource pcommon.Resource) {
attrs := resource.Attributes()
attrs.PutString(conventions.AttributeServiceName, "signup_aggregator")
attrs.PutString(conventions.AttributeHostName, "xxx.et15")
attrs.PutString(conventions.AttributeContainerName, "signup_aggregator")
attrs.PutString(conventions.AttributeContainerImageName, "otel/signupaggregator")
attrs.PutString(conventions.AttributeContainerImageTag, "v1")
attrs.PutString(conventions.AttributeCloudProvider, conventions.AttributeCloudProviderAWS)
attrs.PutString(conventions.AttributeCloudAccountID, "999999998")
attrs.PutString(conventions.AttributeCloudRegion, "us-west-2")
attrs.PutString(conventions.AttributeCloudAvailabilityZone, "us-west-1b")
attrs.PutStr(conventions.AttributeServiceName, "signup_aggregator")
attrs.PutStr(conventions.AttributeHostName, "xxx.et15")
attrs.PutStr(conventions.AttributeContainerName, "signup_aggregator")
attrs.PutStr(conventions.AttributeContainerImageName, "otel/signupaggregator")
attrs.PutStr(conventions.AttributeContainerImageTag, "v1")
attrs.PutStr(conventions.AttributeCloudProvider, conventions.AttributeCloudProviderAWS)
attrs.PutStr(conventions.AttributeCloudAccountID, "999999998")
attrs.PutStr(conventions.AttributeCloudRegion, "us-west-2")
attrs.PutStr(conventions.AttributeCloudAvailabilityZone, "us-west-1b")
}

func fillHTTPClientSpan(span ptrace.Span) {
Expand All @@ -131,11 +131,11 @@ func fillHTTPClientSpan(span ptrace.Span) {
event := span.Events().AppendEmpty()
event.SetName("event")
event.SetTimestamp(1024)
event.Attributes().PutString("key", "value")
event.Attributes().PutStr("key", "value")

link := span.Links().AppendEmpty()
link.TraceState().FromRaw("link:state")
link.Attributes().PutString("link", "true")
link.Attributes().PutStr("link", "true")

status := span.Status()
status.SetCode(1)
Expand Down Expand Up @@ -173,7 +173,7 @@ func constructSpanAttributes(attributes map[string]interface{}) pcommon.Map {
} else if cast, ok := value.(int64); ok {
attrs.PutInt(key, cast)
} else {
attrs.PutString(key, fmt.Sprintf("%v", value))
attrs.PutStr(key, fmt.Sprintf("%v", value))
}
}
return attrs
Expand Down
10 changes: 5 additions & 5 deletions exporter/awscloudwatchlogsexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func BenchmarkLogToCWLog(b *testing.B) {

func testResource() pcommon.Resource {
resource := pcommon.NewResource()
resource.Attributes().PutString("host", "abc123")
resource.Attributes().PutStr("host", "abc123")
resource.Attributes().PutInt("node", 5)
return resource
}
Expand All @@ -131,7 +131,7 @@ func testLogRecord() plog.LogRecord {
record.SetDroppedAttributesCount(4)
record.Body().SetStr("hello world")
record.Attributes().PutInt("key1", 1)
record.Attributes().PutString("key2", "attr2")
record.Attributes().PutStr("key2", "attr2")
record.SetTraceID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})
record.SetSpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8})
record.SetFlags(plog.DefaultLogRecordFlags.WithIsSampled(true))
Expand All @@ -146,7 +146,7 @@ func testLogRecordWithoutTrace() plog.LogRecord {
record.SetDroppedAttributesCount(4)
record.Body().SetStr("hello world")
record.Attributes().PutInt("key1", 1)
record.Attributes().PutString("key2", "attr2")
record.Attributes().PutStr("key2", "attr2")
record.SetTimestamp(1609719139000000)
return record
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestAttrValue(t *testing.T) {
value: func() pcommon.Value {
mAttr := pcommon.NewValueMap()
m := mAttr.Map()
m.PutString("key1", "value1")
m.PutStr("key1", "value1")
m.PutEmpty("key2")
m.PutBool("key3", true)
m.PutInt("key4", 4)
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestConsumeLogs(t *testing.T) {
assert.NotNil(t, exp)
ld := plog.NewLogs()
r := ld.ResourceLogs().AppendEmpty()
r.Resource().Attributes().PutString("hello", "test")
r.Resource().Attributes().PutStr("hello", "test")
logRecords := r.ScopeLogs().AppendEmpty().LogRecords()
logRecords.EnsureCapacity(5)
logRecords.AppendEmpty()
Expand Down
12 changes: 6 additions & 6 deletions exporter/awsemfexporter/datapoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func TestIntDataPointSliceAt(t *testing.T) {
testDPS := pmetric.NewNumberDataPointSlice()
testDP := testDPS.AppendEmpty()
testDP.SetIntValue(tc.value.(int64))
testDP.Attributes().PutString("label", "value")
testDP.Attributes().PutStr("label", "value")

dps := numberDataPointSlice{
instrLibName,
Expand Down Expand Up @@ -366,7 +366,7 @@ func TestDoubleDataPointSliceAt(t *testing.T) {
testDPS := pmetric.NewNumberDataPointSlice()
testDP := testDPS.AppendEmpty()
testDP.SetDoubleValue(tc.value.(float64))
testDP.Attributes().PutString("label1", "value1")
testDP.Attributes().PutStr("label1", "value1")

dps := numberDataPointSlice{
instrLibName,
Expand Down Expand Up @@ -400,7 +400,7 @@ func TestHistogramDataPointSliceAt(t *testing.T) {
testDP.SetSum(17.13)
testDP.BucketCounts().FromRaw([]uint64{1, 2, 3})
testDP.ExplicitBounds().FromRaw([]float64{1, 2, 3})
testDP.Attributes().PutString("label1", "value1")
testDP.Attributes().PutStr("label1", "value1")

dps := histogramDataPointSlice{
instrLibName,
Expand Down Expand Up @@ -432,7 +432,7 @@ func TestHistogramDataPointSliceAtWithMinMax(t *testing.T) {
testDP.SetSum(17.13)
testDP.SetMin(10)
testDP.SetMax(30)
testDP.Attributes().PutString("label1", "value1")
testDP.Attributes().PutStr("label1", "value1")

dps := histogramDataPointSlice{
instrLibName,
Expand Down Expand Up @@ -464,7 +464,7 @@ func TestHistogramDataPointSliceAtWithoutMinMax(t *testing.T) {
testDP := testDPS.AppendEmpty()
testDP.SetCount(uint64(17))
testDP.SetSum(17.13)
testDP.Attributes().PutString("label1", "value1")
testDP.Attributes().PutStr("label1", "value1")

dps := histogramDataPointSlice{
instrLibName,
Expand Down Expand Up @@ -531,7 +531,7 @@ func TestSummaryDataPointSliceAt(t *testing.T) {
testQuantileValue = testDP.QuantileValues().AppendEmpty()
testQuantileValue.SetQuantile(100)
testQuantileValue.SetValue(float64(5))
testDP.Attributes().PutString("label1", "value1")
testDP.Attributes().PutStr("label1", "value1")

dps := summaryDataPointSlice{
instrLibName,
Expand Down
28 changes: 14 additions & 14 deletions exporter/awsemfexporter/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func TestReplacePatternValidTaskId(t *testing.T) {
input := "{TaskId}"

attrMap := pcommon.NewMap()
attrMap.PutString("aws.ecs.cluster.name", "test-cluster-name")
attrMap.PutString("aws.ecs.task.id", "test-task-id")
attrMap.PutStr("aws.ecs.cluster.name", "test-cluster-name")
attrMap.PutStr("aws.ecs.task.id", "test-task-id")

s, success := replacePatterns(input, attrMaptoStringMap(attrMap), logger)

Expand All @@ -50,8 +50,8 @@ func TestReplacePatternValidClusterName(t *testing.T) {
input := "/aws/ecs/containerinsights/{ClusterName}/performance"

attrMap := pcommon.NewMap()
attrMap.PutString("aws.ecs.cluster.name", "test-cluster-name")
attrMap.PutString("aws.ecs.task.id", "test-task-id")
attrMap.PutStr("aws.ecs.cluster.name", "test-cluster-name")
attrMap.PutStr("aws.ecs.task.id", "test-task-id")

s, success := replacePatterns(input, attrMaptoStringMap(attrMap), logger)

Expand All @@ -65,7 +65,7 @@ func TestReplacePatternMissingAttribute(t *testing.T) {
input := "/aws/ecs/containerinsights/{ClusterName}/performance"

attrMap := pcommon.NewMap()
attrMap.PutString("aws.ecs.task.id", "test-task-id")
attrMap.PutStr("aws.ecs.task.id", "test-task-id")

s, success := replacePatterns(input, attrMaptoStringMap(attrMap), logger)

Expand All @@ -79,8 +79,8 @@ func TestReplacePatternValidPodName(t *testing.T) {
input := "/aws/eks/containerinsights/{PodName}/performance"

attrMap := pcommon.NewMap()
attrMap.PutString("aws.eks.cluster.name", "test-cluster-name")
attrMap.PutString("PodName", "test-pod-001")
attrMap.PutStr("aws.eks.cluster.name", "test-cluster-name")
attrMap.PutStr("PodName", "test-pod-001")

s, success := replacePatterns(input, attrMaptoStringMap(attrMap), logger)

Expand All @@ -94,8 +94,8 @@ func TestReplacePatternValidPod(t *testing.T) {
input := "/aws/eks/containerinsights/{PodName}/performance"

attrMap := pcommon.NewMap()
attrMap.PutString("aws.eks.cluster.name", "test-cluster-name")
attrMap.PutString("pod", "test-pod-001")
attrMap.PutStr("aws.eks.cluster.name", "test-cluster-name")
attrMap.PutStr("pod", "test-pod-001")

s, success := replacePatterns(input, attrMaptoStringMap(attrMap), logger)

Expand All @@ -109,7 +109,7 @@ func TestReplacePatternMissingPodName(t *testing.T) {
input := "/aws/eks/containerinsights/{PodName}/performance"

attrMap := pcommon.NewMap()
attrMap.PutString("aws.eks.cluster.name", "test-cluster-name")
attrMap.PutStr("aws.eks.cluster.name", "test-cluster-name")

s, success := replacePatterns(input, attrMaptoStringMap(attrMap), logger)

Expand All @@ -123,7 +123,7 @@ func TestReplacePatternAttrPlaceholderClusterName(t *testing.T) {
input := "/aws/ecs/containerinsights/{ClusterName}/performance"

attrMap := pcommon.NewMap()
attrMap.PutString("ClusterName", "test-cluster-name")
attrMap.PutStr("ClusterName", "test-cluster-name")

s, success := replacePatterns(input, attrMaptoStringMap(attrMap), logger)

Expand All @@ -137,7 +137,7 @@ func TestReplacePatternWrongKey(t *testing.T) {
input := "/aws/ecs/containerinsights/{WrongKey}/performance"

attrMap := pcommon.NewMap()
attrMap.PutString("ClusterName", "test-task-id")
attrMap.PutStr("ClusterName", "test-task-id")

s, success := replacePatterns(input, attrMaptoStringMap(attrMap), logger)

Expand Down Expand Up @@ -165,8 +165,8 @@ func TestReplacePatternValidTaskDefinitionFamily(t *testing.T) {
input := "{TaskDefinitionFamily}"

attrMap := pcommon.NewMap()
attrMap.PutString("aws.ecs.cluster.name", "test-cluster-name")
attrMap.PutString("aws.ecs.task.family", "test-task-definition-family")
attrMap.PutStr("aws.ecs.cluster.name", "test-cluster-name")
attrMap.PutStr("aws.ecs.task.family", "test-task-definition-family")

s, success := replacePatterns(input, attrMaptoStringMap(attrMap), logger)

Expand Down
Loading

0 comments on commit 3a4ec38

Please sign in to comment.