Skip to content

Commit 929b225

Browse files
quentinmitdashpoleTylerHelmuthmx-psiatoulme
authored andcommitted
[processor/resourcedetection] Add support for detecting GCE VMs in Managed Instance Groups (open-telemetry#36142)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This adds resource detection for the GCE "instance group manager" that created an instance, allowing like VMs to be grouped using a resource attribute. I also have corresponding branches prepared for opentelemetry-go and semantic-conventions <!--Describe what testing was performed and which tests were added.--> #### Testing This PR includes unit tests to validate that the correct resource attributes are added, and I manually tested a collector built with this change on a MIG VM and it generates the expected resource attributes. <!--Describe the documentation added.--> #### Documentation Documented with the other resource attributes in the existing documentation. <!--Please delete paragraphs that you did not use before submitting.--> --------- Co-authored-by: David Ashpole <[email protected]> Co-authored-by: Tyler Helmuth <[email protected]> Co-authored-by: Pablo Baeyens <[email protected]> Co-authored-by: Antoine Toulme <[email protected]> Co-authored-by: Yang Song <[email protected]> Co-authored-by: Sean Marciniak <[email protected]>
1 parent eb0c460 commit 929b225

File tree

12 files changed

+222
-53
lines changed

12 files changed

+222
-53
lines changed

.chloggen/gcp-gce-mig.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: resourcedetectionprocessor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: The `gcp` resource detector will now detect resource attributes identifying a GCE instance's managed instance group.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [36142]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

processor/resourcedetectionprocessor/internal/gcp/documentation.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
| gcp.cloud_run.job.task_index | The Job execution task index | Any Str | true |
2222
| gcp.gce.instance.hostname | The hostname of the GCE instance. | Any Str | false |
2323
| gcp.gce.instance.name | The name of the GCE instance. | Any Str | false |
24+
| gcp.gce.instance_group_manager.name | The name of an instanceGroupManager. | Any Str | true |
25+
| gcp.gce.instance_group_manager.region | The region of a regional instanceGroupManager. | Any Str | true |
26+
| gcp.gce.instance_group_manager.zone | The zone of a zonal instanceGroupManager. | Any Str | true |
2427
| host.id | The host.id | Any Str | true |
2528
| host.name | The host.name | Any Str | true |
2629
| host.type | The host.type | Any Str | true |

processor/resourcedetectionprocessor/internal/gcp/gcp.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func (d *detector) Detect(context.Context) (resource pcommon.Resource, schemaURL
153153
d.rb.SetFromCallable(d.rb.SetHostName, d.detector.GCEHostName),
154154
d.rb.SetFromCallable(d.rb.SetGcpGceInstanceHostname, d.detector.GCEInstanceHostname),
155155
d.rb.SetFromCallable(d.rb.SetGcpGceInstanceName, d.detector.GCEInstanceName),
156+
d.rb.SetManagedInstanceGroup(d.detector.GCEManagedInstanceGroup),
156157
)
157158
default:
158159
// We don't support this platform yet, so just return with what we have

processor/resourcedetectionprocessor/internal/gcp/gcp_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,37 @@ func TestDetect(t *testing.T) {
141141
"gcp.gce.instance.name": "my-gke-node-1234",
142142
},
143143
},
144+
{
145+
desc: "GCE with MIG",
146+
detector: newTestDetector(&fakeGCPDetector{
147+
projectID: "my-project",
148+
cloudPlatform: gcp.GCE,
149+
gceHostID: "1472385723456792345",
150+
gceHostName: "my-gke-node-1234",
151+
gceHostType: "n1-standard1",
152+
gceAvailabilityZone: "us-central1-c",
153+
gceRegion: "us-central1",
154+
gcpGceInstanceHostname: "custom.dns.example.com",
155+
gcpGceInstanceName: "my-gke-node-1234",
156+
gcpGceManagedInstanceGroup: gcp.ManagedInstanceGroup{
157+
Name: "my-gke-node",
158+
Location: "us-central1",
159+
Type: gcp.Region,
160+
},
161+
}),
162+
expectedResource: map[string]any{
163+
conventions.AttributeCloudProvider: conventions.AttributeCloudProviderGCP,
164+
conventions.AttributeCloudAccountID: "my-project",
165+
conventions.AttributeCloudPlatform: conventions.AttributeCloudPlatformGCPComputeEngine,
166+
conventions.AttributeHostID: "1472385723456792345",
167+
conventions.AttributeHostName: "my-gke-node-1234",
168+
conventions.AttributeHostType: "n1-standard1",
169+
conventions.AttributeCloudRegion: "us-central1",
170+
conventions.AttributeCloudAvailabilityZone: "us-central1-c",
171+
"gcp.gce.instance_group_manager.name": "my-gke-node",
172+
"gcp.gce.instance_group_manager.region": "us-central1",
173+
},
174+
},
144175
{
145176
desc: "Cloud Run",
146177
detector: newTestDetector(&fakeGCPDetector{
@@ -456,6 +487,7 @@ type fakeGCPDetector struct {
456487
gcpCloudRunJobTaskIndex string
457488
gcpGceInstanceName string
458489
gcpGceInstanceHostname string
490+
gcpGceManagedInstanceGroup gcp.ManagedInstanceGroup
459491
gcpBareMetalSolutionInstanceID string
460492
gcpBareMetalSolutionCloudRegion string
461493
gcpBareMetalSolutionProjectID string
@@ -622,6 +654,13 @@ func (f *fakeGCPDetector) GCEInstanceHostname() (string, error) {
622654
return f.gcpGceInstanceHostname, nil
623655
}
624656

657+
func (f *fakeGCPDetector) GCEManagedInstanceGroup() (gcp.ManagedInstanceGroup, error) {
658+
if f.err != nil {
659+
return gcp.ManagedInstanceGroup{}, f.err
660+
}
661+
return f.gcpGceManagedInstanceGroup, nil
662+
}
663+
625664
func (f *fakeGCPDetector) BareMetalSolutionInstanceID() (string, error) {
626665
if f.err != nil {
627666
return "", f.err

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

Lines changed: 29 additions & 17 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: 40 additions & 34 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: 21 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: 20 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/resource.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,20 @@ func (rb *ResourceBuilder) SetZoneOrRegion(detect func() (string, gcp.LocationTy
4343
}
4444
return nil
4545
}
46+
47+
func (rb *ResourceBuilder) SetManagedInstanceGroup(detect func() (gcp.ManagedInstanceGroup, error)) error {
48+
v, err := detect()
49+
if err != nil {
50+
return err
51+
}
52+
if v.Name != "" {
53+
rb.SetGcpGceInstanceGroupManagerName(v.Name)
54+
}
55+
switch v.Type {
56+
case gcp.Zone:
57+
rb.SetGcpGceInstanceGroupManagerZone(v.Location)
58+
case gcp.Region:
59+
rb.SetGcpGceInstanceGroupManagerRegion(v.Location)
60+
}
61+
return nil
62+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ all_set:
2727
enabled: true
2828
gcp.gce.instance.name:
2929
enabled: true
30+
gcp.gce.instance_group_manager.name:
31+
enabled: true
32+
gcp.gce.instance_group_manager.region:
33+
enabled: true
34+
gcp.gce.instance_group_manager.zone:
35+
enabled: true
3036
host.id:
3137
enabled: true
3238
host.name:
@@ -63,6 +69,12 @@ none_set:
6369
enabled: false
6470
gcp.gce.instance.name:
6571
enabled: false
72+
gcp.gce.instance_group_manager.name:
73+
enabled: false
74+
gcp.gce.instance_group_manager.region:
75+
enabled: false
76+
gcp.gce.instance_group_manager.zone:
77+
enabled: false
6678
host.id:
6779
enabled: false
6880
host.name:

processor/resourcedetectionprocessor/internal/gcp/metadata.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,15 @@ resource_attributes:
7171
description: The hostname of the GCE instance.
7272
type: string
7373
enabled: false
74+
gcp.gce.instance_group_manager.name:
75+
description: The name of an instanceGroupManager.
76+
type: string
77+
enabled: true
78+
gcp.gce.instance_group_manager.zone:
79+
description: The zone of a zonal instanceGroupManager.
80+
type: string
81+
enabled: true
82+
gcp.gce.instance_group_manager.region:
83+
description: The region of a regional instanceGroupManager.
84+
type: string
85+
enabled: true

processor/resourcedetectionprocessor/internal/gcp/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type gcpDetector interface {
3333
CloudRunJobTaskIndex() (string, error)
3434
GCEInstanceHostname() (string, error)
3535
GCEInstanceName() (string, error)
36+
GCEManagedInstanceGroup() (gcp.ManagedInstanceGroup, error)
3637
BareMetalSolutionInstanceID() (string, error)
3738
BareMetalSolutionCloudRegion() (string, error)
3839
BareMetalSolutionProjectID() (string, error)

0 commit comments

Comments
 (0)