Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace pcommon.Insert* usages with pcommon.Upsert* #13853

Merged
merged 1 commit into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func convertLogRecord(lr plog.LogRecord, resourceAttrs pcommon.Map, logger *zap.
resourceAttrs.Range(func(k string, v pcommon.Value) bool {
// LogRecord attribute takes priority
if _, ok := attrs.Get(k); !ok {
resourceAttrsForDimensions.Insert(k, v)
v.CopyTo(resourceAttrsForDimensions.UpsertEmpty(k))
}
return true
})
Expand Down
4 changes: 2 additions & 2 deletions exporter/sumologicexporter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (f *filter) filterIn(attributes pcommon.Map) fields {
attributes.Range(func(k string, v pcommon.Value) bool {
for _, regex := range f.regexes {
if regex.MatchString(k) {
returnValue.Insert(k, v)
v.CopyTo(returnValue.UpsertEmpty(k))
return true
}
}
Expand All @@ -68,7 +68,7 @@ func (f *filter) filterOut(attributes pcommon.Map) fields {
return true
}
}
returnValue.Insert(k, v)
v.CopyTo(returnValue.UpsertEmpty(k))
return true
})
returnValue.Sort()
Expand Down
4 changes: 2 additions & 2 deletions pkg/translator/jaeger/jaegerproto_to_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func translateHostnameAttr(attrs pcommon.Map) {
hostname, hostnameFound := attrs.Get("hostname")
_, convHostNameFound := attrs.Get(conventions.AttributeHostName)
if hostnameFound && !convHostNameFound {
attrs.Insert(conventions.AttributeHostName, hostname)
hostname.CopyTo(attrs.UpsertEmpty(conventions.AttributeHostName))
attrs.Remove("hostname")
}
}
Expand All @@ -188,7 +188,7 @@ func translateJaegerVersionAttr(attrs pcommon.Map) {
jaegerVersion, jaegerVersionFound := attrs.Get("jaeger.version")
_, exporterVersionFound := attrs.Get(occonventions.AttributeExporterVersion)
if jaegerVersionFound && !exporterVersionFound {
attrs.InsertString(occonventions.AttributeExporterVersion, "Jaeger-"+jaegerVersion.StringVal())
attrs.UpsertString(occonventions.AttributeExporterVersion, "Jaeger-"+jaegerVersion.StringVal())
attrs.Remove("jaeger.version")
}
}
Expand Down
2 changes: 1 addition & 1 deletion processor/groupbyattrsprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (gap *groupByAttrsProcessor) extractGroupingAttributes(attrMap pcommon.Map)
for _, attrKey := range gap.groupByKeys {
attrVal, found := attrMap.Get(attrKey)
if found {
groupingAttributes.Insert(attrKey, attrVal)
attrVal.CopyTo(groupingAttributes.UpsertEmpty(attrKey))
foundMatch = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ func TestProcess(t *testing.T) {
{
query: []string{`set(attributes["test"], Concat("-", attributes["attr1"], attributes["attr2"])) where metric.name == Concat("", "operation", "A")`},
want: func(td pmetric.Metrics) {
td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).Attributes().InsertString("test", "test1-test2")
td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(1).Attributes().InsertString("test", "test1-test2")
td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).Attributes().UpsertString("test", "test1-test2")
td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(1).Attributes().UpsertString("test", "test1-test2")
},
},
}
Expand Down
12 changes: 6 additions & 6 deletions processor/transformprocessor/internal/traces/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,27 +168,27 @@ func TestProcess(t *testing.T) {
{
query: `set(attributes["test"], Concat(": ", attributes["http.method"], attributes["http.url"]))`,
want: func(td ptrace.Traces) {
td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Attributes().InsertString("test", "get: http://localhost/health")
td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(1).Attributes().InsertString("test", "get: http://localhost/health")
td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Attributes().UpsertString("test", "get: http://localhost/health")
td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(1).Attributes().UpsertString("test", "get: http://localhost/health")
},
},
{
query: `set(attributes["test"], Concat("", attributes["http.method"], ": ", attributes["http.url"]))`,
want: func(td ptrace.Traces) {
td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Attributes().InsertString("test", "get: http://localhost/health")
td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(1).Attributes().InsertString("test", "get: http://localhost/health")
td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Attributes().UpsertString("test", "get: http://localhost/health")
td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(1).Attributes().UpsertString("test", "get: http://localhost/health")
},
},
{
query: `set(attributes["test"], Concat(": ", attributes["http.method"], attributes["http.url"])) where name == Concat("", "operation", "A")`,
want: func(td ptrace.Traces) {
td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Attributes().InsertString("test", "get: http://localhost/health")
td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Attributes().UpsertString("test", "get: http://localhost/health")
},
},
{
query: `set(attributes["kind"], Concat("", "kind", ": ", kind)) where kind == 1`,
want: func(td ptrace.Traces) {
td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Attributes().InsertString("kind", "kind: 1")
td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Attributes().UpsertString("kind", "kind: 1")
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/prometheusreceiver/internal/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (t *transaction) AppendExemplar(ref storage.SeriesRef, l labels.Labels, e e
copyToLowerBytes(sid[:], b)
exemplar.SetSpanID(pcommon.NewSpanID(sid))
default:
exemplar.FilteredAttributes().Insert(lb.Name, pcommon.NewValueString(lb.Value))
exemplar.FilteredAttributes().UpsertString(lb.Name, lb.Value)
}
}
t.metricBuilder.families[familyName].groups[gk].exemplars[e.Value] = exemplar
Expand Down
2 changes: 1 addition & 1 deletion receiver/splunkhecreceiver/splunkhec_to_metricdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func buildAttributes(dimensions map[string]interface{}) pcommon.Map {
// TODO: Log or metric for this odd ball?
continue
}
attributes.InsertString(key, fmt.Sprintf("%v", val))
attributes.UpsertString(key, fmt.Sprintf("%v", val))
}
return attributes
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ func initializeMetricDps(metric pmetric.Metric, now pcommon.Timestamp, counterVa
}

dp := dps.AppendEmpty()
if counterValue.InstanceName != "" {
dp.Attributes().UpsertString(instanceLabelName, counterValue.InstanceName)
}
if attributes != nil {
for attKey, attVal := range attributes {
dp.Attributes().InsertString(attKey, attVal)
dp.Attributes().UpsertString(attKey, attVal)
}
}
if counterValue.InstanceName != "" {
dp.Attributes().InsertString(instanceLabelName, counterValue.InstanceName)
}

dp.SetTimestamp(now)
dp.SetDoubleVal(counterValue.Value)
Expand Down