From 602a97bb69d78301eff04b5ac4ceab10a03e9d45 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Wed, 6 Sep 2023 18:51:58 +0000 Subject: [PATCH 1/3] Switch from detecting faas.id to faas.instance in the gcp detector. --- .chloggen/gcp-faas-instance.yaml | 27 +++++++++++++++++++ .../internal/gcp/gcp.go | 10 +++---- .../internal/gcp/gcp_test.go | 10 +++---- .../gcp/internal/metadata/generated_config.go | 4 +-- .../metadata/generated_config_test.go | 4 +-- .../internal/metadata/generated_resource.go | 8 +++--- .../metadata/generated_resource_test.go | 6 ++--- .../internal/metadata/testdata/config.yaml | 4 +-- .../internal/gcp/metadata.yaml | 4 +-- 9 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 .chloggen/gcp-faas-instance.yaml diff --git a/.chloggen/gcp-faas-instance.yaml b/.chloggen/gcp-faas-instance.yaml new file mode 100644 index 000000000000..cbf50483e70a --- /dev/null +++ b/.chloggen/gcp-faas-instance.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# 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: Switch from detecting faas.id to faas.instance 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] + +# (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: faas.id has been removed from the semantic conventions. + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# 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: [] diff --git a/processor/resourcedetectionprocessor/internal/gcp/gcp.go b/processor/resourcedetectionprocessor/internal/gcp/gcp.go index c1e7d74184c9..044eda81ef37 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/gcp.go +++ b/processor/resourcedetectionprocessor/internal/gcp/gcp.go @@ -72,7 +72,7 @@ func (d *detector) Detect(context.Context) (resource pcommon.Resource, schemaURL errs = multierr.Combine(errs, d.rb.SetFromCallable(d.rb.SetFaasName, d.detector.FaaSName), d.rb.SetFromCallable(d.rb.SetFaasVersion, d.detector.FaaSVersion), - d.rb.SetFromCallable(d.rb.SetFaasID, d.detector.FaaSID), + d.rb.SetFromCallable(d.rb.SetFaasInstance, d.detector.FaaSID), d.rb.SetFromCallable(d.rb.SetCloudRegion, d.detector.FaaSCloudRegion), ) case gcp.CloudRunJob: @@ -80,7 +80,7 @@ func (d *detector) Detect(context.Context) (resource pcommon.Resource, schemaURL errs = multierr.Combine(errs, d.rb.SetFromCallable(d.rb.SetFaasName, d.detector.FaaSName), d.rb.SetFromCallable(d.rb.SetCloudRegion, d.detector.FaaSCloudRegion), - d.rb.SetFromCallable(d.rb.SetFaasID, d.detector.FaaSID), + d.rb.SetFromCallable(d.rb.SetFaasInstance, d.detector.FaaSID), d.rb.SetFromCallable(d.rb.SetGcpCloudRunJobExecution, d.detector.CloudRunJobExecution), d.rb.SetFromCallable(d.rb.SetGcpCloudRunJobTaskIndex, d.detector.CloudRunJobTaskIndex), ) @@ -89,7 +89,7 @@ func (d *detector) Detect(context.Context) (resource pcommon.Resource, schemaURL errs = multierr.Combine(errs, d.rb.SetFromCallable(d.rb.SetFaasName, d.detector.FaaSName), d.rb.SetFromCallable(d.rb.SetFaasVersion, d.detector.FaaSVersion), - d.rb.SetFromCallable(d.rb.SetFaasID, d.detector.FaaSID), + d.rb.SetFromCallable(d.rb.SetFaasInstance, d.detector.FaaSID), d.rb.SetFromCallable(d.rb.SetCloudRegion, d.detector.FaaSCloudRegion), ) case gcp.AppEngineFlex: @@ -98,14 +98,14 @@ func (d *detector) Detect(context.Context) (resource pcommon.Resource, schemaURL d.rb.SetZoneAndRegion(d.detector.AppEngineFlexAvailabilityZoneAndRegion), d.rb.SetFromCallable(d.rb.SetFaasName, d.detector.AppEngineServiceName), d.rb.SetFromCallable(d.rb.SetFaasVersion, d.detector.AppEngineServiceVersion), - d.rb.SetFromCallable(d.rb.SetFaasID, d.detector.AppEngineServiceInstance), + d.rb.SetFromCallable(d.rb.SetFaasInstance, d.detector.AppEngineServiceInstance), ) case gcp.AppEngineStandard: d.rb.SetCloudPlatform(conventions.AttributeCloudPlatformGCPAppEngine) errs = multierr.Combine(errs, d.rb.SetFromCallable(d.rb.SetFaasName, d.detector.AppEngineServiceName), d.rb.SetFromCallable(d.rb.SetFaasVersion, d.detector.AppEngineServiceVersion), - d.rb.SetFromCallable(d.rb.SetFaasID, d.detector.AppEngineServiceInstance), + d.rb.SetFromCallable(d.rb.SetFaasInstance, d.detector.AppEngineServiceInstance), d.rb.SetFromCallable(d.rb.SetCloudAvailabilityZone, d.detector.AppEngineStandardAvailabilityZone), d.rb.SetFromCallable(d.rb.SetCloudRegion, d.detector.AppEngineStandardCloudRegion), ) diff --git a/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go b/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go index 906dcebe7b2e..890bdc8ac6f3 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go +++ b/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go @@ -156,7 +156,7 @@ func TestDetect(t *testing.T) { conventions.AttributeCloudRegion: "us-central1", conventions.AttributeFaaSName: "my-service", conventions.AttributeFaaSVersion: "123456", - conventions.AttributeFaaSID: "1472385723456792345", + conventions.AttributeFaaSInstance: "1472385723456792345", }, }, { @@ -176,7 +176,7 @@ func TestDetect(t *testing.T) { conventions.AttributeCloudPlatform: conventions.AttributeCloudPlatformGCPCloudRun, conventions.AttributeCloudRegion: "us-central1", conventions.AttributeFaaSName: "my-service", - conventions.AttributeFaaSID: "1472385723456792345", + conventions.AttributeFaaSInstance: "1472385723456792345", "gcp.cloud_run.job.execution": "my-service-ajg89", "gcp.cloud_run.job.task_index": "2", }, @@ -198,7 +198,7 @@ func TestDetect(t *testing.T) { conventions.AttributeCloudRegion: "us-central1", conventions.AttributeFaaSName: "my-service", conventions.AttributeFaaSVersion: "123456", - conventions.AttributeFaaSID: "1472385723456792345", + conventions.AttributeFaaSInstance: "1472385723456792345", }, }, { @@ -220,7 +220,7 @@ func TestDetect(t *testing.T) { conventions.AttributeCloudAvailabilityZone: "us-central1-c", conventions.AttributeFaaSName: "my-service", conventions.AttributeFaaSVersion: "123456", - conventions.AttributeFaaSID: "1472385723456792345", + conventions.AttributeFaaSInstance: "1472385723456792345", }, }, { @@ -242,7 +242,7 @@ func TestDetect(t *testing.T) { conventions.AttributeCloudAvailabilityZone: "us-central1-c", conventions.AttributeFaaSName: "my-service", conventions.AttributeFaaSVersion: "123456", - conventions.AttributeFaaSID: "1472385723456792345", + conventions.AttributeFaaSInstance: "1472385723456792345", }, }, { diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go index 732dff567288..8bcdbca49fe4 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go @@ -14,7 +14,7 @@ type ResourceAttributesConfig struct { CloudPlatform ResourceAttributeConfig `mapstructure:"cloud.platform"` CloudProvider ResourceAttributeConfig `mapstructure:"cloud.provider"` CloudRegion ResourceAttributeConfig `mapstructure:"cloud.region"` - FaasID ResourceAttributeConfig `mapstructure:"faas.id"` + FaasInstance ResourceAttributeConfig `mapstructure:"faas.instance"` FaasName ResourceAttributeConfig `mapstructure:"faas.name"` FaasVersion ResourceAttributeConfig `mapstructure:"faas.version"` GcpCloudRunJobExecution ResourceAttributeConfig `mapstructure:"gcp.cloud_run.job.execution"` @@ -44,7 +44,7 @@ func DefaultResourceAttributesConfig() ResourceAttributesConfig { CloudRegion: ResourceAttributeConfig{ Enabled: true, }, - FaasID: ResourceAttributeConfig{ + FaasInstance: ResourceAttributeConfig{ Enabled: true, }, FaasName: ResourceAttributeConfig{ diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go index 463c4a40d572..528387e0a2af 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go @@ -30,7 +30,7 @@ func TestResourceAttributesConfig(t *testing.T) { CloudPlatform: ResourceAttributeConfig{Enabled: true}, CloudProvider: ResourceAttributeConfig{Enabled: true}, CloudRegion: ResourceAttributeConfig{Enabled: true}, - FaasID: ResourceAttributeConfig{Enabled: true}, + FaasInstance: ResourceAttributeConfig{Enabled: true}, FaasName: ResourceAttributeConfig{Enabled: true}, FaasVersion: ResourceAttributeConfig{Enabled: true}, GcpCloudRunJobExecution: ResourceAttributeConfig{Enabled: true}, @@ -51,7 +51,7 @@ func TestResourceAttributesConfig(t *testing.T) { CloudPlatform: ResourceAttributeConfig{Enabled: false}, CloudProvider: ResourceAttributeConfig{Enabled: false}, CloudRegion: ResourceAttributeConfig{Enabled: false}, - FaasID: ResourceAttributeConfig{Enabled: false}, + FaasInstance: ResourceAttributeConfig{Enabled: false}, FaasName: ResourceAttributeConfig{Enabled: false}, FaasVersion: ResourceAttributeConfig{Enabled: false}, GcpCloudRunJobExecution: ResourceAttributeConfig{Enabled: false}, diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go index 6059deb79488..4c072445e92e 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go @@ -56,10 +56,10 @@ func (rb *ResourceBuilder) SetCloudRegion(val string) { } } -// SetFaasID sets provided value as "faas.id" attribute. -func (rb *ResourceBuilder) SetFaasID(val string) { - if rb.config.FaasID.Enabled { - rb.res.Attributes().PutStr("faas.id", val) +// SetFaasInstance sets provided value as "faas.instance" attribute. +func (rb *ResourceBuilder) SetFaasInstance(val string) { + if rb.config.FaasInstance.Enabled { + rb.res.Attributes().PutStr("faas.instance", val) } } diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go index 40cde6496465..bd99898a3b57 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go @@ -18,7 +18,7 @@ func TestResourceBuilder(t *testing.T) { rb.SetCloudPlatform("cloud.platform-val") rb.SetCloudProvider("cloud.provider-val") rb.SetCloudRegion("cloud.region-val") - rb.SetFaasID("faas.id-val") + rb.SetFaasInstance("faas.instance-val") rb.SetFaasName("faas.name-val") rb.SetFaasVersion("faas.version-val") rb.SetGcpCloudRunJobExecution("gcp.cloud_run.job.execution-val") @@ -70,10 +70,10 @@ func TestResourceBuilder(t *testing.T) { if ok { assert.EqualValues(t, "cloud.region-val", val.Str()) } - val, ok = res.Attributes().Get("faas.id") + val, ok = res.Attributes().Get("faas.instance") assert.True(t, ok) if ok { - assert.EqualValues(t, "faas.id-val", val.Str()) + assert.EqualValues(t, "faas.instance-val", val.Str()) } val, ok = res.Attributes().Get("faas.name") assert.True(t, ok) diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml index 14d08c050cd0..8561a3a99e79 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml @@ -11,7 +11,7 @@ all_set: enabled: true cloud.region: enabled: true - faas.id: + faas.instance: enabled: true faas.name: enabled: true @@ -45,7 +45,7 @@ none_set: enabled: false cloud.region: enabled: false - faas.id: + faas.instance: enabled: false faas.name: enabled: false diff --git a/processor/resourcedetectionprocessor/internal/gcp/metadata.yaml b/processor/resourcedetectionprocessor/internal/gcp/metadata.yaml index 4cfe81b2b4a0..e9cc9a458571 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/metadata.yaml +++ b/processor/resourcedetectionprocessor/internal/gcp/metadata.yaml @@ -43,8 +43,8 @@ resource_attributes: description: The faas.version type: string enabled: true - faas.id: - description: The faas.id + faas.instance: + description: The faas.instance type: string enabled: true k8s.cluster.name: From 84b5d762e75ceaed4248780c04008f49ff79c16c Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Mon, 18 Sep 2023 15:32:13 +0000 Subject: [PATCH 2/3] add feature gate --- .chloggen/gcp-faas-instance.yaml | 6 +- processor/resourcedetectionprocessor/go.mod | 4 +- .../internal/gcp/gcp.go | 22 ++++ .../internal/gcp/gcp_test.go | 119 ++++++++++++++++++ .../gcp/internal/metadata/generated_config.go | 4 + .../metadata/generated_config_test.go | 2 + .../internal/metadata/generated_resource.go | 7 ++ .../metadata/generated_resource_test.go | 10 +- .../internal/metadata/testdata/config.yaml | 4 + .../internal/gcp/metadata.yaml | 4 + 10 files changed, 175 insertions(+), 7 deletions(-) diff --git a/.chloggen/gcp-faas-instance.yaml b/.chloggen/gcp-faas-instance.yaml index cbf50483e70a..fb7ba053ced2 100644 --- a/.chloggen/gcp-faas-instance.yaml +++ b/.chloggen/gcp-faas-instance.yaml @@ -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] @@ -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] diff --git a/processor/resourcedetectionprocessor/go.mod b/processor/resourcedetectionprocessor/go.mod index 57ffadf15912..8697fa2f2696 100644 --- a/processor/resourcedetectionprocessor/go.mod +++ b/processor/resourcedetectionprocessor/go.mod @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/processor/resourcedetectionprocessor/internal/gcp/gcp.go b/processor/resourcedetectionprocessor/internal/gcp/gcp.go index 044eda81ef37..8637266266eb 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/gcp.go +++ b/processor/resourcedetectionprocessor/internal/gcp/gcp.go @@ -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" @@ -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). @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go b/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go index 890bdc8ac6f3..3dce53426e8b 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go +++ b/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go @@ -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" ) @@ -26,6 +27,7 @@ func TestDetect(t *testing.T) { detector internal.Detector expectErr bool expectedResource map[string]any + addFaasID bool }{ { desc: "zonal GKE cluster", @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -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) diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go index 8bcdbca49fe4..b54064817018 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go @@ -14,6 +14,7 @@ type ResourceAttributesConfig struct { CloudPlatform ResourceAttributeConfig `mapstructure:"cloud.platform"` CloudProvider ResourceAttributeConfig `mapstructure:"cloud.provider"` CloudRegion ResourceAttributeConfig `mapstructure:"cloud.region"` + FaasID ResourceAttributeConfig `mapstructure:"faas.id"` FaasInstance ResourceAttributeConfig `mapstructure:"faas.instance"` FaasName ResourceAttributeConfig `mapstructure:"faas.name"` FaasVersion ResourceAttributeConfig `mapstructure:"faas.version"` @@ -44,6 +45,9 @@ func DefaultResourceAttributesConfig() ResourceAttributesConfig { CloudRegion: ResourceAttributeConfig{ Enabled: true, }, + FaasID: ResourceAttributeConfig{ + Enabled: true, + }, FaasInstance: ResourceAttributeConfig{ Enabled: true, }, diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go index 528387e0a2af..a98ec6fff5b6 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go @@ -30,6 +30,7 @@ func TestResourceAttributesConfig(t *testing.T) { CloudPlatform: ResourceAttributeConfig{Enabled: true}, CloudProvider: ResourceAttributeConfig{Enabled: true}, CloudRegion: ResourceAttributeConfig{Enabled: true}, + FaasID: ResourceAttributeConfig{Enabled: true}, FaasInstance: ResourceAttributeConfig{Enabled: true}, FaasName: ResourceAttributeConfig{Enabled: true}, FaasVersion: ResourceAttributeConfig{Enabled: true}, @@ -51,6 +52,7 @@ func TestResourceAttributesConfig(t *testing.T) { CloudPlatform: ResourceAttributeConfig{Enabled: false}, CloudProvider: ResourceAttributeConfig{Enabled: false}, CloudRegion: ResourceAttributeConfig{Enabled: false}, + FaasID: ResourceAttributeConfig{Enabled: false}, FaasInstance: ResourceAttributeConfig{Enabled: false}, FaasName: ResourceAttributeConfig{Enabled: false}, FaasVersion: ResourceAttributeConfig{Enabled: false}, diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go index 4c072445e92e..acd1aab7c307 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go @@ -56,6 +56,13 @@ func (rb *ResourceBuilder) SetCloudRegion(val string) { } } +// SetFaasID sets provided value as "faas.id" attribute. +func (rb *ResourceBuilder) SetFaasID(val string) { + if rb.config.FaasID.Enabled { + rb.res.Attributes().PutStr("faas.id", val) + } +} + // SetFaasInstance sets provided value as "faas.instance" attribute. func (rb *ResourceBuilder) SetFaasInstance(val string) { if rb.config.FaasInstance.Enabled { diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go index bd99898a3b57..f0d207c3a0d0 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go @@ -18,6 +18,7 @@ func TestResourceBuilder(t *testing.T) { rb.SetCloudPlatform("cloud.platform-val") rb.SetCloudProvider("cloud.provider-val") rb.SetCloudRegion("cloud.region-val") + rb.SetFaasID("faas.id-val") rb.SetFaasInstance("faas.instance-val") rb.SetFaasName("faas.name-val") rb.SetFaasVersion("faas.version-val") @@ -35,9 +36,9 @@ func TestResourceBuilder(t *testing.T) { switch test { case "default": - assert.Equal(t, 14, res.Attributes().Len()) + assert.Equal(t, 15, res.Attributes().Len()) case "all_set": - assert.Equal(t, 16, res.Attributes().Len()) + assert.Equal(t, 17, res.Attributes().Len()) case "none_set": assert.Equal(t, 0, res.Attributes().Len()) return @@ -70,6 +71,11 @@ func TestResourceBuilder(t *testing.T) { if ok { assert.EqualValues(t, "cloud.region-val", val.Str()) } + val, ok = res.Attributes().Get("faas.id") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "faas.id-val", val.Str()) + } val, ok = res.Attributes().Get("faas.instance") assert.True(t, ok) if ok { diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml index 8561a3a99e79..00d45ed6c70b 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml @@ -11,6 +11,8 @@ all_set: enabled: true cloud.region: enabled: true + faas.id: + enabled: true faas.instance: enabled: true faas.name: @@ -45,6 +47,8 @@ none_set: enabled: false cloud.region: enabled: false + faas.id: + enabled: false faas.instance: enabled: false faas.name: diff --git a/processor/resourcedetectionprocessor/internal/gcp/metadata.yaml b/processor/resourcedetectionprocessor/internal/gcp/metadata.yaml index e9cc9a458571..b6ab6fcc9ef9 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/metadata.yaml +++ b/processor/resourcedetectionprocessor/internal/gcp/metadata.yaml @@ -43,6 +43,10 @@ resource_attributes: description: The faas.version type: string enabled: true + faas.id: + description: The faas.id. + type: string + enabled: true faas.instance: description: The faas.instance type: string From 44d131842ef15cfba8256540842155a6e3c4ee11 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Fri, 6 Oct 2023 08:49:18 -0400 Subject: [PATCH 3/3] Update processor/resourcedetectionprocessor/internal/gcp/gcp.go Co-authored-by: Alex Boten --- processor/resourcedetectionprocessor/internal/gcp/gcp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processor/resourcedetectionprocessor/internal/gcp/gcp.go b/processor/resourcedetectionprocessor/internal/gcp/gcp.go index 8637266266eb..e2ed72483f92 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/gcp.go +++ b/processor/resourcedetectionprocessor/internal/gcp/gcp.go @@ -28,7 +28,7 @@ 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")) + featuregate.WithRegisterFromVersion("v0.87.0")) // NewDetector returns a detector which can detect resource attributes on: // * Google Compute Engine (GCE).