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

[chore] Remove unnecessary internal common maps package. #36390

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
32 changes: 22 additions & 10 deletions exporter/signalfxexporter/internal/translation/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"go.uber.org/zap/zaptest/observer"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/internal/translation/dpfilters"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/maps"
)

const (
Expand Down Expand Up @@ -232,7 +231,7 @@ func Test_MetricDataToSignalFxV2(t *testing.T) {
doubleSFxDataPoint(
"gauge_double_with_dims",
&sfxMetricTypeGauge,
maps.MergeRawMaps(map[string]any{
mergeRawMaps(map[string]any{
"k_n0": "vn0",
"k_n1": "vn1",
"k_r0": "vr0",
Expand All @@ -241,7 +240,7 @@ func Test_MetricDataToSignalFxV2(t *testing.T) {
int64SFxDataPoint(
"gauge_int_with_dims",
&sfxMetricTypeGauge,
maps.MergeRawMaps(map[string]any{
mergeRawMaps(map[string]any{
"k_n0": "vn0",
"k_n1": "vn1",
"k_r0": "vr0",
Expand Down Expand Up @@ -295,7 +294,7 @@ func Test_MetricDataToSignalFxV2(t *testing.T) {
int64SFxDataPoint(
"gauge_int_with_dims",
&sfxMetricTypeGauge,
maps.MergeRawMaps(map[string]any{
mergeRawMaps(map[string]any{
"k_n0": "vn0",
"k_n1": "vn1",
"k_r0": "vr0",
Expand All @@ -304,7 +303,7 @@ func Test_MetricDataToSignalFxV2(t *testing.T) {
int64SFxDataPoint(
"gauge_int_with_dims",
&sfxMetricTypeGauge,
maps.MergeRawMaps(map[string]any{
mergeRawMaps(map[string]any{
"k_n0": "vn0",
"k_n1": "vn1",
"k_r0": "vr0",
Expand Down Expand Up @@ -338,7 +337,7 @@ func Test_MetricDataToSignalFxV2(t *testing.T) {
doubleSFxDataPoint(
"gauge_double_with_dims",
&sfxMetricTypeGauge,
maps.MergeRawMaps(map[string]any{
mergeRawMaps(map[string]any{
"k_n0": "vn0",
"k_n1": "vn1",
"k_r0": "vr0",
Expand Down Expand Up @@ -372,7 +371,7 @@ func Test_MetricDataToSignalFxV2(t *testing.T) {
doubleSFxDataPoint(
"gauge_double_with_dims",
&sfxMetricTypeGauge,
maps.MergeRawMaps(labelMap, map[string]any{
mergeRawMaps(labelMap, map[string]any{
"cloud_account_id": "efgh",
"cloud_provider": conventions.AttributeCloudProviderAWS,
"cloud_region": "us-east",
Expand Down Expand Up @@ -405,7 +404,7 @@ func Test_MetricDataToSignalFxV2(t *testing.T) {
doubleSFxDataPoint(
"gauge_double_with_dims",
&sfxMetricTypeGauge,
maps.MergeRawMaps(labelMap, map[string]any{
mergeRawMaps(labelMap, map[string]any{
"cloud_provider": conventions.AttributeCloudProviderAWS,
"cloud_account_id": "efgh",
"cloud_region": "us-east",
Expand Down Expand Up @@ -438,7 +437,7 @@ func Test_MetricDataToSignalFxV2(t *testing.T) {
doubleSFxDataPoint(
"gauge_double_with_dims",
&sfxMetricTypeGauge,
maps.MergeRawMaps(labelMap, map[string]any{
mergeRawMaps(labelMap, map[string]any{
"host_id": "abcd",
"cloud_provider": conventions.AttributeCloudProviderGCP,
"k_r0": "vr0",
Expand Down Expand Up @@ -469,7 +468,7 @@ func Test_MetricDataToSignalFxV2(t *testing.T) {
doubleSFxDataPoint(
"gauge_double_with_dims",
&sfxMetricTypeGauge,
maps.MergeRawMaps(labelMap, map[string]any{
mergeRawMaps(labelMap, map[string]any{
"gcp_id": "efgh_abcd",
"k_r0": "vr0",
"k_r1": "vr1",
Expand Down Expand Up @@ -1364,3 +1363,16 @@ func TestMetricsConverter_ConvertDimension(t *testing.T) {
})
}
}

// mergeRawMaps merges n maps with a later map's keys overriding earlier maps.
func mergeRawMaps(maps ...map[string]any) map[string]any {
ret := map[string]any{}

for _, m := range maps {
for k, v := range m {
ret[k] = v
}
}

return ret
}
39 changes: 0 additions & 39 deletions internal/common/maps/maps.go

This file was deleted.

41 changes: 0 additions & 41 deletions internal/common/maps/maps_test.go

This file was deleted.

14 changes: 0 additions & 14 deletions internal/common/maps/package_test.go

This file was deleted.

50 changes: 30 additions & 20 deletions pkg/translator/signalfx/from_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/maps"
)

const (
Expand Down Expand Up @@ -215,7 +213,7 @@ func Test_FromMetrics(t *testing.T) {
doubleSFxDataPoint(
"gauge_double_with_dims",
&sfxMetricTypeGauge,
maps.MergeStringMaps(map[string]string{
mergeStringMaps(map[string]string{
"k_n0": "v_n0",
"k_n1": "v_n1",
"k_r0": "v_r0",
Expand All @@ -225,7 +223,7 @@ func Test_FromMetrics(t *testing.T) {
int64SFxDataPoint(
"gauge_int_with_dims",
&sfxMetricTypeGauge,
maps.MergeStringMaps(map[string]string{
mergeStringMaps(map[string]string{
"k_n0": "v_n0",
"k_n1": "v_n1",
"k_r0": "v_r0",
Expand All @@ -251,13 +249,13 @@ func Test_FromMetrics(t *testing.T) {
doubleSFxDataPoint("histogram_min", &sfxMetricTypeGauge, labelMap, 0.1),
doubleSFxDataPoint("histogram_max", &sfxMetricTypeGauge, labelMap, 11.11),
int64SFxDataPoint("histogram_bucket", &sfxMetricTypeCumulativeCounter,
maps.MergeStringMaps(map[string]string{bucketDimensionKey: "1"}, labelMap), 4),
mergeStringMaps(map[string]string{bucketDimensionKey: "1"}, labelMap), 4),
int64SFxDataPoint("histogram_bucket", &sfxMetricTypeCumulativeCounter,
maps.MergeStringMaps(map[string]string{bucketDimensionKey: "2"}, labelMap), 6),
mergeStringMaps(map[string]string{bucketDimensionKey: "2"}, labelMap), 6),
int64SFxDataPoint("histogram_bucket", &sfxMetricTypeCumulativeCounter,
maps.MergeStringMaps(map[string]string{bucketDimensionKey: "4"}, labelMap), 9),
mergeStringMaps(map[string]string{bucketDimensionKey: "4"}, labelMap), 9),
int64SFxDataPoint("histogram_bucket", &sfxMetricTypeCumulativeCounter,
maps.MergeStringMaps(map[string]string{bucketDimensionKey: "+Inf"}, labelMap), 16),
mergeStringMaps(map[string]string{bucketDimensionKey: "+Inf"}, labelMap), 16),
},
},
{
Expand All @@ -274,13 +272,13 @@ func Test_FromMetrics(t *testing.T) {
wantSfxDataPoints: []*sfxpb.DataPoint{
int64SFxDataPoint("histogram_count", &sfxMetricTypeCumulativeCounter, labelMap, 16),
int64SFxDataPoint("histogram_bucket", &sfxMetricTypeCumulativeCounter,
maps.MergeStringMaps(map[string]string{bucketDimensionKey: "1"}, labelMap), 4),
mergeStringMaps(map[string]string{bucketDimensionKey: "1"}, labelMap), 4),
int64SFxDataPoint("histogram_bucket", &sfxMetricTypeCumulativeCounter,
maps.MergeStringMaps(map[string]string{bucketDimensionKey: "2"}, labelMap), 6),
mergeStringMaps(map[string]string{bucketDimensionKey: "2"}, labelMap), 6),
int64SFxDataPoint("histogram_bucket", &sfxMetricTypeCumulativeCounter,
maps.MergeStringMaps(map[string]string{bucketDimensionKey: "4"}, labelMap), 9),
mergeStringMaps(map[string]string{bucketDimensionKey: "4"}, labelMap), 9),
int64SFxDataPoint("histogram_bucket", &sfxMetricTypeCumulativeCounter,
maps.MergeStringMaps(map[string]string{bucketDimensionKey: "+Inf"}, labelMap), 16),
mergeStringMaps(map[string]string{bucketDimensionKey: "+Inf"}, labelMap), 16),
},
},
{
Expand All @@ -300,13 +298,13 @@ func Test_FromMetrics(t *testing.T) {
doubleSFxDataPoint("delta_histogram_min", &sfxMetricTypeGauge, labelMap, 0.1),
doubleSFxDataPoint("delta_histogram_max", &sfxMetricTypeGauge, labelMap, 11.11),
int64SFxDataPoint("delta_histogram_bucket", &sfxMetricTypeCounter,
maps.MergeStringMaps(map[string]string{bucketDimensionKey: "1"}, labelMap), 4),
mergeStringMaps(map[string]string{bucketDimensionKey: "1"}, labelMap), 4),
int64SFxDataPoint("delta_histogram_bucket", &sfxMetricTypeCounter,
maps.MergeStringMaps(map[string]string{bucketDimensionKey: "2"}, labelMap), 6),
mergeStringMaps(map[string]string{bucketDimensionKey: "2"}, labelMap), 6),
int64SFxDataPoint("delta_histogram_bucket", &sfxMetricTypeCounter,
maps.MergeStringMaps(map[string]string{bucketDimensionKey: "4"}, labelMap), 9),
mergeStringMaps(map[string]string{bucketDimensionKey: "4"}, labelMap), 9),
int64SFxDataPoint("delta_histogram_bucket", &sfxMetricTypeCounter,
maps.MergeStringMaps(map[string]string{bucketDimensionKey: "+Inf"}, labelMap), 16),
mergeStringMaps(map[string]string{bucketDimensionKey: "+Inf"}, labelMap), 16),
},
},
{
Expand Down Expand Up @@ -352,13 +350,13 @@ func Test_FromMetrics(t *testing.T) {
int64SFxDataPoint("summary_count", &sfxMetricTypeCumulativeCounter, labelMap, 111),
doubleSFxDataPoint("summary_sum", &sfxMetricTypeCumulativeCounter, labelMap, 123.4),
doubleSFxDataPoint("summary_quantile", &sfxMetricTypeGauge,
maps.MergeStringMaps(map[string]string{quantileDimensionKey: "0.25"}, labelMap), 0),
mergeStringMaps(map[string]string{quantileDimensionKey: "0.25"}, labelMap), 0),
doubleSFxDataPoint("summary_quantile", &sfxMetricTypeGauge,
maps.MergeStringMaps(map[string]string{quantileDimensionKey: "0.5"}, labelMap), 1),
mergeStringMaps(map[string]string{quantileDimensionKey: "0.5"}, labelMap), 1),
doubleSFxDataPoint("summary_quantile", &sfxMetricTypeGauge,
maps.MergeStringMaps(map[string]string{quantileDimensionKey: "0.75"}, labelMap), 2),
mergeStringMaps(map[string]string{quantileDimensionKey: "0.75"}, labelMap), 2),
doubleSFxDataPoint("summary_quantile", &sfxMetricTypeGauge,
maps.MergeStringMaps(map[string]string{quantileDimensionKey: "1"}, labelMap), 3),
mergeStringMaps(map[string]string{quantileDimensionKey: "1"}, labelMap), 3),
},
},
{
Expand Down Expand Up @@ -570,3 +568,15 @@ func sfxDimensions(m map[string]string) []*sfxpb.Dimension {

return sfxDims
}

func mergeStringMaps(maps ...map[string]string) map[string]string {
ret := map[string]string{}

for _, m := range maps {
for k, v := range m {
ret[k] = v
}
}

return ret
}
3 changes: 0 additions & 3 deletions pkg/translator/signalfx/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/
go 1.22.0

require (
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.113.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.113.0
github.com/signalfx/com_signalfx_metrics_protobuf v0.0.3
github.com/stretchr/testify v1.9.0
Expand Down Expand Up @@ -31,8 +30,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/common => ../../../internal/common

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest => ../../../pkg/pdatatest

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil => ../../../pkg/pdatautil
Expand Down
4 changes: 2 additions & 2 deletions receiver/k8sclusterreceiver/internal/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ package metadata // import "github.com/open-telemetry/opentelemetry-collector-co

import (
"fmt"
"maps"
"strings"
"time"

v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/maps"
metadataPkg "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/constants"
)
Expand Down Expand Up @@ -50,7 +50,7 @@ func TransformObjectMeta(om v1.ObjectMeta) v1.ObjectMeta {
// live on v1.ObjectMeta.
func GetGenericMetadata(om *v1.ObjectMeta, resourceType string) *KubernetesMetadata {
rType := strings.ToLower(resourceType)
metadata := maps.MergeStringMaps(map[string]string{}, om.Labels)
metadata := maps.Clone(om.Labels)

metadata[constants.K8sKeyWorkLoadKind] = resourceType
metadata[constants.K8sKeyWorkLoadName] = om.Name
Expand Down
Loading
Loading