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
5 changes: 3 additions & 2 deletions internal/configs/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1479,8 +1479,9 @@ func (cnf *Configurator) GetIngressCounts() map[string]int {

// GetVirtualServerCounts returns the total count of
// VirtualServer and VirtualServerRoute resources that are handled by the Ingress Controller
func (cnf *Configurator) GetVirtualServerCounts() (vsCount int, vsrCount int) {
vsCount = len(cnf.virtualServers)
func (cnf *Configurator) GetVirtualServerCounts() (int, int) {
vsCount := len(cnf.virtualServers)
vsrCount := 0
for _, vs := range cnf.virtualServers {
vsrCount += len(vs.VirtualServerRoutes)
}
Expand Down
39 changes: 37 additions & 2 deletions internal/telemetry/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ package telemetry

import (
"context"
"errors"
"strings"

metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NodeCount returns the total number of nodes in the cluster.
// It returns an error if the underlying k8s API client errors.
func (c *Collector) NodeCount(ctx context.Context) (int64, error) {
func (c *Collector) NodeCount(ctx context.Context) (int, error) {
nodes, err := c.Config.K8sClientReader.CoreV1().Nodes().List(ctx, metaV1.ListOptions{})
if err != nil {
return 0, err
}
return int64(len(nodes.Items)), nil
return len(nodes.Items), nil
}

// ClusterID returns the UID of the kube-system namespace representing cluster id.
Expand All @@ -35,3 +37,36 @@ func (c *Collector) ClusterVersion() (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