Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[processor/resourcedetection] Add support for Bare Metal Solution GCP platform #32985

Merged
merged 5 commits into from May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
dashpole marked this conversation as resolved.
Show resolved Hide resolved
errs := d.rb.SetFromCallable(d.rb.SetCloudAccountID, d.detector.BareMetalSolutionProjectID)

d.rb.SetCloudPlatform("gcp_bare_metal_solution")
dashpole marked this conversation as resolved.
Show resolved Hide resolved
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)
}
Loading