From 260fe9be3a37e450917aaa816e5172e31e9815dc Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Fri, 25 Oct 2024 16:32:27 -0400 Subject: [PATCH 1/3] [processor/resourcedetection] Add support for detecting GCE VMs in Managed Instance Groups --- .../internal/gcp/documentation.md | 3 + .../internal/gcp/gcp.go | 1 + .../internal/gcp/gcp_test.go | 39 ++++++++++ .../gcp/internal/metadata/generated_config.go | 46 +++++++----- .../metadata/generated_config_test.go | 74 ++++++++++--------- .../internal/metadata/generated_resource.go | 21 ++++++ .../metadata/generated_resource_test.go | 22 +++++- .../gcp/internal/metadata/resource.go | 17 +++++ .../internal/metadata/testdata/config.yaml | 12 +++ .../internal/gcp/metadata.yaml | 12 +++ .../internal/gcp/types.go | 1 + 11 files changed, 195 insertions(+), 53 deletions(-) diff --git a/processor/resourcedetectionprocessor/internal/gcp/documentation.md b/processor/resourcedetectionprocessor/internal/gcp/documentation.md index a8a9d0b2b4a0..0e1c1d056155 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/documentation.md +++ b/processor/resourcedetectionprocessor/internal/gcp/documentation.md @@ -19,6 +19,9 @@ | faas.version | The faas.version | Any Str | true | | gcp.cloud_run.job.execution | The Job execution name | Any Str | true | | gcp.cloud_run.job.task_index | The Job execution task index | Any Str | true | +| 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 | | 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 | | host.id | The host.id | Any Str | true | diff --git a/processor/resourcedetectionprocessor/internal/gcp/gcp.go b/processor/resourcedetectionprocessor/internal/gcp/gcp.go index 7a49da1702a1..02f612952786 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/gcp.go +++ b/processor/resourcedetectionprocessor/internal/gcp/gcp.go @@ -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 diff --git a/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go b/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go index 8574a6250eb2..85ab66560812 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go +++ b/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go @@ -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{ @@ -456,6 +487,7 @@ type fakeGCPDetector struct { gcpCloudRunJobTaskIndex string gcpGceInstanceName string gcpGceInstanceHostname string + gcpGceManagedInstanceGroup gcp.ManagedInstanceGroup gcpBareMetalSolutionInstanceID string gcpBareMetalSolutionCloudRegion string gcpBareMetalSolutionProjectID string @@ -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 diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go index 7753a7be6717..7b7b495b87e3 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go @@ -27,23 +27,26 @@ func (rac *ResourceAttributeConfig) Unmarshal(parser *confmap.Conf) error { // ResourceAttributesConfig provides config for resourcedetectionprocessor/gcp resource attributes. type ResourceAttributesConfig struct { - CloudAccountID ResourceAttributeConfig `mapstructure:"cloud.account.id"` - CloudAvailabilityZone ResourceAttributeConfig `mapstructure:"cloud.availability_zone"` - CloudPlatform ResourceAttributeConfig `mapstructure:"cloud.platform"` - CloudProvider ResourceAttributeConfig `mapstructure:"cloud.provider"` - CloudRegion ResourceAttributeConfig `mapstructure:"cloud.region"` - FaasID ResourceAttributeConfig `mapstructure:"faas.id"` - FaasInstance ResourceAttributeConfig `mapstructure:"faas.instance"` - FaasName ResourceAttributeConfig `mapstructure:"faas.name"` - FaasVersion ResourceAttributeConfig `mapstructure:"faas.version"` - GcpCloudRunJobExecution ResourceAttributeConfig `mapstructure:"gcp.cloud_run.job.execution"` - GcpCloudRunJobTaskIndex ResourceAttributeConfig `mapstructure:"gcp.cloud_run.job.task_index"` - GcpGceInstanceHostname ResourceAttributeConfig `mapstructure:"gcp.gce.instance.hostname"` - GcpGceInstanceName ResourceAttributeConfig `mapstructure:"gcp.gce.instance.name"` - HostID ResourceAttributeConfig `mapstructure:"host.id"` - HostName ResourceAttributeConfig `mapstructure:"host.name"` - HostType ResourceAttributeConfig `mapstructure:"host.type"` - K8sClusterName ResourceAttributeConfig `mapstructure:"k8s.cluster.name"` + CloudAccountID ResourceAttributeConfig `mapstructure:"cloud.account.id"` + CloudAvailabilityZone ResourceAttributeConfig `mapstructure:"cloud.availability_zone"` + CloudPlatform ResourceAttributeConfig `mapstructure:"cloud.platform"` + CloudProvider ResourceAttributeConfig `mapstructure:"cloud.provider"` + CloudRegion ResourceAttributeConfig `mapstructure:"cloud.region"` + FaasID ResourceAttributeConfig `mapstructure:"faas.id"` + FaasInstance ResourceAttributeConfig `mapstructure:"faas.instance"` + FaasName ResourceAttributeConfig `mapstructure:"faas.name"` + FaasVersion ResourceAttributeConfig `mapstructure:"faas.version"` + GcpCloudRunJobExecution ResourceAttributeConfig `mapstructure:"gcp.cloud_run.job.execution"` + GcpCloudRunJobTaskIndex ResourceAttributeConfig `mapstructure:"gcp.cloud_run.job.task_index"` + GcpGceInstanceGroupManagerName ResourceAttributeConfig `mapstructure:"gcp.gce.instance.group.manager.name"` + GcpGceInstanceGroupManagerRegion ResourceAttributeConfig `mapstructure:"gcp.gce.instance.group.manager.region"` + GcpGceInstanceGroupManagerZone ResourceAttributeConfig `mapstructure:"gcp.gce.instance.group.manager.zone"` + GcpGceInstanceHostname ResourceAttributeConfig `mapstructure:"gcp.gce.instance.hostname"` + GcpGceInstanceName ResourceAttributeConfig `mapstructure:"gcp.gce.instance.name"` + HostID ResourceAttributeConfig `mapstructure:"host.id"` + HostName ResourceAttributeConfig `mapstructure:"host.name"` + HostType ResourceAttributeConfig `mapstructure:"host.type"` + K8sClusterName ResourceAttributeConfig `mapstructure:"k8s.cluster.name"` } func DefaultResourceAttributesConfig() ResourceAttributesConfig { @@ -81,6 +84,15 @@ func DefaultResourceAttributesConfig() ResourceAttributesConfig { GcpCloudRunJobTaskIndex: ResourceAttributeConfig{ Enabled: true, }, + GcpGceInstanceGroupManagerName: ResourceAttributeConfig{ + Enabled: true, + }, + GcpGceInstanceGroupManagerRegion: ResourceAttributeConfig{ + Enabled: true, + }, + GcpGceInstanceGroupManagerZone: ResourceAttributeConfig{ + Enabled: true, + }, GcpGceInstanceHostname: ResourceAttributeConfig{ Enabled: false, }, diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go index f1f98b93018c..61dc0020dd90 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go @@ -24,45 +24,51 @@ func TestResourceAttributesConfig(t *testing.T) { { name: "all_set", want: ResourceAttributesConfig{ - CloudAccountID: ResourceAttributeConfig{Enabled: true}, - CloudAvailabilityZone: ResourceAttributeConfig{Enabled: true}, - CloudPlatform: ResourceAttributeConfig{Enabled: true}, - CloudProvider: ResourceAttributeConfig{Enabled: true}, - CloudRegion: ResourceAttributeConfig{Enabled: true}, - FaasID: ResourceAttributeConfig{Enabled: true}, - FaasInstance: ResourceAttributeConfig{Enabled: true}, - FaasName: ResourceAttributeConfig{Enabled: true}, - FaasVersion: ResourceAttributeConfig{Enabled: true}, - GcpCloudRunJobExecution: ResourceAttributeConfig{Enabled: true}, - GcpCloudRunJobTaskIndex: ResourceAttributeConfig{Enabled: true}, - GcpGceInstanceHostname: ResourceAttributeConfig{Enabled: true}, - GcpGceInstanceName: ResourceAttributeConfig{Enabled: true}, - HostID: ResourceAttributeConfig{Enabled: true}, - HostName: ResourceAttributeConfig{Enabled: true}, - HostType: ResourceAttributeConfig{Enabled: true}, - K8sClusterName: ResourceAttributeConfig{Enabled: true}, + CloudAccountID: ResourceAttributeConfig{Enabled: true}, + CloudAvailabilityZone: ResourceAttributeConfig{Enabled: true}, + CloudPlatform: ResourceAttributeConfig{Enabled: true}, + CloudProvider: ResourceAttributeConfig{Enabled: true}, + CloudRegion: ResourceAttributeConfig{Enabled: true}, + FaasID: ResourceAttributeConfig{Enabled: true}, + FaasInstance: ResourceAttributeConfig{Enabled: true}, + FaasName: ResourceAttributeConfig{Enabled: true}, + FaasVersion: ResourceAttributeConfig{Enabled: true}, + GcpCloudRunJobExecution: ResourceAttributeConfig{Enabled: true}, + GcpCloudRunJobTaskIndex: ResourceAttributeConfig{Enabled: true}, + GcpGceInstanceGroupManagerName: ResourceAttributeConfig{Enabled: true}, + GcpGceInstanceGroupManagerRegion: ResourceAttributeConfig{Enabled: true}, + GcpGceInstanceGroupManagerZone: ResourceAttributeConfig{Enabled: true}, + GcpGceInstanceHostname: ResourceAttributeConfig{Enabled: true}, + GcpGceInstanceName: ResourceAttributeConfig{Enabled: true}, + HostID: ResourceAttributeConfig{Enabled: true}, + HostName: ResourceAttributeConfig{Enabled: true}, + HostType: ResourceAttributeConfig{Enabled: true}, + K8sClusterName: ResourceAttributeConfig{Enabled: true}, }, }, { name: "none_set", want: ResourceAttributesConfig{ - CloudAccountID: ResourceAttributeConfig{Enabled: false}, - CloudAvailabilityZone: ResourceAttributeConfig{Enabled: false}, - CloudPlatform: ResourceAttributeConfig{Enabled: false}, - CloudProvider: ResourceAttributeConfig{Enabled: false}, - CloudRegion: ResourceAttributeConfig{Enabled: false}, - FaasID: ResourceAttributeConfig{Enabled: false}, - FaasInstance: ResourceAttributeConfig{Enabled: false}, - FaasName: ResourceAttributeConfig{Enabled: false}, - FaasVersion: ResourceAttributeConfig{Enabled: false}, - GcpCloudRunJobExecution: ResourceAttributeConfig{Enabled: false}, - GcpCloudRunJobTaskIndex: ResourceAttributeConfig{Enabled: false}, - GcpGceInstanceHostname: ResourceAttributeConfig{Enabled: false}, - GcpGceInstanceName: ResourceAttributeConfig{Enabled: false}, - HostID: ResourceAttributeConfig{Enabled: false}, - HostName: ResourceAttributeConfig{Enabled: false}, - HostType: ResourceAttributeConfig{Enabled: false}, - K8sClusterName: ResourceAttributeConfig{Enabled: false}, + CloudAccountID: ResourceAttributeConfig{Enabled: false}, + CloudAvailabilityZone: ResourceAttributeConfig{Enabled: false}, + CloudPlatform: ResourceAttributeConfig{Enabled: false}, + CloudProvider: ResourceAttributeConfig{Enabled: false}, + CloudRegion: ResourceAttributeConfig{Enabled: false}, + FaasID: ResourceAttributeConfig{Enabled: false}, + FaasInstance: ResourceAttributeConfig{Enabled: false}, + FaasName: ResourceAttributeConfig{Enabled: false}, + FaasVersion: ResourceAttributeConfig{Enabled: false}, + GcpCloudRunJobExecution: ResourceAttributeConfig{Enabled: false}, + GcpCloudRunJobTaskIndex: ResourceAttributeConfig{Enabled: false}, + GcpGceInstanceGroupManagerName: ResourceAttributeConfig{Enabled: false}, + GcpGceInstanceGroupManagerRegion: ResourceAttributeConfig{Enabled: false}, + GcpGceInstanceGroupManagerZone: ResourceAttributeConfig{Enabled: false}, + GcpGceInstanceHostname: ResourceAttributeConfig{Enabled: false}, + GcpGceInstanceName: ResourceAttributeConfig{Enabled: false}, + HostID: ResourceAttributeConfig{Enabled: false}, + HostName: ResourceAttributeConfig{Enabled: false}, + HostType: ResourceAttributeConfig{Enabled: false}, + K8sClusterName: ResourceAttributeConfig{Enabled: false}, }, }, } diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go index acd1aab7c307..82d3073d77c3 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go @@ -98,6 +98,27 @@ func (rb *ResourceBuilder) SetGcpCloudRunJobTaskIndex(val string) { } } +// SetGcpGceInstanceGroupManagerName sets provided value as "gcp.gce.instance.group.manager.name" attribute. +func (rb *ResourceBuilder) SetGcpGceInstanceGroupManagerName(val string) { + if rb.config.GcpGceInstanceGroupManagerName.Enabled { + rb.res.Attributes().PutStr("gcp.gce.instance.group.manager.name", val) + } +} + +// SetGcpGceInstanceGroupManagerRegion sets provided value as "gcp.gce.instance.group.manager.region" attribute. +func (rb *ResourceBuilder) SetGcpGceInstanceGroupManagerRegion(val string) { + if rb.config.GcpGceInstanceGroupManagerRegion.Enabled { + rb.res.Attributes().PutStr("gcp.gce.instance.group.manager.region", val) + } +} + +// SetGcpGceInstanceGroupManagerZone sets provided value as "gcp.gce.instance.group.manager.zone" attribute. +func (rb *ResourceBuilder) SetGcpGceInstanceGroupManagerZone(val string) { + if rb.config.GcpGceInstanceGroupManagerZone.Enabled { + rb.res.Attributes().PutStr("gcp.gce.instance.group.manager.zone", val) + } +} + // SetGcpGceInstanceHostname sets provided value as "gcp.gce.instance.hostname" attribute. func (rb *ResourceBuilder) SetGcpGceInstanceHostname(val string) { if rb.config.GcpGceInstanceHostname.Enabled { diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go index 28cd9d9f4127..e69645cae40b 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go @@ -24,6 +24,9 @@ func TestResourceBuilder(t *testing.T) { rb.SetFaasVersion("faas.version-val") rb.SetGcpCloudRunJobExecution("gcp.cloud_run.job.execution-val") rb.SetGcpCloudRunJobTaskIndex("gcp.cloud_run.job.task_index-val") + rb.SetGcpGceInstanceGroupManagerName("gcp.gce.instance.group.manager.name-val") + rb.SetGcpGceInstanceGroupManagerRegion("gcp.gce.instance.group.manager.region-val") + rb.SetGcpGceInstanceGroupManagerZone("gcp.gce.instance.group.manager.zone-val") rb.SetGcpGceInstanceHostname("gcp.gce.instance.hostname-val") rb.SetGcpGceInstanceName("gcp.gce.instance.name-val") rb.SetHostID("host.id-val") @@ -36,9 +39,9 @@ func TestResourceBuilder(t *testing.T) { switch tt { case "default": - assert.Equal(t, 15, res.Attributes().Len()) + assert.Equal(t, 18, res.Attributes().Len()) case "all_set": - assert.Equal(t, 17, res.Attributes().Len()) + assert.Equal(t, 20, res.Attributes().Len()) case "none_set": assert.Equal(t, 0, res.Attributes().Len()) return @@ -101,6 +104,21 @@ func TestResourceBuilder(t *testing.T) { if ok { assert.EqualValues(t, "gcp.cloud_run.job.task_index-val", val.Str()) } + val, ok = res.Attributes().Get("gcp.gce.instance.group.manager.name") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "gcp.gce.instance.group.manager.name-val", val.Str()) + } + val, ok = res.Attributes().Get("gcp.gce.instance.group.manager.region") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "gcp.gce.instance.group.manager.region-val", val.Str()) + } + val, ok = res.Attributes().Get("gcp.gce.instance.group.manager.zone") + assert.True(t, ok) + if ok { + assert.EqualValues(t, "gcp.gce.instance.group.manager.zone-val", val.Str()) + } val, ok = res.Attributes().Get("gcp.gce.instance.hostname") assert.Equal(t, tt == "all_set", ok) if ok { diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/resource.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/resource.go index fd6032df1231..17ba4ba90a0d 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/resource.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/resource.go @@ -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 +} diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml index 00d45ed6c70b..db22079a8c66 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml @@ -23,6 +23,12 @@ all_set: enabled: true gcp.cloud_run.job.task_index: 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 gcp.gce.instance.hostname: enabled: true gcp.gce.instance.name: @@ -59,6 +65,12 @@ none_set: enabled: false gcp.cloud_run.job.task_index: 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 gcp.gce.instance.hostname: enabled: false gcp.gce.instance.name: diff --git a/processor/resourcedetectionprocessor/internal/gcp/metadata.yaml b/processor/resourcedetectionprocessor/internal/gcp/metadata.yaml index b6ab6fcc9ef9..b10fbae9a5b9 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/metadata.yaml +++ b/processor/resourcedetectionprocessor/internal/gcp/metadata.yaml @@ -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 diff --git a/processor/resourcedetectionprocessor/internal/gcp/types.go b/processor/resourcedetectionprocessor/internal/gcp/types.go index 523ba84d73bb..0c3c33de6015 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/types.go +++ b/processor/resourcedetectionprocessor/internal/gcp/types.go @@ -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) From 7cb96f9beba9261828814e3094de6d42e805a0ef Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Wed, 18 Dec 2024 15:30:57 -0500 Subject: [PATCH 2/3] Replace dots with underscores based on Entity SIG discussion --- .../internal/gcp/documentation.md | 6 +-- .../internal/gcp/gcp_test.go | 4 +- .../gcp/internal/metadata/generated_config.go | 18 ++++----- .../metadata/generated_config_test.go | 8 ++-- .../internal/metadata/generated_resource.go | 40 +++++++++---------- .../metadata/generated_resource_test.go | 34 ++++++++-------- .../internal/metadata/testdata/config.yaml | 20 +++++----- .../internal/gcp/metadata.yaml | 6 +-- 8 files changed, 68 insertions(+), 68 deletions(-) diff --git a/processor/resourcedetectionprocessor/internal/gcp/documentation.md b/processor/resourcedetectionprocessor/internal/gcp/documentation.md index 0e1c1d056155..8e1a3a45d4f4 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/documentation.md +++ b/processor/resourcedetectionprocessor/internal/gcp/documentation.md @@ -19,11 +19,11 @@ | faas.version | The faas.version | Any Str | true | | gcp.cloud_run.job.execution | The Job execution name | Any Str | true | | gcp.cloud_run.job.task_index | The Job execution task index | Any Str | true | -| 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 | | 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 | | host.id | The host.id | Any Str | true | | host.name | The host.name | Any Str | true | | host.type | The host.type | Any Str | true | diff --git a/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go b/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go index 85ab66560812..6efec31368f3 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go +++ b/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go @@ -168,8 +168,8 @@ func TestDetect(t *testing.T) { 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", + "gcp.gce.instance_group_manager.name": "my-gke-node", + "gcp.gce.instance_group_manager.region": "us-central1", }, }, { diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go index 7b7b495b87e3..702430bd2245 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config.go @@ -38,11 +38,11 @@ type ResourceAttributesConfig struct { FaasVersion ResourceAttributeConfig `mapstructure:"faas.version"` GcpCloudRunJobExecution ResourceAttributeConfig `mapstructure:"gcp.cloud_run.job.execution"` GcpCloudRunJobTaskIndex ResourceAttributeConfig `mapstructure:"gcp.cloud_run.job.task_index"` - GcpGceInstanceGroupManagerName ResourceAttributeConfig `mapstructure:"gcp.gce.instance.group.manager.name"` - GcpGceInstanceGroupManagerRegion ResourceAttributeConfig `mapstructure:"gcp.gce.instance.group.manager.region"` - GcpGceInstanceGroupManagerZone ResourceAttributeConfig `mapstructure:"gcp.gce.instance.group.manager.zone"` GcpGceInstanceHostname ResourceAttributeConfig `mapstructure:"gcp.gce.instance.hostname"` GcpGceInstanceName ResourceAttributeConfig `mapstructure:"gcp.gce.instance.name"` + GcpGceInstanceGroupManagerName ResourceAttributeConfig `mapstructure:"gcp.gce.instance_group_manager.name"` + GcpGceInstanceGroupManagerRegion ResourceAttributeConfig `mapstructure:"gcp.gce.instance_group_manager.region"` + GcpGceInstanceGroupManagerZone ResourceAttributeConfig `mapstructure:"gcp.gce.instance_group_manager.zone"` HostID ResourceAttributeConfig `mapstructure:"host.id"` HostName ResourceAttributeConfig `mapstructure:"host.name"` HostType ResourceAttributeConfig `mapstructure:"host.type"` @@ -84,6 +84,12 @@ func DefaultResourceAttributesConfig() ResourceAttributesConfig { GcpCloudRunJobTaskIndex: ResourceAttributeConfig{ Enabled: true, }, + GcpGceInstanceHostname: ResourceAttributeConfig{ + Enabled: false, + }, + GcpGceInstanceName: ResourceAttributeConfig{ + Enabled: false, + }, GcpGceInstanceGroupManagerName: ResourceAttributeConfig{ Enabled: true, }, @@ -93,12 +99,6 @@ func DefaultResourceAttributesConfig() ResourceAttributesConfig { GcpGceInstanceGroupManagerZone: ResourceAttributeConfig{ Enabled: true, }, - GcpGceInstanceHostname: ResourceAttributeConfig{ - Enabled: false, - }, - GcpGceInstanceName: ResourceAttributeConfig{ - Enabled: false, - }, HostID: ResourceAttributeConfig{ Enabled: true, }, diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go index 61dc0020dd90..fa49017971fe 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_config_test.go @@ -35,11 +35,11 @@ func TestResourceAttributesConfig(t *testing.T) { FaasVersion: ResourceAttributeConfig{Enabled: true}, GcpCloudRunJobExecution: ResourceAttributeConfig{Enabled: true}, GcpCloudRunJobTaskIndex: ResourceAttributeConfig{Enabled: true}, + GcpGceInstanceHostname: ResourceAttributeConfig{Enabled: true}, + GcpGceInstanceName: ResourceAttributeConfig{Enabled: true}, GcpGceInstanceGroupManagerName: ResourceAttributeConfig{Enabled: true}, GcpGceInstanceGroupManagerRegion: ResourceAttributeConfig{Enabled: true}, GcpGceInstanceGroupManagerZone: ResourceAttributeConfig{Enabled: true}, - GcpGceInstanceHostname: ResourceAttributeConfig{Enabled: true}, - GcpGceInstanceName: ResourceAttributeConfig{Enabled: true}, HostID: ResourceAttributeConfig{Enabled: true}, HostName: ResourceAttributeConfig{Enabled: true}, HostType: ResourceAttributeConfig{Enabled: true}, @@ -60,11 +60,11 @@ func TestResourceAttributesConfig(t *testing.T) { FaasVersion: ResourceAttributeConfig{Enabled: false}, GcpCloudRunJobExecution: ResourceAttributeConfig{Enabled: false}, GcpCloudRunJobTaskIndex: ResourceAttributeConfig{Enabled: false}, + GcpGceInstanceHostname: ResourceAttributeConfig{Enabled: false}, + GcpGceInstanceName: ResourceAttributeConfig{Enabled: false}, GcpGceInstanceGroupManagerName: ResourceAttributeConfig{Enabled: false}, GcpGceInstanceGroupManagerRegion: ResourceAttributeConfig{Enabled: false}, GcpGceInstanceGroupManagerZone: ResourceAttributeConfig{Enabled: false}, - GcpGceInstanceHostname: ResourceAttributeConfig{Enabled: false}, - GcpGceInstanceName: ResourceAttributeConfig{Enabled: false}, HostID: ResourceAttributeConfig{Enabled: false}, HostName: ResourceAttributeConfig{Enabled: false}, HostType: ResourceAttributeConfig{Enabled: false}, diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go index 82d3073d77c3..2180474867bf 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource.go @@ -98,38 +98,38 @@ func (rb *ResourceBuilder) SetGcpCloudRunJobTaskIndex(val string) { } } -// SetGcpGceInstanceGroupManagerName sets provided value as "gcp.gce.instance.group.manager.name" attribute. -func (rb *ResourceBuilder) SetGcpGceInstanceGroupManagerName(val string) { - if rb.config.GcpGceInstanceGroupManagerName.Enabled { - rb.res.Attributes().PutStr("gcp.gce.instance.group.manager.name", val) +// SetGcpGceInstanceHostname sets provided value as "gcp.gce.instance.hostname" attribute. +func (rb *ResourceBuilder) SetGcpGceInstanceHostname(val string) { + if rb.config.GcpGceInstanceHostname.Enabled { + rb.res.Attributes().PutStr("gcp.gce.instance.hostname", val) } } -// SetGcpGceInstanceGroupManagerRegion sets provided value as "gcp.gce.instance.group.manager.region" attribute. -func (rb *ResourceBuilder) SetGcpGceInstanceGroupManagerRegion(val string) { - if rb.config.GcpGceInstanceGroupManagerRegion.Enabled { - rb.res.Attributes().PutStr("gcp.gce.instance.group.manager.region", val) +// SetGcpGceInstanceName sets provided value as "gcp.gce.instance.name" attribute. +func (rb *ResourceBuilder) SetGcpGceInstanceName(val string) { + if rb.config.GcpGceInstanceName.Enabled { + rb.res.Attributes().PutStr("gcp.gce.instance.name", val) } } -// SetGcpGceInstanceGroupManagerZone sets provided value as "gcp.gce.instance.group.manager.zone" attribute. -func (rb *ResourceBuilder) SetGcpGceInstanceGroupManagerZone(val string) { - if rb.config.GcpGceInstanceGroupManagerZone.Enabled { - rb.res.Attributes().PutStr("gcp.gce.instance.group.manager.zone", val) +// SetGcpGceInstanceGroupManagerName sets provided value as "gcp.gce.instance_group_manager.name" attribute. +func (rb *ResourceBuilder) SetGcpGceInstanceGroupManagerName(val string) { + if rb.config.GcpGceInstanceGroupManagerName.Enabled { + rb.res.Attributes().PutStr("gcp.gce.instance_group_manager.name", val) } } -// SetGcpGceInstanceHostname sets provided value as "gcp.gce.instance.hostname" attribute. -func (rb *ResourceBuilder) SetGcpGceInstanceHostname(val string) { - if rb.config.GcpGceInstanceHostname.Enabled { - rb.res.Attributes().PutStr("gcp.gce.instance.hostname", val) +// SetGcpGceInstanceGroupManagerRegion sets provided value as "gcp.gce.instance_group_manager.region" attribute. +func (rb *ResourceBuilder) SetGcpGceInstanceGroupManagerRegion(val string) { + if rb.config.GcpGceInstanceGroupManagerRegion.Enabled { + rb.res.Attributes().PutStr("gcp.gce.instance_group_manager.region", val) } } -// SetGcpGceInstanceName sets provided value as "gcp.gce.instance.name" attribute. -func (rb *ResourceBuilder) SetGcpGceInstanceName(val string) { - if rb.config.GcpGceInstanceName.Enabled { - rb.res.Attributes().PutStr("gcp.gce.instance.name", val) +// SetGcpGceInstanceGroupManagerZone sets provided value as "gcp.gce.instance_group_manager.zone" attribute. +func (rb *ResourceBuilder) SetGcpGceInstanceGroupManagerZone(val string) { + if rb.config.GcpGceInstanceGroupManagerZone.Enabled { + rb.res.Attributes().PutStr("gcp.gce.instance_group_manager.zone", val) } } diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go index e69645cae40b..5991c52b62ce 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/generated_resource_test.go @@ -24,11 +24,11 @@ func TestResourceBuilder(t *testing.T) { rb.SetFaasVersion("faas.version-val") rb.SetGcpCloudRunJobExecution("gcp.cloud_run.job.execution-val") rb.SetGcpCloudRunJobTaskIndex("gcp.cloud_run.job.task_index-val") - rb.SetGcpGceInstanceGroupManagerName("gcp.gce.instance.group.manager.name-val") - rb.SetGcpGceInstanceGroupManagerRegion("gcp.gce.instance.group.manager.region-val") - rb.SetGcpGceInstanceGroupManagerZone("gcp.gce.instance.group.manager.zone-val") rb.SetGcpGceInstanceHostname("gcp.gce.instance.hostname-val") rb.SetGcpGceInstanceName("gcp.gce.instance.name-val") + rb.SetGcpGceInstanceGroupManagerName("gcp.gce.instance_group_manager.name-val") + rb.SetGcpGceInstanceGroupManagerRegion("gcp.gce.instance_group_manager.region-val") + rb.SetGcpGceInstanceGroupManagerZone("gcp.gce.instance_group_manager.zone-val") rb.SetHostID("host.id-val") rb.SetHostName("host.name-val") rb.SetHostType("host.type-val") @@ -104,30 +104,30 @@ func TestResourceBuilder(t *testing.T) { if ok { assert.EqualValues(t, "gcp.cloud_run.job.task_index-val", val.Str()) } - val, ok = res.Attributes().Get("gcp.gce.instance.group.manager.name") - assert.True(t, ok) + val, ok = res.Attributes().Get("gcp.gce.instance.hostname") + assert.Equal(t, tt == "all_set", ok) if ok { - assert.EqualValues(t, "gcp.gce.instance.group.manager.name-val", val.Str()) + assert.EqualValues(t, "gcp.gce.instance.hostname-val", val.Str()) } - val, ok = res.Attributes().Get("gcp.gce.instance.group.manager.region") - assert.True(t, ok) + val, ok = res.Attributes().Get("gcp.gce.instance.name") + assert.Equal(t, tt == "all_set", ok) if ok { - assert.EqualValues(t, "gcp.gce.instance.group.manager.region-val", val.Str()) + assert.EqualValues(t, "gcp.gce.instance.name-val", val.Str()) } - val, ok = res.Attributes().Get("gcp.gce.instance.group.manager.zone") + val, ok = res.Attributes().Get("gcp.gce.instance_group_manager.name") assert.True(t, ok) if ok { - assert.EqualValues(t, "gcp.gce.instance.group.manager.zone-val", val.Str()) + assert.EqualValues(t, "gcp.gce.instance_group_manager.name-val", val.Str()) } - val, ok = res.Attributes().Get("gcp.gce.instance.hostname") - assert.Equal(t, tt == "all_set", ok) + val, ok = res.Attributes().Get("gcp.gce.instance_group_manager.region") + assert.True(t, ok) if ok { - assert.EqualValues(t, "gcp.gce.instance.hostname-val", val.Str()) + assert.EqualValues(t, "gcp.gce.instance_group_manager.region-val", val.Str()) } - val, ok = res.Attributes().Get("gcp.gce.instance.name") - assert.Equal(t, tt == "all_set", ok) + val, ok = res.Attributes().Get("gcp.gce.instance_group_manager.zone") + assert.True(t, ok) if ok { - assert.EqualValues(t, "gcp.gce.instance.name-val", val.Str()) + assert.EqualValues(t, "gcp.gce.instance_group_manager.zone-val", val.Str()) } val, ok = res.Attributes().Get("host.id") assert.True(t, ok) diff --git a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml index db22079a8c66..859e9bef440b 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml +++ b/processor/resourcedetectionprocessor/internal/gcp/internal/metadata/testdata/config.yaml @@ -23,15 +23,15 @@ all_set: enabled: true gcp.cloud_run.job.task_index: enabled: true - gcp.gce.instance.group.manager.name: + gcp.gce.instance.hostname: enabled: true - gcp.gce.instance.group.manager.region: + gcp.gce.instance.name: enabled: true - gcp.gce.instance.group.manager.zone: + gcp.gce.instance_group_manager.name: enabled: true - gcp.gce.instance.hostname: + gcp.gce.instance_group_manager.region: enabled: true - gcp.gce.instance.name: + gcp.gce.instance_group_manager.zone: enabled: true host.id: enabled: true @@ -65,15 +65,15 @@ none_set: enabled: false gcp.cloud_run.job.task_index: enabled: false - gcp.gce.instance.group.manager.name: + gcp.gce.instance.hostname: enabled: false - gcp.gce.instance.group.manager.region: + gcp.gce.instance.name: enabled: false - gcp.gce.instance.group.manager.zone: + gcp.gce.instance_group_manager.name: enabled: false - gcp.gce.instance.hostname: + gcp.gce.instance_group_manager.region: enabled: false - gcp.gce.instance.name: + gcp.gce.instance_group_manager.zone: enabled: false host.id: enabled: false diff --git a/processor/resourcedetectionprocessor/internal/gcp/metadata.yaml b/processor/resourcedetectionprocessor/internal/gcp/metadata.yaml index b10fbae9a5b9..3026c6359447 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/metadata.yaml +++ b/processor/resourcedetectionprocessor/internal/gcp/metadata.yaml @@ -71,15 +71,15 @@ resource_attributes: description: The hostname of the GCE instance. type: string enabled: false - gcp.gce.instance.group.manager.name: + gcp.gce.instance_group_manager.name: description: The name of an instanceGroupManager. type: string enabled: true - gcp.gce.instance.group.manager.zone: + gcp.gce.instance_group_manager.zone: description: The zone of a zonal instanceGroupManager. type: string enabled: true - gcp.gce.instance.group.manager.region: + gcp.gce.instance_group_manager.region: description: The region of a regional instanceGroupManager. type: string enabled: true From 028e0fc19a40482050a92bd8ffffe936c1d693d4 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Wed, 18 Dec 2024 15:52:17 -0500 Subject: [PATCH 3/3] Add changelog --- .chloggen/gcp-gce-mig.yaml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .chloggen/gcp-gce-mig.yaml diff --git a/.chloggen/gcp-gce-mig.yaml b/.chloggen/gcp-gce-mig.yaml new file mode 100644 index 000000000000..7bf3638381a0 --- /dev/null +++ b/.chloggen/gcp-gce-mig.yaml @@ -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]