Skip to content

Commit e7f0204

Browse files
hughesjjatoulme
andauthored
Switch to gcp from gce/gke (#2488)
* Switch to gcp from gce as specified in open-telemetry/opentelemetry-collector-contrib#10348 Tracking issue: https://github.com/signalfx/splunk-otel-collector/issues/2474 * Update cmd/otelcol/config/collector/full_config_linux.yaml Co-authored-by: Antoine Toulme <[email protected]> Co-authored-by: Antoine Toulme <[email protected]>
1 parent c994348 commit e7f0204

21 files changed

+241
-13
lines changed

cmd/otelcol/config/collector/agent_config.yaml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ processors:
204204
# Enables the resource detection processor with default settings
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
207-
#resouredection:
208-
# # a list of resource detectors to run, valid options are: "env", "system", "gce", "ec2", "ecs", "elastic_beanstalk"
207+
#resourcedetection:
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
"log"
20+
"regexp"
21+
22+
"go.opentelemetry.io/collector/confmap"
23+
)
24+
25+
type NormalizeGcp struct{}
26+
27+
func (NormalizeGcp) Convert(_ context.Context, in *confmap.Conf) error {
28+
if in == nil {
29+
return nil
30+
}
31+
32+
const resourceDetector = "processors::resourcedetection(?P<processor_name>/(?:[^:]|:[^:])+)?::detectors"
33+
resourceDetectorRE := regexp.MustCompile(resourceDetector)
34+
out := map[string]any{}
35+
nonNormalizedGcpDetectorFound := false
36+
37+
for _, k := range in.AllKeys() {
38+
v := in.Get(k)
39+
match := resourceDetectorRE.FindStringSubmatch(k)
40+
if match != nil {
41+
if vArr, ok := v.([]interface{}); ok {
42+
normalizedV := make([]interface{}, 0, len(vArr))
43+
found := false
44+
for _, item := range vArr {
45+
switch item.(type) {
46+
case string:
47+
if item == "gce" || item == "gke" {
48+
if !found {
49+
normalizedV = append(normalizedV, "gcp")
50+
}
51+
found = true
52+
nonNormalizedGcpDetectorFound = true
53+
} else if item != nil {
54+
normalizedV = append(normalizedV, item)
55+
}
56+
default:
57+
if item != nil {
58+
normalizedV = append(normalizedV, item)
59+
}
60+
}
61+
}
62+
out[k] = normalizedV
63+
}
64+
}
65+
}
66+
if nonNormalizedGcpDetectorFound {
67+
log.Println("[WARNING] `processors` -> `resourcedetection` -> `detectors` parameter " +
68+
"contains a deprecated configuration. Please update the config according to the guideline: " +
69+
"https://github.com/signalfx/splunk-otel-collector#from-0680-to-0690.")
70+
}
71+
72+
in.Merge(confmap.NewFromStringMap(out))
73+
return nil
74+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
}
84+
85+
func TestNormalizeGcpNoop(t *testing.T) {
86+
expectedCfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_no_op.yaml")
87+
require.NotNil(t, expectedCfgMap)
88+
require.NoError(t, err)
89+
90+
cfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_no_op.yaml")
91+
require.NoError(t, err)
92+
require.NotNil(t, cfgMap)
93+
94+
err = NormalizeGcp{}.Convert(context.Background(), cfgMap)
95+
require.NoError(t, err)
96+
97+
assert.Equal(t, expectedCfgMap, cfgMap)
98+
}
99+
100+
func TestNormalizeGcpSubresources(t *testing.T) {
101+
expectedCfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_subresources_post_migration.yaml")
102+
require.NotNil(t, expectedCfgMap)
103+
require.NoError(t, err)
104+
105+
cfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_subresources.yaml")
106+
require.NoError(t, err)
107+
require.NotNil(t, cfgMap)
108+
109+
err = NormalizeGcp{}.Convert(context.Background(), cfgMap)
110+
require.NoError(t, err)
111+
112+
assert.Equal(t, expectedCfgMap, cfgMap)
113+
}
Lines changed: 9 additions & 0 deletions
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
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
processors:
2+
resourcedetection:
3+
detectors: [gce, ecs, gke, ec2, azure, system]
4+
override: true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
processors:
2+
resourcedetection:
3+
detectors: [ecs, ec2, azure, system]
4+
override: true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
processors:
2+
resourcedetection:
3+
detectors: [gcp, ecs, ec2, azure, system]
4+
override: true
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
processors:
2+
resourcedetection:
3+
detectors: [gce, ecs, gke, ec2, azure, system]
4+
resourcedetection/1:
5+
detectors: [gce, ecs, gke, ec2, azure, system]
6+
resourcedetection/abc:
7+
detectors: [gce, ecs, gke, ec2, azure, system]
8+
resourcedetection/abc123_+!@#%^&*():
9+
detectors: [gce, ecs, gke, ec2, azure, system]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
processors:
2+
resourcedetection:
3+
detectors: [gcp, ecs, ec2, azure, system]
4+
resourcedetection/1:
5+
detectors: [gcp, ecs, ec2, azure, system]
6+
resourcedetection/abc:
7+
detectors: [gcp, ecs, ec2, azure, system]
8+
resourcedetection/abc123_+!@#%^&*():
9+
detectors: [gcp, ecs, ec2, azure, system]

internal/settings/settings.go

Lines changed: 1 addition & 0 deletions
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

internal/settings/settings_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func TestNewSettingsConvertConfig(t *testing.T) {
133133
configconverter.MoveOTLPInsecureKey{},
134134
configconverter.MoveHecTLS{},
135135
configconverter.RenameK8sTagger{},
136+
configconverter.NormalizeGcp{},
136137
}, settings.ConfMapConverters())
137138
require.Equal(t, []string{"--feature-gates", "foo", "--feature-gates", "-bar"}, settings.ColCoreArgs())
138139
}

0 commit comments

Comments
 (0)