Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[processor/resourcedetection] Add support for detecting GCE VMs in Managed Instance Groups #36142

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/gcp-gce-mig.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: 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: The `gcp` resource detector will now detect resource attributes identifying a GCE instance's managed instance group.

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

# (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:

# 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]
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
| gcp.cloud_run.job.task_index | The Job execution task index | Any Str | true |
| gcp.gce.instance.hostname | The hostname of the GCE instance. | Any Str | false |
| gcp.gce.instance.name | The name of the GCE instance. | Any Str | false |
| gcp.gce.instance_group_manager.name | The name of an instanceGroupManager. | Any Str | true |
| gcp.gce.instance_group_manager.region | The region of a regional instanceGroupManager. | Any Str | true |
| gcp.gce.instance_group_manager.zone | The zone of a zonal instanceGroupManager. | Any Str | true |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use availability_zone instead of zone for consistency with cloud.availability_zone? I can see wanting to keep it shorter. Any other reasons why you went with zone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with zone because this is a GCP-specific attribute name and zone is the terminology used in GCP.

| host.id | The host.id | Any Str | true |
| host.name | The host.name | Any Str | true |
| host.type | The host.type | Any Str | true |
Expand Down
1 change: 1 addition & 0 deletions processor/resourcedetectionprocessor/internal/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func (d *detector) Detect(context.Context) (resource pcommon.Resource, schemaURL
d.rb.SetFromCallable(d.rb.SetHostName, d.detector.GCEHostName),
d.rb.SetFromCallable(d.rb.SetGcpGceInstanceHostname, d.detector.GCEInstanceHostname),
d.rb.SetFromCallable(d.rb.SetGcpGceInstanceName, d.detector.GCEInstanceName),
d.rb.SetManagedInstanceGroup(d.detector.GCEManagedInstanceGroup),
)
default:
// We don't support this platform yet, so just return with what we have
Expand Down
39 changes: 39 additions & 0 deletions processor/resourcedetectionprocessor/internal/gcp/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,37 @@ func TestDetect(t *testing.T) {
"gcp.gce.instance.name": "my-gke-node-1234",
},
},
{
desc: "GCE with MIG",
detector: newTestDetector(&fakeGCPDetector{
projectID: "my-project",
cloudPlatform: gcp.GCE,
gceHostID: "1472385723456792345",
gceHostName: "my-gke-node-1234",
gceHostType: "n1-standard1",
gceAvailabilityZone: "us-central1-c",
gceRegion: "us-central1",
gcpGceInstanceHostname: "custom.dns.example.com",
gcpGceInstanceName: "my-gke-node-1234",
gcpGceManagedInstanceGroup: gcp.ManagedInstanceGroup{
Name: "my-gke-node",
Location: "us-central1",
Type: gcp.Region,
},
}),
expectedResource: map[string]any{
conventions.AttributeCloudProvider: conventions.AttributeCloudProviderGCP,
conventions.AttributeCloudAccountID: "my-project",
conventions.AttributeCloudPlatform: conventions.AttributeCloudPlatformGCPComputeEngine,
conventions.AttributeHostID: "1472385723456792345",
conventions.AttributeHostName: "my-gke-node-1234",
conventions.AttributeHostType: "n1-standard1",
conventions.AttributeCloudRegion: "us-central1",
conventions.AttributeCloudAvailabilityZone: "us-central1-c",
"gcp.gce.instance_group_manager.name": "my-gke-node",
"gcp.gce.instance_group_manager.region": "us-central1",
},
},
{
desc: "Cloud Run",
detector: newTestDetector(&fakeGCPDetector{
Expand Down Expand Up @@ -456,6 +487,7 @@ type fakeGCPDetector struct {
gcpCloudRunJobTaskIndex string
gcpGceInstanceName string
gcpGceInstanceHostname string
gcpGceManagedInstanceGroup gcp.ManagedInstanceGroup
gcpBareMetalSolutionInstanceID string
gcpBareMetalSolutionCloudRegion string
gcpBareMetalSolutionProjectID string
Expand Down Expand Up @@ -622,6 +654,13 @@ func (f *fakeGCPDetector) GCEInstanceHostname() (string, error) {
return f.gcpGceInstanceHostname, nil
}

func (f *fakeGCPDetector) GCEManagedInstanceGroup() (gcp.ManagedInstanceGroup, error) {
if f.err != nil {
return gcp.ManagedInstanceGroup{}, f.err
}
return f.gcpGceManagedInstanceGroup, nil
}

func (f *fakeGCPDetector) BareMetalSolutionInstanceID() (string, error) {
if f.err != nil {
return "", f.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.

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 @@ -43,3 +43,20 @@ func (rb *ResourceBuilder) SetZoneOrRegion(detect func() (string, gcp.LocationTy
}
return nil
}

func (rb *ResourceBuilder) SetManagedInstanceGroup(detect func() (gcp.ManagedInstanceGroup, error)) error {
v, err := detect()
if err != nil {
return err
}
if v.Name != "" {
rb.SetGcpGceInstanceGroupManagerName(v.Name)
}
switch v.Type {
case gcp.Zone:
rb.SetGcpGceInstanceGroupManagerZone(v.Location)
case gcp.Region:
rb.SetGcpGceInstanceGroupManagerRegion(v.Location)
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ all_set:
enabled: true
gcp.gce.instance.name:
enabled: true
gcp.gce.instance_group_manager.name:
enabled: true
gcp.gce.instance_group_manager.region:
enabled: true
gcp.gce.instance_group_manager.zone:
enabled: true
host.id:
enabled: true
host.name:
Expand Down Expand Up @@ -63,6 +69,12 @@ none_set:
enabled: false
gcp.gce.instance.name:
enabled: false
gcp.gce.instance_group_manager.name:
enabled: false
gcp.gce.instance_group_manager.region:
enabled: false
gcp.gce.instance_group_manager.zone:
enabled: false
host.id:
enabled: false
host.name:
Expand Down
12 changes: 12 additions & 0 deletions processor/resourcedetectionprocessor/internal/gcp/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,15 @@ resource_attributes:
description: The hostname of the GCE instance.
type: string
enabled: false
gcp.gce.instance_group_manager.name:
description: The name of an instanceGroupManager.
type: string
enabled: true
gcp.gce.instance_group_manager.zone:
description: The zone of a zonal instanceGroupManager.
type: string
enabled: true
gcp.gce.instance_group_manager.region:
description: The region of a regional instanceGroupManager.
type: string
enabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type gcpDetector interface {
CloudRunJobTaskIndex() (string, error)
GCEInstanceHostname() (string, error)
GCEInstanceName() (string, error)
GCEManagedInstanceGroup() (gcp.ManagedInstanceGroup, error)
BareMetalSolutionInstanceID() (string, error)
BareMetalSolutionCloudRegion() (string, error)
BareMetalSolutionProjectID() (string, error)
Expand Down
Loading