Skip to content

Commit

Permalink
add feature gate
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Oct 5, 2023
1 parent 602a97b commit 84b5d76
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .chloggen/gcp-faas-instance.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'breaking'
change_type: 'deprecation'

# 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: Switch from detecting faas.id to faas.instance in the gcp detector.
note: Detect faas.instance in the gcp detector, and deprecate detecting faas.id in the gcp detector.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [26486]
Expand All @@ -24,4 +24,4 @@ subtext: faas.id has been removed from the semantic conventions.
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
change_logs: [user]
4 changes: 2 additions & 2 deletions processor/resourcedetectionprocessor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/google/go-cmp v0.5.9
github.com/hashicorp/consul/api v1.25.1
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/ecsutil v0.86.1-0.20231004185026-b5635a7a90d2
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.86.1-0.20231004185026-b5635a7a90d2
github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig v0.86.1-0.20231004185026-b5635a7a90d2
github.com/open-telemetry/opentelemetry-collector-contrib/internal/metadataproviders v0.86.1-0.20231004185026-b5635a7a90d2
github.com/shirou/gopsutil/v3 v3.23.9
Expand All @@ -19,6 +20,7 @@ require (
go.opentelemetry.io/collector/config/configtls v0.86.1-0.20231004185026-b5635a7a90d2
go.opentelemetry.io/collector/confmap v0.86.1-0.20231004185026-b5635a7a90d2
go.opentelemetry.io/collector/consumer v0.86.1-0.20231004185026-b5635a7a90d2
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0015.0.20231004185026-b5635a7a90d2
go.opentelemetry.io/collector/pdata v1.0.0-rcv0015.0.20231004185026-b5635a7a90d2
go.opentelemetry.io/collector/processor v0.86.1-0.20231004185026-b5635a7a90d2
go.opentelemetry.io/collector/semconv v0.86.1-0.20231004185026-b5635a7a90d2
Expand Down Expand Up @@ -79,7 +81,6 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.86.1-0.20231004185026-b5635a7a90d2 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/openshift/api v3.9.0+incompatible // indirect
Expand All @@ -102,7 +103,6 @@ require (
go.opentelemetry.io/collector/config/internal v0.86.1-0.20231004185026-b5635a7a90d2 // indirect
go.opentelemetry.io/collector/extension v0.86.1-0.20231004185026-b5635a7a90d2 // indirect
go.opentelemetry.io/collector/extension/auth v0.86.1-0.20231004185026-b5635a7a90d2 // indirect
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0015.0.20231004185026-b5635a7a90d2 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
Expand Down
22 changes: 22 additions & 0 deletions processor/resourcedetectionprocessor/internal/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"cloud.google.com/go/compute/metadata"
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/processor"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
Expand All @@ -23,6 +24,12 @@ const (
TypeStr = "gcp"
)

var removeGCPFaasID = featuregate.GlobalRegistry().MustRegister(
"processor.resourcedetection.removeGCPFaasID",
featuregate.StageAlpha,
featuregate.WithRegisterDescription("Remove faas.id from the GCP detector. Use faas.instance instead."),
featuregate.WithRegisterFromVersion("v0.85.0"))

// NewDetector returns a detector which can detect resource attributes on:
// * Google Compute Engine (GCE).
// * Google Kubernetes Engine (GKE).
Expand Down Expand Up @@ -75,6 +82,9 @@ func (d *detector) Detect(context.Context) (resource pcommon.Resource, schemaURL
d.rb.SetFromCallable(d.rb.SetFaasInstance, d.detector.FaaSID),
d.rb.SetFromCallable(d.rb.SetCloudRegion, d.detector.FaaSCloudRegion),
)
if !removeGCPFaasID.IsEnabled() {
errs = multierr.Combine(errs, d.rb.SetFromCallable(d.rb.SetFaasID, d.detector.FaaSID))
}
case gcp.CloudRunJob:
d.rb.SetCloudPlatform(conventions.AttributeCloudPlatformGCPCloudRun)
errs = multierr.Combine(errs,
Expand All @@ -84,6 +94,9 @@ func (d *detector) Detect(context.Context) (resource pcommon.Resource, schemaURL
d.rb.SetFromCallable(d.rb.SetGcpCloudRunJobExecution, d.detector.CloudRunJobExecution),
d.rb.SetFromCallable(d.rb.SetGcpCloudRunJobTaskIndex, d.detector.CloudRunJobTaskIndex),
)
if !removeGCPFaasID.IsEnabled() {
errs = multierr.Combine(errs, d.rb.SetFromCallable(d.rb.SetFaasID, d.detector.FaaSID))
}
case gcp.CloudFunctions:
d.rb.SetCloudPlatform(conventions.AttributeCloudPlatformGCPCloudFunctions)
errs = multierr.Combine(errs,
Expand All @@ -92,6 +105,9 @@ func (d *detector) Detect(context.Context) (resource pcommon.Resource, schemaURL
d.rb.SetFromCallable(d.rb.SetFaasInstance, d.detector.FaaSID),
d.rb.SetFromCallable(d.rb.SetCloudRegion, d.detector.FaaSCloudRegion),
)
if !removeGCPFaasID.IsEnabled() {
errs = multierr.Combine(errs, d.rb.SetFromCallable(d.rb.SetFaasID, d.detector.FaaSID))
}
case gcp.AppEngineFlex:
d.rb.SetCloudPlatform(conventions.AttributeCloudPlatformGCPAppEngine)
errs = multierr.Combine(errs,
Expand All @@ -100,6 +116,9 @@ func (d *detector) Detect(context.Context) (resource pcommon.Resource, schemaURL
d.rb.SetFromCallable(d.rb.SetFaasVersion, d.detector.AppEngineServiceVersion),
d.rb.SetFromCallable(d.rb.SetFaasInstance, d.detector.AppEngineServiceInstance),
)
if !removeGCPFaasID.IsEnabled() {
errs = multierr.Combine(errs, d.rb.SetFromCallable(d.rb.SetFaasID, d.detector.AppEngineServiceInstance))
}
case gcp.AppEngineStandard:
d.rb.SetCloudPlatform(conventions.AttributeCloudPlatformGCPAppEngine)
errs = multierr.Combine(errs,
Expand All @@ -109,6 +128,9 @@ func (d *detector) Detect(context.Context) (resource pcommon.Resource, schemaURL
d.rb.SetFromCallable(d.rb.SetCloudAvailabilityZone, d.detector.AppEngineStandardAvailabilityZone),
d.rb.SetFromCallable(d.rb.SetCloudRegion, d.detector.AppEngineStandardCloudRegion),
)
if !removeGCPFaasID.IsEnabled() {
errs = multierr.Combine(errs, d.rb.SetFromCallable(d.rb.SetFaasID, d.detector.AppEngineServiceInstance))
}
case gcp.GCE:
d.rb.SetCloudPlatform(conventions.AttributeCloudPlatformGCPComputeEngine)
errs = multierr.Combine(errs,
Expand Down
119 changes: 119 additions & 0 deletions processor/resourcedetectionprocessor/internal/gcp/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal"
localMetadata "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/gcp/internal/metadata"
)
Expand All @@ -26,6 +27,7 @@ func TestDetect(t *testing.T) {
detector internal.Detector
expectErr bool
expectedResource map[string]any
addFaasID bool
}{
{
desc: "zonal GKE cluster",
Expand Down Expand Up @@ -159,6 +161,28 @@ func TestDetect(t *testing.T) {
conventions.AttributeFaaSInstance: "1472385723456792345",
},
},
{
desc: "Cloud Run with feature gate disabled",
detector: newTestDetector(&fakeGCPDetector{
projectID: "my-project",
cloudPlatform: gcp.CloudRun,
faaSID: "1472385723456792345",
faaSCloudRegion: "us-central1",
faaSName: "my-service",
faaSVersion: "123456",
}),
expectedResource: map[string]any{
conventions.AttributeCloudProvider: conventions.AttributeCloudProviderGCP,
conventions.AttributeCloudAccountID: "my-project",
conventions.AttributeCloudPlatform: conventions.AttributeCloudPlatformGCPCloudRun,
conventions.AttributeCloudRegion: "us-central1",
conventions.AttributeFaaSName: "my-service",
conventions.AttributeFaaSVersion: "123456",
conventions.AttributeFaaSInstance: "1472385723456792345",
conventions.AttributeFaaSID: "1472385723456792345",
},
addFaasID: true,
},
{
desc: "Cloud Run Job",
detector: newTestDetector(&fakeGCPDetector{
Expand All @@ -181,6 +205,30 @@ func TestDetect(t *testing.T) {
"gcp.cloud_run.job.task_index": "2",
},
},
{
desc: "Cloud Run Job with feature gate disabled",
detector: newTestDetector(&fakeGCPDetector{
projectID: "my-project",
cloudPlatform: gcp.CloudRunJob,
faaSID: "1472385723456792345",
faaSCloudRegion: "us-central1",
faaSName: "my-service",
gcpCloudRunJobExecution: "my-service-ajg89",
gcpCloudRunJobTaskIndex: "2",
}),
expectedResource: map[string]any{
conventions.AttributeCloudProvider: conventions.AttributeCloudProviderGCP,
conventions.AttributeCloudAccountID: "my-project",
conventions.AttributeCloudPlatform: conventions.AttributeCloudPlatformGCPCloudRun,
conventions.AttributeCloudRegion: "us-central1",
conventions.AttributeFaaSName: "my-service",
conventions.AttributeFaaSInstance: "1472385723456792345",
conventions.AttributeFaaSID: "1472385723456792345",
"gcp.cloud_run.job.execution": "my-service-ajg89",
"gcp.cloud_run.job.task_index": "2",
},
addFaasID: true,
},
{
desc: "Cloud Functions",
detector: newTestDetector(&fakeGCPDetector{
Expand All @@ -201,6 +249,28 @@ func TestDetect(t *testing.T) {
conventions.AttributeFaaSInstance: "1472385723456792345",
},
},
{
desc: "Cloud Functions with feature gate disabled",
detector: newTestDetector(&fakeGCPDetector{
projectID: "my-project",
cloudPlatform: gcp.CloudFunctions,
faaSID: "1472385723456792345",
faaSCloudRegion: "us-central1",
faaSName: "my-service",
faaSVersion: "123456",
}),
expectedResource: map[string]any{
conventions.AttributeCloudProvider: conventions.AttributeCloudProviderGCP,
conventions.AttributeCloudAccountID: "my-project",
conventions.AttributeCloudPlatform: conventions.AttributeCloudPlatformGCPCloudFunctions,
conventions.AttributeCloudRegion: "us-central1",
conventions.AttributeFaaSName: "my-service",
conventions.AttributeFaaSVersion: "123456",
conventions.AttributeFaaSInstance: "1472385723456792345",
conventions.AttributeFaaSID: "1472385723456792345",
},
addFaasID: true,
},
{
desc: "App Engine Standard",
detector: newTestDetector(&fakeGCPDetector{
Expand All @@ -223,6 +293,30 @@ func TestDetect(t *testing.T) {
conventions.AttributeFaaSInstance: "1472385723456792345",
},
},
{
desc: "App Engine Standard with feature gate disabled",
detector: newTestDetector(&fakeGCPDetector{
projectID: "my-project",
cloudPlatform: gcp.AppEngineStandard,
appEngineServiceInstance: "1472385723456792345",
appEngineAvailabilityZone: "us-central1-c",
appEngineRegion: "us-central1",
appEngineServiceName: "my-service",
appEngineServiceVersion: "123456",
}),
expectedResource: map[string]any{
conventions.AttributeCloudProvider: conventions.AttributeCloudProviderGCP,
conventions.AttributeCloudAccountID: "my-project",
conventions.AttributeCloudPlatform: conventions.AttributeCloudPlatformGCPAppEngine,
conventions.AttributeCloudRegion: "us-central1",
conventions.AttributeCloudAvailabilityZone: "us-central1-c",
conventions.AttributeFaaSName: "my-service",
conventions.AttributeFaaSVersion: "123456",
conventions.AttributeFaaSInstance: "1472385723456792345",
conventions.AttributeFaaSID: "1472385723456792345",
},
addFaasID: true,
},
{
desc: "App Engine Flex",
detector: newTestDetector(&fakeGCPDetector{
Expand All @@ -245,6 +339,30 @@ func TestDetect(t *testing.T) {
conventions.AttributeFaaSInstance: "1472385723456792345",
},
},
{
desc: "App Engine Flex with feature gate disabled",
detector: newTestDetector(&fakeGCPDetector{
projectID: "my-project",
cloudPlatform: gcp.AppEngineFlex,
appEngineServiceInstance: "1472385723456792345",
appEngineAvailabilityZone: "us-central1-c",
appEngineRegion: "us-central1",
appEngineServiceName: "my-service",
appEngineServiceVersion: "123456",
}),
expectedResource: map[string]any{
conventions.AttributeCloudProvider: conventions.AttributeCloudProviderGCP,
conventions.AttributeCloudAccountID: "my-project",
conventions.AttributeCloudPlatform: conventions.AttributeCloudPlatformGCPAppEngine,
conventions.AttributeCloudRegion: "us-central1",
conventions.AttributeCloudAvailabilityZone: "us-central1-c",
conventions.AttributeFaaSName: "my-service",
conventions.AttributeFaaSVersion: "123456",
conventions.AttributeFaaSInstance: "1472385723456792345",
conventions.AttributeFaaSID: "1472385723456792345",
},
addFaasID: true,
},
{
desc: "Unknown Platform",
detector: newTestDetector(&fakeGCPDetector{
Expand All @@ -268,6 +386,7 @@ func TestDetect(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
defer testutil.SetFeatureGateForTest(t, removeGCPFaasID, !tc.addFaasID)()
res, schema, err := tc.detector.Detect(context.TODO())
if tc.expectErr {
assert.Error(t, err)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ all_set:
enabled: true
cloud.region:
enabled: true
faas.id:
enabled: true
faas.instance:
enabled: true
faas.name:
Expand Down Expand Up @@ -45,6 +47,8 @@ none_set:
enabled: false
cloud.region:
enabled: false
faas.id:
enabled: false
faas.instance:
enabled: false
faas.name:
Expand Down
Loading

0 comments on commit 84b5d76

Please sign in to comment.