Skip to content

Commit

Permalink
Switch from detecting faas.id to faas.instance in the gcp detector. (o…
Browse files Browse the repository at this point in the history
…pen-telemetry#26486)

Context:
GoogleCloudPlatform/opentelemetry-operations-go#679

faas.id was removed from the semantic conventions:
open-telemetry/opentelemetry-specification#3188

We were previously using it improperly to store the instance id of the
faas, which should be mapped to faas.instance instead.

---------

Co-authored-by: Alex Boten <[email protected]>
  • Loading branch information
2 people authored and jmsnll committed Nov 12, 2023
1 parent 40f11ef commit 78c0fec
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 10 deletions.
27 changes: 27 additions & 0 deletions .chloggen/gcp-faas-instance.yaml
Original file line number Diff line number Diff line change
@@ -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: '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: 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]

# (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: [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
32 changes: 27 additions & 5 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.87.0"))

// NewDetector returns a detector which can detect resource attributes on:
// * Google Compute Engine (GCE).
// * Google Kubernetes Engine (GKE).
Expand Down Expand Up @@ -72,43 +79,58 @@ 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),
)
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,
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),
)
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,
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),
)
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,
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),
)
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,
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),
)
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 @@ -156,8 +158,30 @@ func TestDetect(t *testing.T) {
conventions.AttributeCloudRegion: "us-central1",
conventions.AttributeFaaSName: "my-service",
conventions.AttributeFaaSVersion: "123456",
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",
Expand All @@ -176,10 +200,34 @@ func TestDetect(t *testing.T) {
conventions.AttributeCloudPlatform: conventions.AttributeCloudPlatformGCPCloudRun,
conventions.AttributeCloudRegion: "us-central1",
conventions.AttributeFaaSName: "my-service",
conventions.AttributeFaaSInstance: "1472385723456792345",
"gcp.cloud_run.job.execution": "my-service-ajg89",
"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",
Expand All @@ -198,8 +246,30 @@ func TestDetect(t *testing.T) {
conventions.AttributeCloudRegion: "us-central1",
conventions.AttributeFaaSName: "my-service",
conventions.AttributeFaaSVersion: "123456",
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",
Expand All @@ -220,8 +290,32 @@ func TestDetect(t *testing.T) {
conventions.AttributeCloudAvailabilityZone: "us-central1-c",
conventions.AttributeFaaSName: "my-service",
conventions.AttributeFaaSVersion: "123456",
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",
Expand All @@ -242,8 +336,32 @@ func TestDetect(t *testing.T) {
conventions.AttributeCloudAvailabilityZone: "us-central1-c",
conventions.AttributeFaaSName: "my-service",
conventions.AttributeFaaSVersion: "123456",
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",
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.

Loading

0 comments on commit 78c0fec

Please sign in to comment.