Skip to content

Commit 8d99c1b

Browse files
committed
Switch to gcp from gce as specified in open-telemetry/opentelemetry-collector-contrib#10348
1 parent 35c4a22 commit 8d99c1b

18 files changed

+239
-12
lines changed

cmd/otelcol/config/collector/agent_config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ processors:
110110
# libraries can send wrong values from container environments.
111111
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourcedetectionprocessor#ordering
112112
resourcedetection:
113-
detectors: [gce, ecs, ec2, azure, system]
113+
detectors: [gcp, ecs, ec2, azure, system]
114114
override: true
115115

116116
# Optional: The following processor can be used to add a default "deployment.environment" attribute to the logs and

cmd/otelcol/config/collector/full_config_linux.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ processors:
205205
# Full configuration here: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourcedetectionprocessor
206206
# NOTE: This processor settings need to be change when using this processor
207207
#resouredection:
208-
# # a list of resource detectors to run, valid options are: "env", "system", "gce", "ec2", "ecs", "elastic_beanstalk"
208+
# # a list of resource detectors to run, valid options are: "env", "system", "gcp", "ec2", "ecs", "elastic_beanstalk"
209209
#detectors: [ <string> ]
210210
# # determines if existing resource attributes should be overridden or preserved, defaults to true
211211
#override: <bool>
@@ -214,7 +214,7 @@ processors:
214214
# Detector order is important: the `system` detector goes last so it can't preclude cloud detectors from setting host/os info.
215215
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourcedetectionprocessor#ordering
216216
resourcedetection/internal:
217-
detectors: [gce, ecs, ec2, azure, system]
217+
detectors: [gcp, ecs, ec2, azure, system]
218218
override: true
219219

220220
# Enables the memory limiter processor with default settings

cmd/otelcol/config/collector/gateway_config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ processors:
8383
# Detector order is important: the `system` detector goes last so it can't preclude cloud detectors from setting host/os info.
8484
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourcedetectionprocessor#ordering
8585
resourcedetection/internal:
86-
detectors: [gce, ecs, ec2, azure, system]
86+
detectors: [gcp, ecs, ec2, azure, system]
8787
override: true
8888

8989
exporters:

cmd/otelcol/config/collector/otlp_config_linux.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ processors:
7070
# Detector order is important: the `system` detector goes last so it can't preclude cloud detectors from setting host/os info.
7171
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourcedetectionprocessor#ordering
7272
resourcedetection/internal:
73-
detectors: [gce, ecs, ec2, azure, system]
73+
detectors: [gcp, ecs, ec2, azure, system]
7474
override: true
7575

7676
exporters:

cmd/otelcol/config/collector/upstream_agent_config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ processors:
100100
# libraries can send wrong values from container environments.
101101
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourcedetectionprocessor#ordering
102102
resourcedetection:
103-
detectors: [gce, ecs, ec2, azure, system]
103+
detectors: [gcp, ecs, ec2, azure, system]
104104
override: true
105105

106106
# Optional: The following processor can be used to add a default "deployment.environment" attribute to the logs and

cmd/translatesfx/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ by the `signalfx` exporter to generate cloud resource IDs.
396396
resourcedetection:
397397
detectors:
398398
- env
399-
- gce
399+
- gcp
400400
- ecs
401401
- ec2
402402
- azure

