Skip to content

Commit 289843b

Browse files
[processor/resourcedetection] Add support for Bare Metal Solution GCP 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 <[email protected]>
1 parent d3c9cff commit 289843b

File tree

4 files changed

+110
-26
lines changed

4 files changed

+110
-26
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: resourcedetectionprocessor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Support GCP Bare Metal Solution in resource detection processor.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [32985]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

processor/resourcedetectionprocessor/internal/gcp/gcp.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var removeGCPFaasID = featuregate.GlobalRegistry().MustRegister(
3636
// * Google App Engine (GAE).
3737
// * Cloud Run.
3838
// * Cloud Functions.
39+
// * Bare Metal Solutions (BMS).
3940
func NewDetector(set processor.CreateSettings, dcfg internal.DetectorConfig) (internal.Detector, error) {
4041
cfg := dcfg.(Config)
4142
return &detector{
@@ -52,6 +53,18 @@ type detector struct {
5253
}
5354

5455
func (d *detector) Detect(context.Context) (resource pcommon.Resource, schemaURL string, err error) {
56+
if d.detector.CloudPlatform() == gcp.BareMetalSolution {
57+
d.rb.SetCloudProvider(conventions.AttributeCloudProviderGCP)
58+
errs := d.rb.SetFromCallable(d.rb.SetCloudAccountID, d.detector.BareMetalSolutionProjectID)
59+
60+
d.rb.SetCloudPlatform("gcp_bare_metal_solution")
61+
errs = multierr.Combine(errs,
62+
d.rb.SetFromCallable(d.rb.SetHostName, d.detector.BareMetalSolutionInstanceID),
63+
d.rb.SetFromCallable(d.rb.SetCloudRegion, d.detector.BareMetalSolutionCloudRegion),
64+
)
65+
return d.rb.Emit(), conventions.SchemaURL, errs
66+
}
67+
5568
if !metadata.OnGCE() {
5669
return pcommon.NewResource(), "", nil
5770
}

processor/resourcedetectionprocessor/internal/gcp/gcp_test.go

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,23 @@ func TestDetect(t *testing.T) {
363363
},
364364
addFaasID: true,
365365
},
366+
{
367+
desc: "Bare Metal Solution",
368+
detector: newTestDetector(&fakeGCPDetector{
369+
projectID: "my-project",
370+
cloudPlatform: gcp.BareMetalSolution,
371+
gcpBareMetalSolutionCloudRegion: "us-central1",
372+
gcpBareMetalSolutionInstanceID: "1472385723456792345",
373+
gcpBareMetalSolutionProjectID: "my-project",
374+
}),
375+
expectedResource: map[string]any{
376+
conventions.AttributeCloudProvider: conventions.AttributeCloudProviderGCP,
377+
conventions.AttributeCloudAccountID: "my-project",
378+
conventions.AttributeCloudPlatform: "gcp_bare_metal_solution",
379+
conventions.AttributeCloudRegion: "us-central1",
380+
conventions.AttributeHostName: "1472385723456792345",
381+
},
382+
},
366383
{
367384
desc: "Unknown Platform",
368385
detector: newTestDetector(&fakeGCPDetector{
@@ -413,32 +430,35 @@ func newTestDetector(gcpDetector *fakeGCPDetector, opts ...func(*localMetadata.R
413430

414431
// fakeGCPDetector implements gcpDetector and uses fake values.
415432
type fakeGCPDetector struct {
416-
err error
417-
projectID string
418-
cloudPlatform gcp.Platform
419-
gkeAvailabilityZone string
420-
gkeRegion string
421-
gkeClusterName string
422-
gkeHostID string
423-
faaSName string
424-
faaSVersion string
425-
faaSID string
426-
faaSCloudRegion string
427-
appEngineAvailabilityZone string
428-
appEngineRegion string
429-
appEngineServiceName string
430-
appEngineServiceVersion string
431-
appEngineServiceInstance string
432-
gceAvailabilityZone string
433-
gceRegion string
434-
gceHostType string
435-
gceHostID string
436-
gceHostName string
437-
gceHostNameErr error
438-
gcpCloudRunJobExecution string
439-
gcpCloudRunJobTaskIndex string
440-
gcpGceInstanceName string
441-
gcpGceInstanceHostname string
433+
err error
434+
projectID string
435+
cloudPlatform gcp.Platform
436+
gkeAvailabilityZone string
437+
gkeRegion string
438+
gkeClusterName string
439+
gkeHostID string
440+
faaSName string
441+
faaSVersion string
442+
faaSID string
443+
faaSCloudRegion string
444+
appEngineAvailabilityZone string
445+
appEngineRegion string
446+
appEngineServiceName string
447+
appEngineServiceVersion string
448+
appEngineServiceInstance string
449+
gceAvailabilityZone string
450+
gceRegion string
451+
gceHostType string
452+
gceHostID string
453+
gceHostName string
454+
gceHostNameErr error
455+
gcpCloudRunJobExecution string
456+
gcpCloudRunJobTaskIndex string
457+
gcpGceInstanceName string
458+
gcpGceInstanceHostname string
459+
gcpBareMetalSolutionInstanceID string
460+
gcpBareMetalSolutionCloudRegion string
461+
gcpBareMetalSolutionProjectID string
442462
}
443463

444464
func (f *fakeGCPDetector) ProjectID() (string, error) {
@@ -601,3 +621,24 @@ func (f *fakeGCPDetector) GCEInstanceHostname() (string, error) {
601621
}
602622
return f.gcpGceInstanceHostname, nil
603623
}
624+
625+
func (f *fakeGCPDetector) BareMetalSolutionInstanceID() (string, error) {
626+
if f.err != nil {
627+
return "", f.err
628+
}
629+
return f.gcpBareMetalSolutionInstanceID, nil
630+
}
631+
632+
func (f *fakeGCPDetector) BareMetalSolutionCloudRegion() (string, error) {
633+
if f.err != nil {
634+
return "", f.err
635+
}
636+
return f.gcpBareMetalSolutionCloudRegion, nil
637+
}
638+
639+
func (f *fakeGCPDetector) BareMetalSolutionProjectID() (string, error) {
640+
if f.err != nil {
641+
return "", f.err
642+
}
643+
return f.gcpBareMetalSolutionProjectID, nil
644+
}

processor/resourcedetectionprocessor/internal/gcp/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@ type gcpDetector interface {
3333
CloudRunJobTaskIndex() (string, error)
3434
GCEInstanceHostname() (string, error)
3535
GCEInstanceName() (string, error)
36+
BareMetalSolutionInstanceID() (string, error)
37+
BareMetalSolutionCloudRegion() (string, error)
38+
BareMetalSolutionProjectID() (string, error)
3639
}

0 commit comments

Comments
 (0)