Skip to content

Commit

Permalink
[processor/resourcedetection] Support Cloud Run Jobs (open-telemetry#…
Browse files Browse the repository at this point in the history
…23681)

**Description:** Adds support for Cloud Run Jobs using gcp-specific
resource attributes

**Documentation:** Semantic conventions updates:
https://github.com/open-telemetry/semantic-conventions/blob/2246279243d743c6e073470f4e3551826f3115bc/specification/resource/semantic_conventions/cloud_provider/gcp/cloud_run.md
  • Loading branch information
damemi authored Jul 27, 2023
1 parent 6c96e96 commit 572dbba
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 38 deletions.
20 changes: 20 additions & 0 deletions .chloggen/gcp-cloud-run-jobs-detector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

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

# 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: Support GCP Cloud Run Jobs in resource detection processor.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [23681]

# (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:
9 changes: 9 additions & 0 deletions processor/resourcedetectionprocessor/internal/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ func (d *detector) Detect(context.Context) (resource pcommon.Resource, schemaURL
d.rb.SetFromCallable(d.rb.SetFaasID, d.detector.FaaSID),
d.rb.SetFromCallable(d.rb.SetCloudRegion, d.detector.FaaSCloudRegion),
)
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.SetGcpCloudRunJobExecution, d.detector.CloudRunJobExecution),
d.rb.SetFromCallable(d.rb.SetGcpCloudRunJobTaskIndex, d.detector.CloudRunJobTaskIndex),
)
case gcp.CloudFunctions:
d.rb.SetCloudPlatform(conventions.AttributeCloudPlatformGCPCloudFunctions)
errs = multierr.Combine(errs,
Expand Down
38 changes: 38 additions & 0 deletions processor/resourcedetectionprocessor/internal/gcp/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,28 @@ func TestDetect(t *testing.T) {
conventions.AttributeFaaSID: "1472385723456792345",
},
},
{
desc: "Cloud Run Job",
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.AttributeFaaSID: "1472385723456792345",
"gcp.cloud_run.job.execution": "my-service-ajg89",
"gcp.cloud_run.job.task_index": "2",
},
},
{
desc: "Cloud Functions",
detector: newTestDetector(&fakeGCPDetector{
Expand Down Expand Up @@ -259,6 +281,8 @@ type fakeGCPDetector struct {
gceHostID string
gceHostName string
gceHostNameErr error
gcpCloudRunJobExecution string
gcpCloudRunJobTaskIndex string
}

func (f *fakeGCPDetector) ProjectID() (string, error) {
Expand Down Expand Up @@ -393,3 +417,17 @@ func (f *fakeGCPDetector) GCEHostName() (string, error) {
}
return f.gceHostName, f.gceHostNameErr
}

func (f *fakeGCPDetector) CloudRunJobTaskIndex() (string, error) {
if f.err != nil {
return "", f.err
}
return f.gcpCloudRunJobTaskIndex, nil
}

func (f *fakeGCPDetector) CloudRunJobExecution() (string, error) {
if f.err != nil {
return "", f.err
}
return f.gcpCloudRunJobExecution, nil
}

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 @@ -17,6 +17,10 @@ all_set:
enabled: true
faas.version:
enabled: true
gcp.cloud_run.job.execution:
enabled: true
gcp.cloud_run.job.task_index:
enabled: true
host.id:
enabled: true
host.name:
Expand All @@ -43,6 +47,10 @@ none_set:
enabled: false
faas.version:
enabled: false
gcp.cloud_run.job.execution:
enabled: false
gcp.cloud_run.job.task_index:
enabled: false
host.id:
enabled: false
host.name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ resource_attributes:
k8s.cluster.name:
description: The k8s.cluster.name
type: string
enabled: true
gcp.cloud_run.job.execution:
description: The Job execution name
type: string
enabled: true
gcp.cloud_run.job.task_index:
description: The Job execution task index
type: string
enabled: true
2 changes: 2 additions & 0 deletions processor/resourcedetectionprocessor/internal/gcp/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ type gcpDetector interface {
GCEHostType() (string, error)
GCEHostID() (string, error)
GCEHostName() (string, error)
CloudRunJobExecution() (string, error)
CloudRunJobTaskIndex() (string, error)
}

0 comments on commit 572dbba

Please sign in to comment.