forked from open-telemetry/opentelemetry-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to gcp from gce/gke (open-telemetry#2488)
* Switch to gcp from gce as specified in open-telemetry/opentelemetry-collector-contrib#10348 Tracking issue: signalfx/splunk-otel-collector#2474 * Update cmd/otelcol/config/collector/full_config_linux.yaml Co-authored-by: Antoine Toulme <antoine@lunar-ocean.com> Co-authored-by: Antoine Toulme <antoine@lunar-ocean.com>
- Loading branch information
Showing
21 changed files
with
241 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ processors: | |
detectors: | ||
- system | ||
- env | ||
- gce | ||
- gcp | ||
- ecs | ||
- ec2 | ||
- azure | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package configconverter | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"regexp" | ||
|
||
"go.opentelemetry.io/collector/confmap" | ||
) | ||
|
||
type NormalizeGcp struct{} | ||
|
||
func (NormalizeGcp) Convert(_ context.Context, in *confmap.Conf) error { | ||
if in == nil { | ||
return nil | ||
} | ||
|
||
const resourceDetector = "processors::resourcedetection(?P<processor_name>/(?:[^:]|:[^:])+)?::detectors" | ||
resourceDetectorRE := regexp.MustCompile(resourceDetector) | ||
out := map[string]any{} | ||
nonNormalizedGcpDetectorFound := false | ||
|
||
for _, k := range in.AllKeys() { | ||
v := in.Get(k) | ||
match := resourceDetectorRE.FindStringSubmatch(k) | ||
if match != nil { | ||
if vArr, ok := v.([]interface{}); ok { | ||
normalizedV := make([]interface{}, 0, len(vArr)) | ||
found := false | ||
for _, item := range vArr { | ||
switch item.(type) { | ||
case string: | ||
if item == "gce" || item == "gke" { | ||
if !found { | ||
normalizedV = append(normalizedV, "gcp") | ||
} | ||
found = true | ||
nonNormalizedGcpDetectorFound = true | ||
} else if item != nil { | ||
normalizedV = append(normalizedV, item) | ||
} | ||
default: | ||
if item != nil { | ||
normalizedV = append(normalizedV, item) | ||
} | ||
} | ||
} | ||
out[k] = normalizedV | ||
} | ||
} | ||
} | ||
if nonNormalizedGcpDetectorFound { | ||
log.Println("[WARNING] `processors` -> `resourcedetection` -> `detectors` parameter " + | ||
"contains a deprecated configuration. Please update the config according to the guideline: " + | ||
"https://github.com/signalfx/splunk-otel-collector#from-0680-to-0690.") | ||
} | ||
|
||
in.Merge(confmap.NewFromStringMap(out)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package configconverter | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/confmap/confmaptest" | ||
) | ||
|
||
func TestNormalizeGcp(t *testing.T) { | ||
expectedCfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_post_migration.yaml") | ||
require.NotNil(t, expectedCfgMap) | ||
require.NoError(t, err) | ||
|
||
cfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config.yaml") | ||
require.NoError(t, err) | ||
require.NotNil(t, cfgMap) | ||
|
||
err = NormalizeGcp{}.Convert(context.Background(), cfgMap) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, expectedCfgMap, cfgMap) | ||
} | ||
|
||
func TestNormalizeGcpMany(t *testing.T) { | ||
expectedCfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_post_migration.yaml") | ||
require.NotNil(t, expectedCfgMap) | ||
require.NoError(t, err) | ||
|
||
cfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_many.yaml") | ||
require.NoError(t, err) | ||
require.NotNil(t, cfgMap) | ||
|
||
err = NormalizeGcp{}.Convert(context.Background(), cfgMap) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, expectedCfgMap, cfgMap) | ||
} | ||
|
||
func TestNormalizeGcpSame(t *testing.T) { | ||
expectedCfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_post_migration.yaml") | ||
require.NotNil(t, expectedCfgMap) | ||
require.NoError(t, err) | ||
|
||
cfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_post_migration.yaml") | ||
require.NoError(t, err) | ||
require.NotNil(t, cfgMap) | ||
|
||
err = NormalizeGcp{}.Convert(context.Background(), cfgMap) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, expectedCfgMap, cfgMap) | ||
} | ||
|
||
func TestNormalizeGcpNoop(t *testing.T) { | ||
expectedCfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_no_op.yaml") | ||
require.NotNil(t, expectedCfgMap) | ||
require.NoError(t, err) | ||
|
||
cfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_no_op.yaml") | ||
require.NoError(t, err) | ||
require.NotNil(t, cfgMap) | ||
|
||
err = NormalizeGcp{}.Convert(context.Background(), cfgMap) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, expectedCfgMap, cfgMap) | ||
} | ||
|
||
func TestNormalizeGcpSubresources(t *testing.T) { | ||
expectedCfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_subresources_post_migration.yaml") | ||
require.NotNil(t, expectedCfgMap) | ||
require.NoError(t, err) | ||
|
||
cfgMap, err := confmaptest.LoadConf("testdata/normalize_gcp/upstream_agent_config_subresources.yaml") | ||
require.NoError(t, err) | ||
require.NotNil(t, cfgMap) | ||
|
||
err = NormalizeGcp{}.Convert(context.Background(), cfgMap) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, expectedCfgMap, cfgMap) | ||
} |
9 changes: 9 additions & 0 deletions
9
internal/configconverter/testdata/normalize_gcp/upstream_agent_config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
processors: | ||
# Detect if the collector is running on a cloud system, which is important for creating unique cloud provider dimensions. | ||
# Detector order is important: the `system` detector goes last so it can't preclude cloud detectors from setting host/os info. | ||
# Resource detection processor is configured to override all host and cloud attributes because instrumentation | ||
# libraries can send wrong values from container environments. | ||
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/resourcedetectionprocessor#ordering | ||
resourcedetection: | ||
detectors: [gce, ecs, ec2, azure, system] | ||
override: true |
4 changes: 4 additions & 0 deletions
4
internal/configconverter/testdata/normalize_gcp/upstream_agent_config_many.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
processors: | ||
resourcedetection: | ||
detectors: [gce, ecs, gke, ec2, azure, system] | ||
override: true |
4 changes: 4 additions & 0 deletions
4
internal/configconverter/testdata/normalize_gcp/upstream_agent_config_no_op.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
processors: | ||
resourcedetection: | ||
detectors: [ecs, ec2, azure, system] | ||
override: true |
4 changes: 4 additions & 0 deletions
4
internal/configconverter/testdata/normalize_gcp/upstream_agent_config_post_migration.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
processors: | ||
resourcedetection: | ||
detectors: [gcp, ecs, ec2, azure, system] | ||
override: true |
9 changes: 9 additions & 0 deletions
9
internal/configconverter/testdata/normalize_gcp/upstream_agent_config_subresources.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
processors: | ||
resourcedetection: | ||
detectors: [gce, ecs, gke, ec2, azure, system] | ||
resourcedetection/1: | ||
detectors: [gce, ecs, gke, ec2, azure, system] | ||
resourcedetection/abc: | ||
detectors: [gce, ecs, gke, ec2, azure, system] | ||
resourcedetection/abc123_+!@#%^&*(): | ||
detectors: [gce, ecs, gke, ec2, azure, system] |
9 changes: 9 additions & 0 deletions
9
...igconverter/testdata/normalize_gcp/upstream_agent_config_subresources_post_migration.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
processors: | ||
resourcedetection: | ||
detectors: [gcp, ecs, ec2, azure, system] | ||
resourcedetection/1: | ||
detectors: [gcp, ecs, ec2, azure, system] | ||
resourcedetection/abc: | ||
detectors: [gcp, ecs, ec2, azure, system] | ||
resourcedetection/abc123_+!@#%^&*(): | ||
detectors: [gcp, ecs, ec2, azure, system] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters