diff --git a/processor/resourcedetectionprocessor/internal/openshift/openshift.go b/processor/resourcedetectionprocessor/internal/openshift/openshift.go index 244bfc2cf3d0..cf82e7330f38 100644 --- a/processor/resourcedetectionprocessor/internal/openshift/openshift.go +++ b/processor/resourcedetectionprocessor/internal/openshift/openshift.go @@ -16,6 +16,7 @@ package openshift // import "github.com/open-telemetry/opentelemetry-collector-c import ( "context" + "strings" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/processor" @@ -61,17 +62,44 @@ func (d *detector) Detect(ctx context.Context) (resource pcommon.Resource, schem return res, "", nil } - if infra.Provider != "" { - attrs.PutStr(conventions.AttributeCloudProvider, infra.Provider) + var ( + region string + platform string + provider string + ) + + switch strings.ToLower(infra.Status.PlatformStatus.Type) { + case "aws": + provider = conventions.AttributeCloudProviderAWS + platform = conventions.AttributeCloudPlatformAWSOpenshift + region = strings.ToLower(infra.Status.PlatformStatus.Aws.Region) + case "azure": + provider = conventions.AttributeCloudProviderAzure + platform = conventions.AttributeCloudPlatformAzureOpenshift + region = strings.ToLower(infra.Status.PlatformStatus.Azure.CloudName) + case "gcp": + provider = conventions.AttributeCloudProviderGCP + platform = conventions.AttributeCloudPlatformGoogleCloudOpenshift + region = strings.ToLower(infra.Status.PlatformStatus.GCP.Region) + case "ibmcloud": + provider = conventions.AttributeCloudProviderIbmCloud + platform = conventions.AttributeCloudPlatformIbmCloudOpenshift + region = strings.ToLower(infra.Status.PlatformStatus.IBMCloud.Location) + case "openstack": + region = strings.ToLower(infra.Status.PlatformStatus.OpenStack.CloudName) + } + + if infra.Status.InfrastructureName != "" { + attrs.PutStr(conventions.AttributeK8SClusterName, infra.Status.InfrastructureName) } - if infra.Platform != "" { - attrs.PutStr(conventions.AttributeCloudPlatform, infra.Platform) + if provider != "" { + attrs.PutStr(conventions.AttributeCloudProvider, provider) } - if infra.Name != "" { - attrs.PutStr(conventions.AttributeK8SClusterName, infra.Name) + if platform != "" { + attrs.PutStr(conventions.AttributeCloudPlatform, platform) } - if infra.Region != "" { - attrs.PutStr(conventions.AttributeCloudRegion, infra.Region) + if region != "" { + attrs.PutStr(conventions.AttributeCloudRegion, region) } // TODO(frzifus): support conventions openshift and kubernetes cluster version. diff --git a/processor/resourcedetectionprocessor/internal/openshift/openshift_test.go b/processor/resourcedetectionprocessor/internal/openshift/openshift_test.go index 5d5cdafbdde0..67ce9c4c7520 100644 --- a/processor/resourcedetectionprocessor/internal/openshift/openshift_test.go +++ b/processor/resourcedetectionprocessor/internal/openshift/openshift_test.go @@ -29,7 +29,7 @@ import ( ) type providerResponse struct { - ocp.InfrastructureMetadata + ocp.InfrastructureAPIResponse OpenShiftClusterVersion string K8SClusterVersion string @@ -56,11 +56,11 @@ func (m *mockProvider) K8SClusterVersion(context.Context) (string, error) { return m.res.K8SClusterVersion, nil } -func (m *mockProvider) Infrastructure(context.Context) (*ocp.InfrastructureMetadata, error) { +func (m *mockProvider) Infrastructure(context.Context) (*ocp.InfrastructureAPIResponse, error) { if m.infraErr != nil { return nil, m.infraErr } - return &m.res.InfrastructureMetadata, nil + return &m.res.InfrastructureAPIResponse, nil } func newTestDetector(t *testing.T, res *providerResponse, ocpCVErr, k8sCVErr, infraErr error) internal.Detector { @@ -107,11 +107,18 @@ func TestDetect(t *testing.T) { { name: "detect all details", detector: newTestDetector(t, &providerResponse{ - InfrastructureMetadata: ocp.InfrastructureMetadata{ - Name: "name", - Region: "region", - Platform: "aws_openshift", - Provider: "aws", + InfrastructureAPIResponse: ocp.InfrastructureAPIResponse{ + Status: ocp.InfrastructureStatus{ + InfrastructureName: "test-d-bm4rt", + ControlPlaneTopology: "HighlyAvailable", + InfrastructureTopology: "HighlyAvailable", + PlatformStatus: ocp.InfrastructurePlatformStatus{ + Type: "AWS", + Aws: ocp.InfrastructureStatusAWS{ + Region: "us-east-1", + }, + }, + }, }, OpenShiftClusterVersion: "4.1.2", K8SClusterVersion: "1.23.4", @@ -120,10 +127,10 @@ func TestDetect(t *testing.T) { expectedResource: func() pcommon.Resource { res := pcommon.NewResource() attrs := res.Attributes() + attrs.PutStr(conventions.AttributeK8SClusterName, "test-d-bm4rt") attrs.PutStr(conventions.AttributeCloudProvider, "aws") attrs.PutStr(conventions.AttributeCloudPlatform, "aws_openshift") - attrs.PutStr(conventions.AttributeK8SClusterName, "name") - attrs.PutStr(conventions.AttributeCloudRegion, "region") + attrs.PutStr(conventions.AttributeCloudRegion, "us-east-1") return res }(), expectedSchemaURL: conventions.SchemaURL,