cmd/translatesfx/translatesfx/otel.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func newOtelCfg() *otelCfg {
6363
Receivers: map[string]map[string]any{},
6464
Processors: map[string]map[string]any{
6565
resourceDetection: {
66-
"detectors": []string{"system", "env", "gce", "ecs", "ec2", "azure"},
66+
"detectors": []string{"system", "env", "gcp", "ecs", "ec2", "azure"},
6767
},
6868
},
6969
Extensions: map[string]map[string]any{},

cmd/translatesfx/translatesfx/otel_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func TestInfoToOtelConfig_ResourceDetectionProcessor(t *testing.T) {
159159
assert.NotNil(t, oc.Processors)
160160
rdProc := oc.Processors["resourcedetection"]
161161
assert.Equal(t, map[string]any{
162-
"detectors": []string{"system", "env", "gce", "ecs", "ec2", "azure"},
162+
"detectors": []string{"system", "env", "gcp", "ecs", "ec2", "azure"},
163163
}, rdProc)
164164
assert.Equal(t, []string{"resourcedetection"}, oc.Service.Pipelines["metrics"].Processors)
165165
}

cmd/translatesfx/translatesfx/testdata/otel-e2e-expected.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ processors:
5656
detectors:
5757
- system
5858
- env
59-
- gce
59+
- gcp
6060
- ecs
6161
- ec2
6262
- azure

docs/apm-infra-correlation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ receivers:
6767
...
6868
processors:
6969
resourcedetection:
70-
detectors: [system,env,gce,ec2]
70+
detectors: [system,env,gcp,ec2]
7171
override: true
7272
resource/add_environment:
7373
attributes:
@@ -164,7 +164,7 @@ receivers:
164164
...
165165
processors:
166166
resourcedetection:
167-
detectors: [system,env,gce,ec2]
167+
detectors: [system,env,gcp,ec2]
168168
override: true
169169
resource/add_environment:
170170
attributes:

internal/configconverter/README.md

Whitespace-only changes.
+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package configconverter
16+
17+
import (
18+
"context"
19+
"fmt"
20+
"go.opentelemetry.io/collector/confmap"
21+
"log"
22+
)
23+
24+
type NormalizeGcp struct{}
25+
26+
func (NormalizeGcp) Convert(_ context.Context, in *confmap.Conf) error {
27+
if in == nil {
28+
return fmt.Errorf("cannot NormalizeGcp on nil *confmap.Conf")
29+
}
30+
31+
const resourceDetector = "processors::resourcedetection::detectors"
32+
out := map[string]any{}
33+
var nonNormalizedGcpDetectorFound bool
34+
for _, k := range in.AllKeys() {
35+
v := in.Get(k)
36+
match := resourceDetector == k
37+
if !match {
38+
out[k] = v
39+
} else {
40+
// v should be an array, maybe single string
41+
switch v.(type) {
42+
case string:
43+
if v == "gce" || v == "gke" {
44+
v = "gcp"
45+
}
46+
case []interface{}:
47+
vArr := v.([]interface{})
48+
normalizedV := make([]interface{}, 0, len(vArr))
49+
seen := false
50+
for _, item := range vArr {
51+
switch item.(type) {
52+
case string:
53+
if item == "gce" || item == "gke" {
54+
if !seen {
55+
normalizedV = append(normalizedV, "gcp")
56+
}
57+
seen = true
58+
} else if item != nil {
59+
normalizedV = append(normalizedV, item)
60+
}
61+
default:
62+
if item != nil {
63+
normalizedV = append(normalizedV, item)
64+
}
65+
}
66+
}
67+
v = normalizedV
68+
}
69+
out[resourceDetector] = v
70+
nonNormalizedGcpDetectorFound = true
71+
}
72+
}
73+
if nonNormalizedGcpDetectorFound {
74+
log.Println("[WARNING] `processors` -> `resourcedetection` -> `detectors` parameter " +
75+
"contains a deprecated configuration. Please update the config according to the guideline: " +
76+
"https://github.com/signalfx/splunk-otel-collector#from-0680-to-0690.")
77+
}
78+
79+
*in = *confmap.NewFromStringMap(out)
80+
return nil
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Copyright The OpenTelemetry Authors
16+
//
17+
// Licensed under the Apache License, Version 2.0 (the "License");
18+
// you may not use this file except in compliance with the License.
19+
// You may obtain a copy of the License at
20+
//
21+
// http://www.apache.org/licenses/LICENSE-2.0
22+
//
23+
// Unless required by applicable law or agreed to in writing, software
24+
// distributed under the License is distributed on an "AS IS" BASIS,
25+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26+
// See the License for the specific language governing permissions and
27+
// limitations under the License.
28+
29+
package configconverter
30+
31+
import (
32+
"context"
33+
"testing"
34+
35+
"github.com/stretchr/testify/assert"
36+
"github.com/stretchr/testify/require"
37+
"go.opentelemetry.io/collector/confmap/confmaptest"
38+
)
39+
40+
func TestNormalizeGcp(t *testing.T) {
41+
expectedCfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_post_migration.yaml")
42+
require.NotNil(t, expectedCfgMap)
43+
require.NoError(t, err)
44+
45+
cfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config.yaml")
46+
require.NoError(t, err)
47+
require.NotNil(t, cfgMap)
48+
49+
err = NormalizeGcp{}.Convert(context.Background(), cfgMap)
50+
require.NoError(t, err)
51+
52+
assert.Equal(t, expectedCfgMap, cfgMap)
53+
}
54+
55+
func TestNormalizeGcpMany(t *testing.T) {
56+
expectedCfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_post_migration.yaml")
57+
require.NotNil(t, expectedCfgMap)
58+
require.NoError(t, err)
59+
60+
cfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_many.yaml")
61+
require.NoError(t, err)
62+
require.NotNil(t, cfgMap)
63+
64+
err = NormalizeGcp{}.Convert(context.Background(), cfgMap)
65+
require.NoError(t, err)
66+
67+
assert.Equal(t, expectedCfgMap, cfgMap)
68+
}
69+
70+
func TestNormalizeGcpSame(t *testing.T) {
71+
expectedCfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_post_migration.yaml")
72+
require.NotNil(t, expectedCfgMap)
73+
require.NoError(t, err)
74+
75+
cfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_post_migration.yaml")
76+
require.NoError(t, err)
77+
require.NotNil(t, cfgMap)
78+
79+
err = NormalizeGcp{}.Convert(context.Background(), cfgMap)
80+
require.NoError(t, err)
81+
82+
assert.Equal(t, expectedCfgMap, cfgMap)
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
receivers:
2+
hostmetrics:
3+
collection_interval: 1s
4+
scrapers:
5+
cpu:
6+
processors:
7+
resourcedetection/gce:
8+
detectors: [gce]
9+
override: true
10+
resourcedetection/gcp:
11+
detectors: [gce]
12+
override: true
13+
resourcedetection/gke:
14+
detectors: [gke]
15+
override: true
16+
resourcedetection/all:
17+
detectors: [gcp, gce, gke]
18+
override: true
19+
resourcedetection/all.plus.non.gcp:
20+
detectors: [gcp, gce, gke, ec2]
21+
override: true
22+
exporters:
23+
logging:
24+
loglevel: info
25+
sampling_initial: 2
26+
sampling_thereafter: 500
27+
service:
28+
pipelines:
29+
metrics:
30+
receivers:
31+
- hostmetrics
32+
processors:
33+
- resourcedetection/gce
34+
exporters:
35+
- logging
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
processors:
2+
# Detect if the collector is running on a cloud system, which is important for creating unique cloud provider dimensions.
3+
# Detector order is important: the `system` detector goes last so it can't preclude cloud detectors from setting host/os info.
4+
# Resource detection processor is configured to override all host and cloud attributes because instrumentation
5+
# libraries can send wrong values from container environments.
6+
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourcedetectionprocessor#ordering
7+
resourcedetection:
8+
detectors: [gce, ecs, ec2, azure, system]
9+
override: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
processors:
2+
# Detect if the collector is running on a cloud system, which is important for creating unique cloud provider dimensions.
3+
# Detector order is important: the `system` detector goes last so it can't preclude cloud detectors from setting host/os info.
4+
# Resource detection processor is configured to override all host and cloud attributes because instrumentation
5+
# libraries can send wrong values from container environments.
6+
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourcedetectionprocessor#ordering
7+
resourcedetection:
8+
detectors: [gce, ecs, gke, ec2, azure, system]
9+
override: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
processors:
2+
# Detect if the collector is running on a cloud system, which is important for creating unique cloud provider dimensions.
3+
# Detector order is important: the `system` detector goes last so it can't preclude cloud detectors from setting host/os info.
4+
# Resource detection processor is configured to override all host and cloud attributes because instrumentation
5+
# libraries can send wrong values from container environments.
6+
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourcedetectionprocessor#ordering
7+
resourcedetection:
8+
detectors: [gcp, ecs, ec2, azure, system]
9+
override: true

internal/settings/settings.go

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ func (s *Settings) ConfMapConverters() []confmap.Converter {
147147
configconverter.MoveOTLPInsecureKey{},
148148
configconverter.MoveHecTLS{},
149149
configconverter.RenameK8sTagger{},
150+
configconverter.NormalizeGcp{},
150151
)
151152
}
152153
return confMapConverters

0 commit comments

Comments
 (0)