Skip to content

bugfix: remove deprecated resource detectors #17383

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

Merged
merged 3 commits into from
Jan 4, 2023
Merged
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
16 changes: 16 additions & 0 deletions .chloggen/fix-10348.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: resourcedetectionprocessor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove deprecated gke/gce detectors, use gcp instead.

# One or more tracking issues related to the change
issues: [10348]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
4 changes: 2 additions & 2 deletions processor/resourcedetectionprocessor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func TestLoadConfig(t *testing.T) {
errorMessage string
}{
{
id: component.NewIDWithName(typeStr, "gce"),
id: component.NewIDWithName(typeStr, "gcp"),
expected: &Config{
Detectors: []string{"env", "gce"},
Detectors: []string{"env", "gcp"},
HTTPClientSettings: cfg,
Override: false,
},
Expand Down
6 changes: 0 additions & 6 deletions processor/resourcedetectionprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ func NewFactory() processor.Factory {
elasticbeanstalk.TypeStr: elasticbeanstalk.NewDetector,
env.TypeStr: env.NewDetector,
gcp.TypeStr: gcp.NewDetector,
// TODO(#10348): Remove GKE and GCE after the v0.54.0 release.
gcp.DeprecatedGKETypeStr: gcp.NewDetector,
gcp.DeprecatedGCETypeStr: gcp.NewDetector,
system.TypeStr: system.NewDetector,
})

Expand Down Expand Up @@ -208,9 +205,6 @@ func (f *factory) getResourceProvider(
return provider, nil
}

// TODO(#10348): Remove this after the v0.54.0 release.
configuredDetectors = gcp.DeduplicateDetectors(params, configuredDetectors)

detectorTypes := make([]internal.DetectorType, 0, len(configuredDetectors))
for _, key := range configuredDetectors {
detectorTypes = append(detectorTypes, internal.DetectorType(strings.TrimSpace(key)))
Expand Down
32 changes: 0 additions & 32 deletions processor/resourcedetectionprocessor/internal/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ import (
const (
// TypeStr is type of detector.
TypeStr = "gcp"
// 'gke' and 'gce' detectors are replaced with the unified 'gcp' detector
// TODO(#10348): Remove these after the v0.54.0 release.
DeprecatedGKETypeStr = "gke"
DeprecatedGCETypeStr = "gce"
)

// NewDetector returns a detector which can detect resource attributes on:
Expand Down Expand Up @@ -164,31 +160,3 @@ func (r *resourceBuilder) addZoneOrRegion(detect func() (string, gcp.LocationTyp
r.errs = append(r.errs, fmt.Errorf("location must be zone or region. Got %v", locType))
}
}

// DeduplicateDetectors ensures only one of ['gcp','gke','gce'] are present in
// the list of detectors. Currently, users configure both GCE and GKE detectors
// when running on GKE. Resource merge would fail in this case if we don't
// deduplicate, which would break users.
// TODO(#10348): Remove this function after the v0.54.0 release.
func DeduplicateDetectors(set processor.CreateSettings, detectors []string) []string {
var out []string
var found bool
for _, d := range detectors {
switch d {
case DeprecatedGKETypeStr:
set.Logger.Warn("The 'gke' detector is deprecated. Use the 'gcp' detector instead.")
case DeprecatedGCETypeStr:
set.Logger.Warn("The 'gce' detector is deprecated. Use the 'gcp' detector instead.")
case TypeStr:
default:
out = append(out, d)
continue
}
// ensure we only keep the first GCP detector we find.
if !found {
found = true
out = append(out, d)
}
}
return out
}
44 changes: 0 additions & 44 deletions processor/resourcedetectionprocessor/internal/gcp/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

"github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/processor/processortest"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
"go.uber.org/zap"

Expand Down Expand Up @@ -403,46 +402,3 @@ func (f *fakeGCPDetector) GCEHostName() (string, error) {
}
return f.gceHostName, f.gceHostNameErr
}

func TestDeduplicateDetectors(t *testing.T) {
for _, tc := range []struct {
desc string
in []string
expected []string
}{
{
desc: "empty",
expected: nil,
},
{
desc: "single gcp",
in: []string{"gcp"},
expected: []string{"gcp"},
},
{
desc: "single gce",
in: []string{"gce"},
expected: []string{"gce"},
},
{
desc: "single gke",
in: []string{"gke"},
expected: []string{"gke"},
},
{
desc: "multi",
in: []string{"gcp", "gce", "gke"},
expected: []string{"gcp"},
},
{
desc: "multi with others",
in: []string{"foo", "gcp", "gce", "bar", "gke"},
expected: []string{"foo", "gcp", "bar"},
},
} {
t.Run(tc.desc, func(t *testing.T) {
out := DeduplicateDetectors(processortest.NewNopCreateSettings(), tc.in)
assert.Equal(t, tc.expected, out)
})
}
}
4 changes: 2 additions & 2 deletions processor/resourcedetectionprocessor/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resourcedetection:
resourcedetection/gce:
detectors: [env, gce]
resourcedetection/gcp:
detectors: [env, gcp]
timeout: 2s
override: false

Expand Down