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

Feat/telemetry platform #5217

Merged
merged 13 commits into from
Mar 12, 2024
35 changes: 35 additions & 0 deletions internal/telemetry/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package telemetry

import (
"context"
"errors"
"strings"

metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -35,3 +37,36 @@ func (c *Collector) K8sVersion() (string, error) {
}
return sv.String(), nil
}

// Platform returns a string representing platform name.
func (c *Collector) Platform(ctx context.Context) (string, error) {
nodes, err := c.Config.K8sClientReader.CoreV1().Nodes().List(ctx, metaV1.ListOptions{})
if err != nil {
return "", err
}
if len(nodes.Items) == 0 {
return "", errors.New("no nodes in the cluster, cannot determine platform name")
}
return lookupPlatform(nodes.Items[0].Spec.ProviderID), nil
}

// lookupPlatform takes a string representing a K8s PlatformID
// retrieved from a cluster node and returns a string
// representing the platform name.
func lookupPlatform(providerID string) string {
provider := strings.TrimSpace(providerID)
if provider == "" {
return "other"
}

provider = strings.ToLower(providerID)
jjngx marked this conversation as resolved.
Show resolved Hide resolved

p := strings.Split(provider, ":")
if len(p) == 0 {
return "other"
}
if p[0] == "" {
return "other"
}
return p[0]
}
Loading
Loading