diff --git a/internal/receiver/databricksreceiver/metrics_provider.go b/internal/receiver/databricksreceiver/metrics_provider.go index 3b706d1bb9b..8f03c9e616c 100644 --- a/internal/receiver/databricksreceiver/metrics_provider.go +++ b/internal/receiver/databricksreceiver/metrics_provider.go @@ -17,7 +17,6 @@ package databricksreceiver import ( "fmt" - "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "github.com/signalfx/splunk-otel-collector/internal/receiver/databricksreceiver/internal/metadata" @@ -50,24 +49,14 @@ func (p metricsProvider) addJobStatusMetrics(ms pmetric.MetricSlice) ([]int, err jobPt := jobPts.AppendEmpty() pauseStatus := pauseStatusToInt(j.Settings.Schedule.PauseStatus) jobPt.SetIntVal(pauseStatus) - jobIDAttr := pcommon.NewValueInt(int64(j.JobID)) - jobPt.Attributes().Insert(metadata.A.JobID, jobIDAttr) + jobPt.Attributes().UpsertInt(metadata.A.JobID, int64(j.JobID)) for _, task := range j.Settings.Tasks { taskPt := taskPts.AppendEmpty() taskPt.SetIntVal(pauseStatus) taskAttrs := taskPt.Attributes() - taskAttrs.Insert( - metadata.A.JobID, - jobIDAttr, - ) - taskAttrs.Insert( - metadata.A.TaskID, - pcommon.NewValueString(task.TaskKey), - ) - taskAttrs.Insert( - metadata.A.TaskType, - pcommon.NewValueString(taskType(task)), - ) + taskAttrs.UpsertInt(metadata.A.JobID, int64(j.JobID)) + taskAttrs.UpsertString(metadata.A.TaskID, task.TaskKey) + taskAttrs.UpsertString(metadata.A.TaskType, taskType(task)) } } return jobIDs, nil diff --git a/internal/receiver/databricksreceiver/run_metrics_provider.go b/internal/receiver/databricksreceiver/run_metrics_provider.go index ab0ace08061..c421ff19b0b 100644 --- a/internal/receiver/databricksreceiver/run_metrics_provider.go +++ b/internal/receiver/databricksreceiver/run_metrics_provider.go @@ -17,7 +17,6 @@ package databricksreceiver import ( "fmt" - "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "github.com/signalfx/splunk-otel-collector/internal/receiver/databricksreceiver/internal/metadata" @@ -67,14 +66,13 @@ func (p runMetricsProvider) addSingleJobRunMetrics( } jobPt := jobPts.AppendEmpty() jobPt.SetIntVal(int64(run.ExecutionDuration)) - jobIDAttr := pcommon.NewValueInt(int64(jobID)) - jobPt.Attributes().Insert(metadata.Attributes.JobID, jobIDAttr) + jobPt.Attributes().UpsertInt(metadata.Attributes.JobID, int64(jobID)) for _, task := range run.Tasks { taskPt := taskPts.AppendEmpty() taskPt.SetIntVal(int64(task.ExecutionDuration)) taskAttrs := taskPt.Attributes() - taskAttrs.Insert(metadata.Attributes.JobID, jobIDAttr) - taskAttrs.Insert(metadata.Attributes.TaskID, pcommon.NewValueString(task.TaskKey)) + taskAttrs.UpsertInt(metadata.Attributes.JobID, int64(jobID)) + taskAttrs.UpsertString(metadata.Attributes.TaskID, task.TaskKey) } } return nil diff --git a/internal/receiver/databricksreceiver/scraper.go b/internal/receiver/databricksreceiver/scraper.go index 8e8d06d4953..a62ec681e69 100644 --- a/internal/receiver/databricksreceiver/scraper.go +++ b/internal/receiver/databricksreceiver/scraper.go @@ -18,7 +18,6 @@ import ( "context" "fmt" - "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" "github.com/signalfx/splunk-otel-collector/internal/receiver/databricksreceiver/internal/metadata" @@ -37,10 +36,7 @@ func (s scraper) scrape(_ context.Context) (pmetric.Metrics, error) { out := pmetric.NewMetrics() rms := out.ResourceMetrics() rm := rms.AppendEmpty() - rm.Resource().Attributes().Insert( - metadata.A.DatabricksInstanceName, - pcommon.NewValueString(s.instanceName), - ) + rm.Resource().Attributes().UpsertString(metadata.A.DatabricksInstanceName, s.instanceName) ilms := rm.ScopeMetrics() ilm := ilms.AppendEmpty() ms := ilm.Metrics() diff --git a/internal/receiver/discoveryreceiver/endpoint_tracker.go b/internal/receiver/discoveryreceiver/endpoint_tracker.go index 193ea43f4b3..39af4431763 100644 --- a/internal/receiver/discoveryreceiver/endpoint_tracker.go +++ b/internal/receiver/discoveryreceiver/endpoint_tracker.go @@ -115,9 +115,9 @@ func endpointToPLogs(observerID config.ComponentID, eventType string, endpoints pLogs = plog.NewLogs() rlog := pLogs.ResourceLogs().AppendEmpty() rAttrs := rlog.Resource().Attributes() - rAttrs.InsertString(eventTypeAttr, eventType) - rAttrs.InsertString(observerNameAttr, observerID.Name()) - rAttrs.InsertString(observerTypeAttr, string(observerID.Type())) + rAttrs.UpsertString(eventTypeAttr, eventType) + rAttrs.UpsertString(observerNameAttr, observerID.Name()) + rAttrs.UpsertString(observerTypeAttr, string(observerID.Type())) sl := rlog.ScopeLogs().AppendEmpty() for _, endpoint := range endpoints { logRecord := sl.LogRecords().AppendEmpty() @@ -134,12 +134,12 @@ func endpointToPLogs(observerID config.ComponentID, eventType string, endpoints // this must be the first mutation of attrs since it's destructive envAttrs.CopyTo(attrs) } - attrs.InsertString("type", string(endpoint.Details.Type())) + attrs.UpsertString("type", string(endpoint.Details.Type())) } else { logRecord.Body().SetStringVal(fmt.Sprintf("%s endpoint %s", eventType, endpoint.ID)) } - attrs.InsertString("endpoint", endpoint.Target) - attrs.InsertString("id", string(endpoint.ID)) + attrs.UpsertString("endpoint", endpoint.Target) + attrs.UpsertString("id", string(endpoint.ID)) // sorted log record attributes for determinism attrs.Sort() @@ -155,13 +155,11 @@ func endpointEnvToAttrs(endpointType observer.EndpointType, endpointEnv observer // should result in a ValueMap case shouldEmbedMap(endpointType, k): if asMap, ok := v.(map[string]string); ok { - val := pcommon.NewValueMap() - mapVal := val.MapVal() + mapVal := attrs.UpsertEmptyMap(k) for item, itemVal := range asMap { - mapVal.InsertString(item, itemVal) + mapVal.UpsertString(item, itemVal) } mapVal.Sort() - attrs.Insert(k, val) } else { return attrs, fmt.Errorf("failed parsing %v env attributes", endpointType) } @@ -169,24 +167,22 @@ func endpointEnvToAttrs(endpointType observer.EndpointType, endpointEnv observer // embedded as ValueMap case observer.EndpointType(k) == observer.PodType && endpointType == observer.PortType: if podEnv, ok := v.(observer.EndpointEnv); ok { - val := pcommon.NewValueMap() podAttrs, e := endpointEnvToAttrs(observer.PodType, podEnv) if e != nil { return attrs, fmt.Errorf("failed parsing %v pod attributes ", endpointType) } - podAttrs.CopyTo(val.MapVal()) - attrs.Insert(k, val) + podAttrs.CopyTo(attrs.UpsertEmptyMap(k)) } else { return attrs, fmt.Errorf("failed parsing %v pod env %#v", endpointType, v) } default: switch vVal := v.(type) { case uint16: - attrs.InsertInt(k, int64(vVal)) + attrs.UpsertInt(k, int64(vVal)) case bool: - attrs.InsertBool(k, vVal) + attrs.UpsertBool(k, vVal) default: - attrs.InsertString(k, fmt.Sprintf("%v", v)) + attrs.UpsertString(k, fmt.Sprintf("%v", v)) } } } diff --git a/internal/receiver/discoveryreceiver/endpoint_tracker_test.go b/internal/receiver/discoveryreceiver/endpoint_tracker_test.go index 33d422cf7c2..bd656378805 100644 --- a/internal/receiver/discoveryreceiver/endpoint_tracker_test.go +++ b/internal/receiver/discoveryreceiver/endpoint_tracker_test.go @@ -39,22 +39,18 @@ func TestEndpointToPLogsHappyPath(t *testing.T) { plogs := expectedPLogs() lr := plogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) attrs := lr.Attributes() - annotations := pcommon.NewValueMap() - annotationsMap := annotations.MapVal() - annotationsMap.InsertString("annotation.one", "value.one") - annotationsMap.InsertString("annotation.two", "value.two") - attrs.Insert("annotations", annotations) - attrs.InsertString("endpoint", "pod.target") - attrs.InsertString("id", "pod.endpoint.id") - labels := pcommon.NewValueMap() - labelsMap := labels.MapVal() - labelsMap.InsertString("label.one", "value.one") - labelsMap.InsertString("label.two", "value.two") - attrs.Insert("labels", labels) - attrs.InsertString("name", "pod.name") - attrs.InsertString("namespace", "namespace") - attrs.InsertString("type", "pod") - attrs.InsertString("uid", "uid") + annotationsMap := attrs.UpsertEmptyMap("annotations") + annotationsMap.UpsertString("annotation.one", "value.one") + annotationsMap.UpsertString("annotation.two", "value.two") + attrs.UpsertString("endpoint", "pod.target") + attrs.UpsertString("id", "pod.endpoint.id") + labelsMap := attrs.UpsertEmptyMap("labels") + labelsMap.UpsertString("label.one", "value.one") + labelsMap.UpsertString("label.two", "value.two") + attrs.UpsertString("name", "pod.name") + attrs.UpsertString("namespace", "namespace") + attrs.UpsertString("type", "pod") + attrs.UpsertString("uid", "uid") lr.Body().SetStringVal("event.type pod endpoint pod.endpoint.id") return plogs }(), @@ -66,30 +62,24 @@ func TestEndpointToPLogsHappyPath(t *testing.T) { plogs := expectedPLogs() lr := plogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) attrs := lr.Attributes() - attrs.InsertString("endpoint", "port.target") - attrs.InsertString("id", "port.endpoint.id") - attrs.InsertString("name", "port.name") - - podEnv := pcommon.NewValueMap() - podEnvMap := podEnv.MapVal() - annotations := pcommon.NewValueMap() - annotationsMap := annotations.MapVal() - annotationsMap.InsertString("annotation.one", "value.one") - annotationsMap.InsertString("annotation.two", "value.two") - podEnvMap.Insert("annotations", annotations) - labels := pcommon.NewValueMap() - labelsMap := labels.MapVal() - labelsMap.InsertString("label.one", "value.one") - labelsMap.InsertString("label.two", "value.two") - podEnvMap.Insert("labels", labels) - podEnvMap.InsertString("name", "pod.name") - podEnvMap.InsertString("namespace", "namespace") - podEnvMap.InsertString("uid", "uid") - attrs.Insert("pod", podEnv) - - attrs.InsertInt("port", 1) - attrs.InsertString("transport", "transport") - attrs.InsertString("type", "port") + attrs.UpsertString("endpoint", "port.target") + attrs.UpsertString("id", "port.endpoint.id") + attrs.UpsertString("name", "port.name") + + podEnvMap := attrs.UpsertEmptyMap("pod") + annotationsMap := podEnvMap.UpsertEmptyMap("annotations") + annotationsMap.UpsertString("annotation.one", "value.one") + annotationsMap.UpsertString("annotation.two", "value.two") + labelsMap := podEnvMap.UpsertEmptyMap("labels") + labelsMap.UpsertString("label.one", "value.one") + labelsMap.UpsertString("label.two", "value.two") + podEnvMap.UpsertString("name", "pod.name") + podEnvMap.UpsertString("namespace", "namespace") + podEnvMap.UpsertString("uid", "uid") + + attrs.UpsertInt("port", 1) + attrs.UpsertString("transport", "transport") + attrs.UpsertString("type", "port") lr.Body().SetStringVal("event.type port endpoint port.endpoint.id") return plogs }(), @@ -101,14 +91,14 @@ func TestEndpointToPLogsHappyPath(t *testing.T) { plogs := expectedPLogs() lr := plogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) attrs := lr.Attributes() - attrs.InsertString("command", "command") - attrs.InsertString("endpoint", "hostport.target") - attrs.InsertString("id", "hostport.endpoint.id") - attrs.InsertBool("is_ipv6", true) - attrs.InsertInt("port", 1) - attrs.InsertString("process_name", "process.name") - attrs.InsertString("transport", "transport") - attrs.InsertString("type", "hostport") + attrs.UpsertString("command", "command") + attrs.UpsertString("endpoint", "hostport.target") + attrs.UpsertString("id", "hostport.endpoint.id") + attrs.UpsertBool("is_ipv6", true) + attrs.UpsertInt("port", 1) + attrs.UpsertString("process_name", "process.name") + attrs.UpsertString("transport", "transport") + attrs.UpsertString("type", "hostport") lr.Body().SetStringVal("event.type hostport endpoint hostport.endpoint.id") return plogs }(), @@ -120,23 +110,21 @@ func TestEndpointToPLogsHappyPath(t *testing.T) { plogs := expectedPLogs() lr := plogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) attrs := lr.Attributes() - attrs.InsertInt("alternate_port", 2) - attrs.InsertString("command", "command") - attrs.InsertString("container_id", "container.id") - attrs.InsertString("endpoint", "container.target") - attrs.InsertString("host", "host") - attrs.InsertString("id", "container.endpoint.id") - attrs.InsertString("image", "image") - labels := pcommon.NewValueMap() - labelsMap := labels.MapVal() - labelsMap.InsertString("label.one", "value.one") - labelsMap.InsertString("label.two", "value.two") - attrs.Insert("labels", labels) - attrs.InsertString("name", "container.name") - attrs.InsertInt("port", 1) - attrs.InsertString("tag", "tag") - attrs.InsertString("transport", "transport") - attrs.InsertString("type", "container") + attrs.UpsertInt("alternate_port", 2) + attrs.UpsertString("command", "command") + attrs.UpsertString("container_id", "container.id") + attrs.UpsertString("endpoint", "container.target") + attrs.UpsertString("host", "host") + attrs.UpsertString("id", "container.endpoint.id") + attrs.UpsertString("image", "image") + labelsMap := attrs.UpsertEmptyMap("labels") + labelsMap.UpsertString("label.one", "value.one") + labelsMap.UpsertString("label.two", "value.two") + attrs.UpsertString("name", "container.name") + attrs.UpsertInt("port", 1) + attrs.UpsertString("tag", "tag") + attrs.UpsertString("transport", "transport") + attrs.UpsertString("type", "container") lr.Body().SetStringVal("event.type container endpoint container.endpoint.id") return plogs }(), @@ -148,27 +136,23 @@ func TestEndpointToPLogsHappyPath(t *testing.T) { plogs := expectedPLogs() lr := plogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) attrs := lr.Attributes() - annotations := pcommon.NewValueMap() - annotationsMap := annotations.MapVal() - annotationsMap.InsertString("annotation.one", "value.one") - annotationsMap.InsertString("annotation.two", "value.two") - attrs.Insert("annotations", annotations) - attrs.InsertString("endpoint", "k8s.node.target") - attrs.InsertString("external_dns", "external.dns") - attrs.InsertString("external_ip", "external.ip") - attrs.InsertString("hostname", "host.name") - attrs.InsertString("id", "k8s.node.endpoint.id") - attrs.InsertString("internal_dns", "internal.dns") - attrs.InsertString("internal_ip", "internal.ip") - attrs.InsertInt("kubelet_endpoint_port", 1) - labels := pcommon.NewValueMap() - labelsMap := labels.MapVal() - labelsMap.InsertString("label.one", "value.one") - labelsMap.InsertString("label.two", "value.two") - attrs.Insert("labels", labels) - attrs.InsertString("name", "k8s.node.name") - attrs.InsertString("type", "k8s.node") - attrs.InsertString("uid", "uid") + annotationsMap := attrs.UpsertEmptyMap("annotations") + annotationsMap.UpsertString("annotation.one", "value.one") + annotationsMap.UpsertString("annotation.two", "value.two") + attrs.UpsertString("endpoint", "k8s.node.target") + attrs.UpsertString("external_dns", "external.dns") + attrs.UpsertString("external_ip", "external.ip") + attrs.UpsertString("hostname", "host.name") + attrs.UpsertString("id", "k8s.node.endpoint.id") + attrs.UpsertString("internal_dns", "internal.dns") + attrs.UpsertString("internal_ip", "internal.ip") + attrs.UpsertInt("kubelet_endpoint_port", 1) + labelsMap := attrs.UpsertEmptyMap("labels") + labelsMap.UpsertString("label.one", "value.one") + labelsMap.UpsertString("label.two", "value.two") + attrs.UpsertString("name", "k8s.node.name") + attrs.UpsertString("type", "k8s.node") + attrs.UpsertString("uid", "uid") lr.Body().SetStringVal("event.type k8s.node endpoint k8s.node.endpoint.id") return plogs }(), @@ -216,8 +200,8 @@ func TestEndpointToPLogsInvalidEndpoints(t *testing.T) { plogs := expectedPLogs() lr := plogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) attrs := lr.Attributes() - attrs.InsertString("endpoint", "endpoint.target") - attrs.InsertString("id", "endpoint.id") + attrs.UpsertString("endpoint", "endpoint.target") + attrs.UpsertString("id", "endpoint.id") lr.Body().SetStringVal("event.type endpoint endpoint.id") return plogs }(), @@ -233,9 +217,9 @@ func TestEndpointToPLogsInvalidEndpoints(t *testing.T) { plogs := expectedPLogs() lr := plogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) attrs := lr.Attributes() - attrs.InsertString("endpoint", "endpoint.target") - attrs.InsertString("id", "endpoint.id") - attrs.InsertString("type", "empty.details.env") + attrs.UpsertString("endpoint", "endpoint.target") + attrs.UpsertString("id", "endpoint.id") + attrs.UpsertString("type", "empty.details.env") lr.Body().SetStringVal("event.type empty.details.env endpoint endpoint.id") return plogs }(), @@ -251,11 +235,11 @@ func TestEndpointToPLogsInvalidEndpoints(t *testing.T) { plogs := expectedPLogs() lr := plogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) attrs := lr.Attributes() - attrs.InsertBool("annotations", false) - attrs.InsertString("endpoint", "endpoint.target") - attrs.InsertString("id", "endpoint.id") - attrs.InsertBool("labels", true) - attrs.InsertString("type", "unexpected.env") + attrs.UpsertBool("annotations", false) + attrs.UpsertString("endpoint", "endpoint.target") + attrs.UpsertString("id", "endpoint.id") + attrs.UpsertBool("labels", true) + attrs.UpsertString("type", "unexpected.env") lr.Body().SetStringVal("event.type unexpected.env endpoint endpoint.id") return plogs }(), @@ -367,31 +351,25 @@ func FuzzEndpointToPlogs(f *testing.F) { expectedLR := resourceLogs.ScopeLogs().At(0).LogRecords().At(0) expectedLR.Body().SetStringVal(fmt.Sprintf("%s port endpoint %s", eventType, endpointID)) attrs := expectedLR.Attributes() - attrs.InsertString("endpoint", target) - attrs.InsertString("id", endpointID) - attrs.InsertString("name", portName) - - podEnv := pcommon.NewValueMap() - podEnvMap := podEnv.MapVal() - annotations := pcommon.NewValueMap() - annotationsMap := annotations.MapVal() - annotationsMap.InsertString(annotationOne, annotationValueOne) + attrs.UpsertString("endpoint", target) + attrs.UpsertString("id", endpointID) + attrs.UpsertString("name", portName) + + podEnvMap := attrs.UpsertEmptyMap("pod") + annotationsMap := podEnvMap.UpsertEmptyMap("annotations") + annotationsMap.UpsertString(annotationOne, annotationValueOne) annotationsMap.UpsertString(annotationTwo, annotationValueTwo) annotationsMap.Sort() - podEnvMap.Insert("annotations", annotations) - labels := pcommon.NewValueMap() - labelsMap := labels.MapVal() - labelsMap.InsertString(labelOne, labelValueOne) + labelsMap := podEnvMap.UpsertEmptyMap("labels") + labelsMap.UpsertString(labelOne, labelValueOne) labelsMap.UpsertString(labelTwo, labelValueTwo) labelsMap.Sort() - podEnvMap.Insert("labels", labels) - podEnvMap.InsertString("name", podName) - podEnvMap.InsertString("namespace", namespace) - podEnvMap.InsertString("uid", uid) - attrs.Insert("pod", podEnv) - attrs.InsertInt("port", int64(port)) - attrs.InsertString("transport", transport) - attrs.InsertString("type", "port") + podEnvMap.UpsertString("name", podName) + podEnvMap.UpsertString("namespace", namespace) + podEnvMap.UpsertString("uid", uid) + attrs.UpsertInt("port", int64(port)) + attrs.UpsertString("transport", transport) + attrs.UpsertString("type", "port") require.Equal(t, 1, plogs.LogRecordCount()) lr := plogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) @@ -508,9 +486,9 @@ var ( func expectedPLogs() plog.Logs { plogs := plog.NewLogs() rAttrs := plogs.ResourceLogs().AppendEmpty().Resource().Attributes() - rAttrs.InsertString("discovery.event.type", "event.type") - rAttrs.InsertString("discovery.observer.name", "observer.name") - rAttrs.InsertString("discovery.observer.type", "observer.type") + rAttrs.UpsertString("discovery.event.type", "event.type") + rAttrs.UpsertString("discovery.observer.name", "observer.name") + rAttrs.UpsertString("discovery.observer.type", "observer.type") sLogs := plogs.ResourceLogs().At(0).ScopeLogs().AppendEmpty() lr := sLogs.LogRecords().AppendEmpty() lr.SetTimestamp(pcommon.NewTimestampFromTime(t0)) diff --git a/internal/receiver/smartagentreceiver/converter/event.go b/internal/receiver/smartagentreceiver/converter/event.go index 95f2f8c54ea..f2bff8878f1 100644 --- a/internal/receiver/smartagentreceiver/converter/event.go +++ b/internal/receiver/smartagentreceiver/converter/event.go @@ -52,25 +52,23 @@ func sfxEventToPDataLogs(event *event.Event, logger *zap.Logger) plog.Logs { attrs.Clear() attrs.EnsureCapacity(attrsCapacity) + for k, v := range event.Dimensions { + attrs.UpsertString(k, v) + } + if event.Category == 0 { // This attribute must be present or SFx exporter will not know it's an event - attrs.InsertNull(SFxEventCategoryKey) + attrs.UpsertEmpty(SFxEventCategoryKey) } else { - attrs.InsertInt(SFxEventCategoryKey, int64(event.Category)) + attrs.UpsertInt(SFxEventCategoryKey, int64(event.Category)) } if event.EventType != "" { - attrs.InsertString(SFxEventType, event.EventType) - } - - for k, v := range event.Dimensions { - attrs.InsertString(k, v) + attrs.UpsertString(SFxEventType, event.EventType) } if len(event.Properties) > 0 { - propMapVal := pcommon.NewValueMap() - propMap := propMapVal.MapVal() - propMap.Clear() + propMap := attrs.UpsertEmptyMap(SFxEventPropertiesKey) propMap.EnsureCapacity(len(event.Properties)) for property, value := range event.Properties { @@ -83,30 +81,28 @@ func sfxEventToPDataLogs(event *event.Event, logger *zap.Logger) plog.Logs { // https://github.com/signalfx/com_signalfx_metrics_protobuf/blob/master/model/signalfx_metrics.pb.go#L567 // bool, float64, int64, and string are only supported types. case string: - propMap.InsertString(property, v) + propMap.UpsertString(property, v) case bool: - propMap.InsertBool(property, v) + propMap.UpsertBool(property, v) case int: - propMap.InsertInt(property, int64(v)) + propMap.UpsertInt(property, int64(v)) case int8: - propMap.InsertInt(property, int64(v)) + propMap.UpsertInt(property, int64(v)) case int16: - propMap.InsertInt(property, int64(v)) + propMap.UpsertInt(property, int64(v)) case int32: - propMap.InsertInt(property, int64(v)) + propMap.UpsertInt(property, int64(v)) case int64: - propMap.InsertInt(property, v) + propMap.UpsertInt(property, v) case float32: - propMap.InsertDouble(property, float64(v)) + propMap.UpsertDouble(property, float64(v)) case float64: - propMap.InsertDouble(property, v) + propMap.UpsertDouble(property, v) default: // Default to string representation. - propMap.InsertString(property, fmt.Sprintf("%v", value)) + propMap.UpsertString(property, fmt.Sprintf("%v", value)) } } - - attrs.Insert(SFxEventPropertiesKey, propMapVal) } return logs diff --git a/internal/receiver/smartagentreceiver/converter/event_test.go b/internal/receiver/smartagentreceiver/converter/event_test.go index 63da0dfc139..86ddd45a35d 100644 --- a/internal/receiver/smartagentreceiver/converter/event_test.go +++ b/internal/receiver/smartagentreceiver/converter/event_test.go @@ -127,7 +127,7 @@ func newExpectedLog(properties map[string]pcommon.Value, timestamp uint64) plog. attrs := lr.Attributes() for k, v := range properties { - attrs.Insert(k, v) + v.CopyTo(attrs.UpsertEmpty(k)) } return ld diff --git a/internal/receiver/smartagentreceiver/converter/metrics.go b/internal/receiver/smartagentreceiver/converter/metrics.go index 4f93e47bd8a..85aa22b6c14 100644 --- a/internal/receiver/smartagentreceiver/converter/metrics.go +++ b/internal/receiver/smartagentreceiver/converter/metrics.go @@ -113,6 +113,6 @@ func fillNumberDatapoint(value sfx.Value, timestamp time.Time, dimensions map[st attributes := dp.Attributes() attributes.EnsureCapacity(len(dimensions)) for k, v := range dimensions { - attributes.InsertString(k, v) + attributes.UpsertString(k, v) } } diff --git a/internal/receiver/smartagentreceiver/converter/metrics_test.go b/internal/receiver/smartagentreceiver/converter/metrics_test.go index a75fe87d13b..c6034b06c2c 100644 --- a/internal/receiver/smartagentreceiver/converter/metrics_test.go +++ b/internal/receiver/smartagentreceiver/converter/metrics_test.go @@ -208,7 +208,7 @@ func TestDatapointsToPDataMetrics(t *testing.T) { }(), expectedMetrics: func() pmetric.Metrics { md := pdataMetrics(pmetric.MetricDataTypeGauge, 13, now) - md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Gauge().DataPoints().At(0).Attributes().UpdateString("k0", "") + md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Gauge().DataPoints().At(0).Attributes().UpsertString("k0", "") return md }(), }, diff --git a/internal/receiver/smartagentreceiver/converter/traces_test.go b/internal/receiver/smartagentreceiver/converter/traces_test.go index a590d1c0ed6..0e43ceea9b6 100644 --- a/internal/receiver/smartagentreceiver/converter/traces_test.go +++ b/internal/receiver/smartagentreceiver/converter/traces_test.go @@ -501,10 +501,10 @@ func newPDataSpan( td := ptrace.NewTraces() rs := td.ResourceSpans().AppendEmpty() if serviceName != "" { - rs.Resource().Attributes().InsertString("service.name", serviceName) + rs.Resource().Attributes().UpsertString("service.name", serviceName) } if dataSourceIP != "" { - rs.Resource().Attributes().InsertString("ip", dataSourceIP) + rs.Resource().Attributes().UpsertString("ip", dataSourceIP) } span := rs.ScopeSpans().AppendEmpty().Spans().AppendEmpty() @@ -538,11 +538,11 @@ func newPDataSpan( for k, val := range attributes { switch v := val.(type) { case string: - attrs.InsertString(k, v) + attrs.UpsertString(k, v) default: vInt, err := strconv.ParseInt(fmt.Sprintf("%v", v), 10, 64) require.NoError(t, err) - attrs.InsertInt(k, vInt) + attrs.UpsertInt(k, vInt) } } diff --git a/tests/testutils/pdata_to_resource_metrics.go b/tests/testutils/pdata_to_resource_metrics.go index d9cabfb9349..0bb389895f1 100644 --- a/tests/testutils/pdata_to_resource_metrics.go +++ b/tests/testutils/pdata_to_resource_metrics.go @@ -101,13 +101,7 @@ func addResourceAttribute(resourceMetric *ResourceMetric, name string, value pco case pcommon.ValueTypeMap: val = value.MapVal().AsRaw() case pcommon.ValueTypeSlice: - // Coerce to []any - // Required pdata helper is not exposed so we pass value as a map - // and use helper that calls it internally. - toTranslate := pcommon.NewMap() - toTranslate.Insert(name, value) - translated := toTranslate.AsRaw() - val = translated[name] + val = value.SliceVal().AsRaw() default: val = nil } diff --git a/tests/testutils/pdata_to_resource_metrics_test.go b/tests/testutils/pdata_to_resource_metrics_test.go index 8b4459fbfed..3a7c21cc4db 100644 --- a/tests/testutils/pdata_to_resource_metrics_test.go +++ b/tests/testutils/pdata_to_resource_metrics_test.go @@ -5,7 +5,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" ) @@ -13,11 +12,11 @@ func pdataMetrics() pmetric.Metrics { metrics := pmetric.NewMetrics() resourceMetrics := metrics.ResourceMetrics().AppendEmpty() attrs := resourceMetrics.Resource().Attributes() - attrs.InsertBool("bool", true) - attrs.InsertString("string", "a_string") - attrs.InsertInt("int", 123) - attrs.InsertDouble("double", 123.45) - attrs.InsertNull("null") + attrs.UpsertBool("bool", true) + attrs.UpsertString("string", "a_string") + attrs.UpsertInt("int", 123) + attrs.UpsertDouble("double", 123.45) + attrs.UpsertEmpty("null") ilms := resourceMetrics.ScopeMetrics() ilmOne := ilms.AppendEmpty() @@ -31,9 +30,9 @@ func pdataMetrics() pmetric.Metrics { ilmOneMetricOne.SetDataType(pmetric.MetricDataTypeGauge) ilmOneMetricOneDps := ilmOneMetricOne.Gauge().DataPoints() ilmOneMetricOneDps.AppendEmpty().SetIntVal(12345) - ilmOneMetricOneDps.At(0).Attributes().Insert("label_name_1", pcommon.NewValueString("label_value_1")) + ilmOneMetricOneDps.At(0).Attributes().UpsertString("label_name_1", "label_value_1") ilmOneMetricOneDps.AppendEmpty().SetIntVal(23456) - ilmOneMetricOneDps.At(1).Attributes().Insert("label_name_2", pcommon.NewValueString("label_value_2")) + ilmOneMetricOneDps.At(1).Attributes().UpsertString("label_name_2", "label_value_2") ilmOneMetricTwo := ilmOneMetrics.AppendEmpty() ilmOneMetricTwo.SetName("a_double_gauge") @@ -42,9 +41,9 @@ func pdataMetrics() pmetric.Metrics { ilmOneMetricTwo.SetDataType(pmetric.MetricDataTypeGauge) ilmOneMetricTwoDps := ilmOneMetricTwo.Gauge().DataPoints() ilmOneMetricTwoDps.AppendEmpty().SetDoubleVal(234.56) - ilmOneMetricTwoDps.At(0).Attributes().Insert("label_name_3", pcommon.NewValueString("label_value_3")) + ilmOneMetricTwoDps.At(0).Attributes().UpsertString("label_name_3", "label_value_3") ilmOneMetricTwoDps.AppendEmpty().SetDoubleVal(345.67) - ilmOneMetricTwoDps.At(1).Attributes().Insert("label_name_4", pcommon.NewValueString("label_value_4")) + ilmOneMetricTwoDps.At(1).Attributes().UpsertString("label_name_4", "label_value_4") ilms.AppendEmpty().Scope().SetName("an_instrumentation_library_without_version_or_metrics") @@ -59,9 +58,9 @@ func pdataMetrics() pmetric.Metrics { ilmThreeMetricOne.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative) ilmThreeMetricOneDps := ilmThreeMetricOne.Sum().DataPoints() ilmThreeMetricOneDps.AppendEmpty().SetIntVal(34567) - ilmThreeMetricOneDps.At(0).Attributes().Insert("label_name_5", pcommon.NewValueString("label_value_5")) + ilmThreeMetricOneDps.At(0).Attributes().UpsertString("label_name_5", "label_value_5") ilmThreeMetricOneDps.AppendEmpty().SetIntVal(45678) - ilmThreeMetricOneDps.At(1).Attributes().Insert("label_name_6", pcommon.NewValueString("label_value_6")) + ilmThreeMetricOneDps.At(1).Attributes().UpsertString("label_name_6", "label_value_6") ilmThreeMetricTwo := ilmThreeMetrics.AppendEmpty() ilmThreeMetricTwo.SetName("a_monotonic_delta_int_sum") @@ -72,9 +71,9 @@ func pdataMetrics() pmetric.Metrics { ilmThreeMetricTwo.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta) ilmThreeMetricTwoDps := ilmThreeMetricTwo.Sum().DataPoints() ilmThreeMetricTwoDps.AppendEmpty().SetIntVal(56789) - ilmThreeMetricTwoDps.At(0).Attributes().Insert("label_name_7", pcommon.NewValueString("label_value_7")) + ilmThreeMetricTwoDps.At(0).Attributes().UpsertString("label_name_7", "label_value_7") ilmThreeMetricTwoDps.AppendEmpty().SetIntVal(67890) - ilmThreeMetricTwoDps.At(1).Attributes().Insert("label_name_8", pcommon.NewValueString("label_value_8")) + ilmThreeMetricTwoDps.At(1).Attributes().UpsertString("label_name_8", "label_value_8") ilmThreeMetricThree := ilmThreeMetrics.AppendEmpty() ilmThreeMetricThree.SetName("a_monotonic_unspecified_int_sum") @@ -85,9 +84,9 @@ func pdataMetrics() pmetric.Metrics { ilmThreeMetricThree.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityUnspecified) ilmThreeMetricThreeDps := ilmThreeMetricThree.Sum().DataPoints() ilmThreeMetricThreeDps.AppendEmpty().SetIntVal(78901) - ilmThreeMetricThreeDps.At(0).Attributes().Insert("label_name_9", pcommon.NewValueString("label_value_9")) + ilmThreeMetricThreeDps.At(0).Attributes().UpsertString("label_name_9", "label_value_9") ilmThreeMetricThreeDps.AppendEmpty().SetIntVal(89012) - ilmThreeMetricThreeDps.At(1).Attributes().Insert("label_name_10", pcommon.NewValueString("label_value_10")) + ilmThreeMetricThreeDps.At(1).Attributes().UpsertString("label_name_10", "label_value_10") ilmThreeMetricFour := ilmThreeMetrics.AppendEmpty() ilmThreeMetricFour.SetName("a_monotonic_cumulative_double_sum") @@ -98,9 +97,9 @@ func pdataMetrics() pmetric.Metrics { ilmThreeMetricFour.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative) ilmThreeMetricFourDps := ilmThreeMetricFour.Sum().DataPoints() ilmThreeMetricFourDps.AppendEmpty().SetDoubleVal(456.78) - ilmThreeMetricFourDps.At(0).Attributes().Insert("label_name_11", pcommon.NewValueString("label_value_11")) + ilmThreeMetricFourDps.At(0).Attributes().UpsertString("label_name_11", "label_value_11") ilmThreeMetricFourDps.AppendEmpty().SetDoubleVal(567.89) - ilmThreeMetricFourDps.At(1).Attributes().Insert("label_name_12", pcommon.NewValueString("label_value_12")) + ilmThreeMetricFourDps.At(1).Attributes().UpsertString("label_name_12", "label_value_12") ilmThreeMetricFive := ilmThreeMetrics.AppendEmpty() ilmThreeMetricFive.SetName("a_monotonic_delta_double_sum") @@ -111,9 +110,9 @@ func pdataMetrics() pmetric.Metrics { ilmThreeMetricFive.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta) ilmThreeMetricFiveDps := ilmThreeMetricFive.Sum().DataPoints() ilmThreeMetricFiveDps.AppendEmpty().SetDoubleVal(678.90) - ilmThreeMetricFiveDps.At(0).Attributes().Insert("label_name_13", pcommon.NewValueString("label_value_13")) + ilmThreeMetricFiveDps.At(0).Attributes().UpsertString("label_name_13", "label_value_13") ilmThreeMetricFiveDps.AppendEmpty().SetDoubleVal(789.01) - ilmThreeMetricFiveDps.At(1).Attributes().Insert("label_name_14", pcommon.NewValueString("label_value_14")) + ilmThreeMetricFiveDps.At(1).Attributes().UpsertString("label_name_14", "label_value_14") ilmThreeMetricSix := ilmThreeMetrics.AppendEmpty() ilmThreeMetricSix.SetName("a_monotonic_unspecified_double_sum") @@ -124,9 +123,9 @@ func pdataMetrics() pmetric.Metrics { ilmThreeMetricSix.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityUnspecified) ilmThreeMetricSixDps := ilmThreeMetricSix.Sum().DataPoints() ilmThreeMetricSixDps.AppendEmpty().SetDoubleVal(890.12) - ilmThreeMetricSixDps.At(0).Attributes().Insert("label_name_15", pcommon.NewValueString("label_value_15")) + ilmThreeMetricSixDps.At(0).Attributes().UpsertString("label_name_15", "label_value_15") ilmThreeMetricSixDps.AppendEmpty().SetDoubleVal(901.23) - ilmThreeMetricSixDps.At(1).Attributes().Insert("label_name_16", pcommon.NewValueString("label_value_16")) + ilmThreeMetricSixDps.At(1).Attributes().UpsertString("label_name_16", "label_value_16") ilmThreeMetricSeven := ilmThreeMetrics.AppendEmpty() ilmThreeMetricSeven.SetName("a_nonmonotonic_cumulative_int_sum") @@ -137,9 +136,9 @@ func pdataMetrics() pmetric.Metrics { ilmThreeMetricSeven.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative) ilmThreeMetricSevenDps := ilmThreeMetricSeven.Sum().DataPoints() ilmThreeMetricSevenDps.AppendEmpty().SetIntVal(90123) - ilmThreeMetricSevenDps.At(0).Attributes().Insert("label_name_17", pcommon.NewValueString("label_value_17")) + ilmThreeMetricSevenDps.At(0).Attributes().UpsertString("label_name_17", "label_value_17") ilmThreeMetricSevenDps.AppendEmpty().SetIntVal(123456) - ilmThreeMetricSevenDps.At(1).Attributes().Insert("label_name_18", pcommon.NewValueString("label_value_18")) + ilmThreeMetricSevenDps.At(1).Attributes().UpsertString("label_name_18", "label_value_18") ilmThreeMetricEight := ilmThreeMetrics.AppendEmpty() ilmThreeMetricEight.SetName("a_nonmonotonic_delta_int_sum") @@ -150,9 +149,9 @@ func pdataMetrics() pmetric.Metrics { ilmThreeMetricEight.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta) ilmThreeMetricEightDps := ilmThreeMetricEight.Sum().DataPoints() ilmThreeMetricEightDps.AppendEmpty().SetIntVal(234567) - ilmThreeMetricEightDps.At(0).Attributes().Insert("label_name_19", pcommon.NewValueString("label_value_19")) + ilmThreeMetricEightDps.At(0).Attributes().UpsertString("label_name_19", "label_value_19") ilmThreeMetricEightDps.AppendEmpty().SetIntVal(345678) - ilmThreeMetricEightDps.At(1).Attributes().Insert("label_name_20", pcommon.NewValueString("label_value_20")) + ilmThreeMetricEightDps.At(1).Attributes().UpsertString("label_name_20", "label_value_20") ilmThreeMetricNine := ilmThreeMetrics.AppendEmpty() ilmThreeMetricNine.SetName("a_nonmonotonic_unspecified_int_sum") @@ -163,9 +162,9 @@ func pdataMetrics() pmetric.Metrics { ilmThreeMetricNine.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityUnspecified) ilmThreeMetricNineDps := ilmThreeMetricNine.Sum().DataPoints() ilmThreeMetricNineDps.AppendEmpty().SetIntVal(456789) - ilmThreeMetricNineDps.At(0).Attributes().Insert("label_name_21", pcommon.NewValueString("label_value_21")) + ilmThreeMetricNineDps.At(0).Attributes().UpsertString("label_name_21", "label_value_21") ilmThreeMetricNineDps.AppendEmpty().SetIntVal(567890) - ilmThreeMetricNineDps.At(1).Attributes().Insert("label_name_22", pcommon.NewValueString("label_value_22")) + ilmThreeMetricNineDps.At(1).Attributes().UpsertString("label_name_22", "label_value_22") ilmThreeMetricTen := ilmThreeMetrics.AppendEmpty() ilmThreeMetricTen.SetName("a_nonmonotonic_cumulative_double_sum") @@ -176,9 +175,9 @@ func pdataMetrics() pmetric.Metrics { ilmThreeMetricTen.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityCumulative) ilmThreeMetricTenDps := ilmThreeMetricTen.Sum().DataPoints() ilmThreeMetricTenDps.AppendEmpty().SetDoubleVal(1234.56) - ilmThreeMetricTenDps.At(0).Attributes().Insert("label_name_23", pcommon.NewValueString("label_value_23")) + ilmThreeMetricTenDps.At(0).Attributes().UpsertString("label_name_23", "label_value_23") ilmThreeMetricTenDps.AppendEmpty().SetDoubleVal(2345.67) - ilmThreeMetricTenDps.At(1).Attributes().Insert("label_name_24", pcommon.NewValueString("label_value_24")) + ilmThreeMetricTenDps.At(1).Attributes().UpsertString("label_name_24", "label_value_24") ilmThreeMetricEleven := ilmThreeMetrics.AppendEmpty() ilmThreeMetricEleven.SetName("a_nonmonotonic_delta_double_sum") @@ -189,9 +188,9 @@ func pdataMetrics() pmetric.Metrics { ilmThreeMetricEleven.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityDelta) ilmThreeMetricElevenDps := ilmThreeMetricEleven.Sum().DataPoints() ilmThreeMetricElevenDps.AppendEmpty().SetDoubleVal(3456.78) - ilmThreeMetricElevenDps.At(0).Attributes().Insert("label_name_25", pcommon.NewValueString("label_value_25")) + ilmThreeMetricElevenDps.At(0).Attributes().UpsertString("label_name_25", "label_value_25") ilmThreeMetricElevenDps.AppendEmpty().SetDoubleVal(4567.89) - ilmThreeMetricElevenDps.At(1).Attributes().Insert("label_name_26", pcommon.NewValueString("label_value_26")) + ilmThreeMetricElevenDps.At(1).Attributes().UpsertString("label_name_26", "label_value_26") ilmThreeMetricTwelve := ilmThreeMetrics.AppendEmpty() ilmThreeMetricTwelve.SetName("a_nonmonotonic_unspecified_double_sum") @@ -202,9 +201,9 @@ func pdataMetrics() pmetric.Metrics { ilmThreeMetricTwelve.Sum().SetAggregationTemporality(pmetric.MetricAggregationTemporalityUnspecified) ilmThreeMetricTwelveDps := ilmThreeMetricTwelve.Sum().DataPoints() ilmThreeMetricTwelveDps.AppendEmpty().SetDoubleVal(5678.90) - ilmThreeMetricTwelveDps.At(0).Attributes().Insert("label_name_27", pcommon.NewValueString("label_value_27")) + ilmThreeMetricTwelveDps.At(0).Attributes().UpsertString("label_name_27", "label_value_27") ilmThreeMetricTwelveDps.AppendEmpty().SetDoubleVal(6789.01) - ilmThreeMetricTwelveDps.At(1).Attributes().Insert("label_name_28", pcommon.NewValueString("label_value_28")) + ilmThreeMetricTwelveDps.At(1).Attributes().UpsertString("label_name_28", "label_value_28") return metrics }