From 5832f654d469d14705142ce0543810c953f1ba7b Mon Sep 17 00:00:00 2001 From: Alexey Basinov Date: Fri, 10 May 2024 09:25:45 -0700 Subject: [PATCH 1/3] Add support for Bare Metal Solution GCP platform --- .../internal/gcp/gcp.go | 13 ++++ .../internal/gcp/gcp_test.go | 76 ++++++++++++------- .../internal/gcp/types.go | 3 + 3 files changed, 66 insertions(+), 26 deletions(-) diff --git a/processor/resourcedetectionprocessor/internal/gcp/gcp.go b/processor/resourcedetectionprocessor/internal/gcp/gcp.go index e2ed72483f92..19fe89ab474b 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/gcp.go +++ b/processor/resourcedetectionprocessor/internal/gcp/gcp.go @@ -36,6 +36,7 @@ var removeGCPFaasID = featuregate.GlobalRegistry().MustRegister( // * Google App Engine (GAE). // * Cloud Run. // * Cloud Functions. +// * Bare Metal Solutions (BMS). func NewDetector(set processor.CreateSettings, dcfg internal.DetectorConfig) (internal.Detector, error) { cfg := dcfg.(Config) return &detector{ @@ -52,6 +53,18 @@ type detector struct { } func (d *detector) Detect(context.Context) (resource pcommon.Resource, schemaURL string, err error) { + if d.detector.CloudPlatform() == gcp.BareMetalSolution { + d.rb.SetCloudProvider(conventions.AttributeCloudProviderGCP) + errs := d.rb.SetFromCallable(d.rb.SetCloudAccountID, d.detector.BareMetalSolutionProjectID) + + d.rb.SetCloudPlatform("gcp_bare_metal_solution") + errs = multierr.Combine(errs, + d.rb.SetFromCallable(d.rb.SetHostName, d.detector.BareMetalSolutionInstanceID), + d.rb.SetFromCallable(d.rb.SetCloudRegion, d.detector.BareMetalSolutionCloudRegion), + ) + return d.rb.Emit(), conventions.SchemaURL, errs + } + if !metadata.OnGCE() { return pcommon.NewResource(), "", nil } diff --git a/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go b/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go index 3dce53426e8b..96882da713a4 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go +++ b/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go @@ -413,32 +413,35 @@ func newTestDetector(gcpDetector *fakeGCPDetector, opts ...func(*localMetadata.R // fakeGCPDetector implements gcpDetector and uses fake values. type fakeGCPDetector struct { - err error - projectID string - cloudPlatform gcp.Platform - gkeAvailabilityZone string - gkeRegion string - gkeClusterName string - gkeHostID string - faaSName string - faaSVersion string - faaSID string - faaSCloudRegion string - appEngineAvailabilityZone string - appEngineRegion string - appEngineServiceName string - appEngineServiceVersion string - appEngineServiceInstance string - gceAvailabilityZone string - gceRegion string - gceHostType string - gceHostID string - gceHostName string - gceHostNameErr error - gcpCloudRunJobExecution string - gcpCloudRunJobTaskIndex string - gcpGceInstanceName string - gcpGceInstanceHostname string + err error + projectID string + cloudPlatform gcp.Platform + gkeAvailabilityZone string + gkeRegion string + gkeClusterName string + gkeHostID string + faaSName string + faaSVersion string + faaSID string + faaSCloudRegion string + appEngineAvailabilityZone string + appEngineRegion string + appEngineServiceName string + appEngineServiceVersion string + appEngineServiceInstance string + gceAvailabilityZone string + gceRegion string + gceHostType string + gceHostID string + gceHostName string + gceHostNameErr error + gcpCloudRunJobExecution string + gcpCloudRunJobTaskIndex string + gcpGceInstanceName string + gcpGceInstanceHostname string + gcpBareMetalSolutionInstanceID string + gcpBareMetalSolutionCloudRegion string + gcpBareMetalSolutionProjectID string } func (f *fakeGCPDetector) ProjectID() (string, error) { @@ -601,3 +604,24 @@ func (f *fakeGCPDetector) GCEInstanceHostname() (string, error) { } return f.gcpGceInstanceHostname, nil } + +func (f *fakeGCPDetector) BareMetalSolutionInstanceID() (string, error) { + if f.err != nil { + return "", f.err + } + return f.gcpBareMetalSolutionInstanceID, nil +} + +func (f *fakeGCPDetector) BareMetalSolutionCloudRegion() (string, error) { + if f.err != nil { + return "", f.err + } + return f.gcpBareMetalSolutionCloudRegion, nil +} + +func (f *fakeGCPDetector) BareMetalSolutionProjectID() (string, error) { + if f.err != nil { + return "", f.err + } + return f.gcpBareMetalSolutionProjectID, nil +} diff --git a/processor/resourcedetectionprocessor/internal/gcp/types.go b/processor/resourcedetectionprocessor/internal/gcp/types.go index a4bcb4e2bbf6..523ba84d73bb 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/types.go +++ b/processor/resourcedetectionprocessor/internal/gcp/types.go @@ -33,4 +33,7 @@ type gcpDetector interface { CloudRunJobTaskIndex() (string, error) GCEInstanceHostname() (string, error) GCEInstanceName() (string, error) + BareMetalSolutionInstanceID() (string, error) + BareMetalSolutionCloudRegion() (string, error) + BareMetalSolutionProjectID() (string, error) } From d1ebdd7820b6b0effd9dc01aa389dd2d65c0b9d5 Mon Sep 17 00:00:00 2001 From: Alexey Basinov Date: Mon, 13 May 2024 10:14:28 -0700 Subject: [PATCH 2/3] add a test for BMS --- .../internal/gcp/gcp_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go b/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go index 96882da713a4..8574a6250eb2 100644 --- a/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go +++ b/processor/resourcedetectionprocessor/internal/gcp/gcp_test.go @@ -363,6 +363,23 @@ func TestDetect(t *testing.T) { }, addFaasID: true, }, + { + desc: "Bare Metal Solution", + detector: newTestDetector(&fakeGCPDetector{ + projectID: "my-project", + cloudPlatform: gcp.BareMetalSolution, + gcpBareMetalSolutionCloudRegion: "us-central1", + gcpBareMetalSolutionInstanceID: "1472385723456792345", + gcpBareMetalSolutionProjectID: "my-project", + }), + expectedResource: map[string]any{ + conventions.AttributeCloudProvider: conventions.AttributeCloudProviderGCP, + conventions.AttributeCloudAccountID: "my-project", + conventions.AttributeCloudPlatform: "gcp_bare_metal_solution", + conventions.AttributeCloudRegion: "us-central1", + conventions.AttributeHostName: "1472385723456792345", + }, + }, { desc: "Unknown Platform", detector: newTestDetector(&fakeGCPDetector{ From 87b97a8f2624b9cd076642dcecca4830af2e0190 Mon Sep 17 00:00:00 2001 From: Alexey Basinov Date: Tue, 14 May 2024 08:12:01 -0700 Subject: [PATCH 3/3] Add a changelog entry --- .../gcp-bare-metal-solution-detector.yaml | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .chloggen/gcp-bare-metal-solution-detector.yaml diff --git a/.chloggen/gcp-bare-metal-solution-detector.yaml b/.chloggen/gcp-bare-metal-solution-detector.yaml new file mode 100644 index 000000000000..756a0baaf674 --- /dev/null +++ b/.chloggen/gcp-bare-metal-solution-detector.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: Support GCP Bare Metal Solution 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: [32985] + +# (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: []