Skip to content

Commit

Permalink
[processor/resourcedetection] Add support for Bare Metal Solution GCP…
Browse files Browse the repository at this point in the history
… platform (#32985)

**Description:** Add support for Bare Metal Solution platform to the GCP
resourcedetection processor

FYI I had to place the check for gcp.BareMetalSolution before
!metadata.OnGCE() because the latter fails on Bare Metal Solution due to
the absence of a metadata server.

**Link to tracking Issue:**

**Testing:** unit tests updated

**Documentation:**

---------

Co-authored-by: David Ashpole <dashpole@google.com>
  • Loading branch information
AlexBasinov and dashpole authored May 15, 2024
1 parent d3c9cff commit 289843b
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 26 deletions.
27 changes: 27 additions & 0 deletions .chloggen/gcp-bare-metal-solution-detector.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: 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: []
13 changes: 13 additions & 0 deletions processor/resourcedetectionprocessor/internal/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
}
Expand Down
93 changes: 67 additions & 26 deletions processor/resourcedetectionprocessor/internal/gcp/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions processor/resourcedetectionprocessor/internal/gcp/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 289843b

Please sign in to comment.