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: [] 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..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{ @@ -413,32 +430,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 +621,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) }