Skip to content

Collect Kubernetes distribution platform and version #1651

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

Merged
merged 24 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Revert CollectNodeCount and remove CollectNodeList
  • Loading branch information
bjee19 committed Mar 13, 2024
commit 39d0f148b484cbf60882e9fc72473587e61a33e7
15 changes: 8 additions & 7 deletions internal/mode/static/telemetry/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@ func CollectClusterID(ctx context.Context, k8sClient client.Reader) (string, err
return string(kubeNamespace.GetUID()), nil
}

// CollectNodeList returns a NodeList of all the Nodes in the cluster.
func CollectNodeList(ctx context.Context, k8sClient client.Reader) (v1.NodeList, error) {
// CollectNodeCount returns the number of nodes in the cluster.
func CollectNodeCount(ctx context.Context, k8sClient client.Reader) (int, error) {
var nodes v1.NodeList
if err := k8sClient.List(ctx, &nodes); err != nil {
return nodes, fmt.Errorf("failed to get NodeList: %w", err)
return 0, fmt.Errorf("failed to get NodeList: %w", err)
}

return nodes, nil
return len(nodes.Items), nil
}

type clusterInformation struct {
Expand All @@ -279,10 +279,11 @@ type clusterInformation struct {

func collectClusterInformation(ctx context.Context, k8sClient client.Reader) (clusterInformation, error) {
var clusterInfo clusterInformation
var err error

nodes, err := CollectNodeList(ctx, k8sClient)
if err != nil {
return clusterInformation{}, fmt.Errorf("failed to collect cluster information: %w", err)
var nodes v1.NodeList
if err = k8sClient.List(ctx, &nodes); err != nil {
return clusterInformation{}, fmt.Errorf("failed to get NodeList: %w", err)
}
if len(nodes.Items) == 0 {
return clusterInformation{}, errors.New("failed to collect cluster information: NodeList length is zero")
Expand Down
6 changes: 2 additions & 4 deletions internal/mode/static/usage/job_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ func CreateUsageJobWorker(
cfg config.Config,
) func(ctx context.Context) {
return func(ctx context.Context) {
nodeList, err := telemetry.CollectNodeList(ctx, k8sClient)
nodeCount, err := telemetry.CollectNodeCount(ctx, k8sClient)
if err != nil {
logger.Error(err, "Failed to collect nodes")
logger.Error(err, "Failed to collect node count")
}

nodeCount := len(nodeList.Items)

podCount, err := GetTotalNGFPodCount(ctx, k8sClient)
if err != nil {
logger.Error(err, "Failed to collect replica count")
Expand Down