Skip to content

Commit 572dbba

Browse files
authored
[processor/resourcedetection] Support Cloud Run Jobs (#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
1 parent 6c96e96 commit 572dbba

File tree

10 files changed

+161
-38
lines changed

10 files changed

+161
-38
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use this changelog template to create an entry for release notes.
2+
# If your change doesn't affect end users, such as a test fix or a tooling change,
3+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
4+
5+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
6+
change_type: enhancement
7+
8+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
9+
component: resourcedetectionprocessor
10+
11+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
12+
note: Support GCP Cloud Run Jobs in resource detection processor.
13+
14+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
15+
issues: [23681]
16+
17+
# (Optional) One or more lines of additional information to render under the primary note.
18+
# These lines will be padded with 2 spaces and then inserted directly into the document.
19+
# Use pipe (|) for multiline entries.
20+
subtext:

processor/resourcedetectionprocessor/internal/gcp/gcp.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ func (d *detector) Detect(context.Context) (resource pcommon.Resource, schemaURL
7575
d.rb.SetFromCallable(d.rb.SetFaasID, d.detector.FaaSID),
7676
d.rb.SetFromCallable(d.rb.SetCloudRegion, d.detector.FaaSCloudRegion),
7777
)
78+
case gcp.CloudRunJob:
79+
d.rb.SetCloudPlatform(conventions.AttributeCloudPlatformGCPCloudRun)
80+
errs = multierr.Combine(errs,
81+
d.rb.SetFromCallable(d.rb.SetFaasName, d.detector.FaaSName),
82+
d.rb.SetFromCallable(d.rb.SetCloudRegion, d.detector.FaaSCloudRegion),
83+
d.rb.SetFromCallable(d.rb.SetFaasID, d.detector.FaaSID),
84+
d.rb.SetFromCallable(d.rb.SetGcpCloudRunJobExecution, d.detector.CloudRunJobExecution),
85+
d.rb.SetFromCallable(d.rb.SetGcpCloudRunJobTaskIndex, d.detector.CloudRunJobTaskIndex),
86+
)
7887
case gcp.CloudFunctions:
7988
d.rb.SetCloudPlatform(conventions.AttributeCloudPlatformGCPCloudFunctions)
8089
errs = multierr.Combine(errs,

processor/resourcedetectionprocessor/internal/gcp/gcp_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,28 @@ func TestDetect(t *testing.T) {
128128
conventions.AttributeFaaSID: "1472385723456792345",
129129
},
130130
},
131+
{
132+
desc: "Cloud Run Job",
133+
detector: newTestDetector(&fakeGCPDetector{
134+
projectID: "my-project",
135+
cloudPlatform: gcp.CloudRunJob,
136+
faaSID: "1472385723456792345",
137+
faaSCloudRegion: "us-central1",
138+
faaSName: "my-service",
139+
gcpCloudRunJobExecution: "my-service-ajg89",
140+
gcpCloudRunJobTaskIndex: "2",
141+
}),
142+
expectedResource: map[string]any{
143+
conventions.AttributeCloudProvider: conventions.AttributeCloudProviderGCP,
144+
conventions.AttributeCloudAccountID: "my-project",
145+
conventions.AttributeCloudPlatform: conventions.AttributeCloudPlatformGCPCloudRun,
146+
conventions.AttributeCloudRegion: "us-central1",
147+
conventions.AttributeFaaSName: "my-service",
148+
conventions.AttributeFaaSID: "1472385723456792345",
149+
"gcp.cloud_run.job.execution": "my-service-ajg89",
150+
"gcp.cloud_run.job.task_index": "2",
151+
},
152+
},
131153
{
132154
desc: "Cloud Functions",
133155
detector: newTestDetector(&fakeGCPDetector{
@@ -259,6 +281,8 @@ type fakeGCPDetector struct {
259281
gceHostID string
260282
gceHostName string
261283
gceHostNameErr error
284+
gcpCloudRunJobExecution string
285+
gcpCloudRunJobTaskIndex string
262286
}
263287

264288
func (f *fakeGCPDetector) ProjectID() (string, error) {
@@ -393,3 +417,17 @@ func (f *fakeGCPDetector) GCEHostName() (string, error) {
393417
}
394418
return f.gceHostName, f.gceHostNameErr
395419
}
420+
421+
func (f *fakeGCPDetector) CloudRunJobTaskIndex() (string, error) {
422+
if f.err != nil {
423+
return "", f.err
424+
}
425+
return f.gcpCloudRunJobTaskIndex, nil
426+
}
427+
428+
func (f *fakeGCPDetector) CloudRunJobExecution() (string, error) {
429+
if f.err != nil {
430+
return "", f.err
431+
}
432+
return f.gcpCloudRunJobExecution, nil
433+
}

processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go

Lines changed: 20 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go

Lines changed: 28 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ all_set:
1717
enabled: true
1818
faas.version:
1919
enabled: true
20+
gcp.cloud_run.job.execution:
21+
enabled: true
22+
gcp.cloud_run.job.task_index:
23+
enabled: true
2024
host.id:
2125
enabled: true
2226
host.name:
@@ -43,6 +47,10 @@ none_set:
4347
enabled: false
4448
faas.version:
4549
enabled: false
50+
gcp.cloud_run.job.execution:
51+
enabled: false
52+
gcp.cloud_run.job.task_index:
53+
enabled: false
4654
host.id:
4755
enabled: false
4856
host.name:

processor/resourcedetectionprocessor/internal/gcp/metadata.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,12 @@ resource_attributes:
5050
k8s.cluster.name:
5151
description: The k8s.cluster.name
5252
type: string
53+
enabled: true
54+
gcp.cloud_run.job.execution:
55+
description: The Job execution name
56+
type: string
57+
enabled: true
58+
gcp.cloud_run.job.task_index:
59+
description: The Job execution task index
60+
type: string
5361
enabled: true

processor/resourcedetectionprocessor/internal/gcp/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ type gcpDetector interface {
2929
GCEHostType() (string, error)
3030
GCEHostID() (string, error)
3131
GCEHostName() (string, error)
32+
CloudRunJobExecution() (string, error)
33+
CloudRunJobTaskIndex() (string, error)
3234
}

0 commit comments

Comments
 (0)