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

Collects ClusterId for Telemetry Object Collector #1565

Merged
merged 15 commits into from
Feb 15, 2024
Merged
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions internal/mode/static/telemetry/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/graph"
)

// kubeSystem indicates the name of kube-system namespace
salonichf5 marked this conversation as resolved.
Show resolved Hide resolved
const kubeSystem = "kube-system"
salonichf5 marked this conversation as resolved.
Show resolved Hide resolved

//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . GraphGetter

// GraphGetter gets the latest Graph.
Expand Down Expand Up @@ -49,6 +52,7 @@ type ProjectMetadata struct {
// Note: this type might change once https://github.com/nginxinc/nginx-gateway-fabric/issues/1318 is implemented.
type Data struct {
ProjectMetadata ProjectMetadata
ClusterID string
NodeCount int
NGFResourceCounts NGFResourceCounts
NGFReplicaCount int
Expand Down Expand Up @@ -99,6 +103,11 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
return Data{}, fmt.Errorf("failed to collect NGF replica count: %w", err)
}

var clusterID string
if clusterID, err = collectClusterID(ctx, c.cfg.K8sClientReader); err != nil {
return Data{}, fmt.Errorf("failed to collect clusterID: %w", err)
}

data := Data{
NodeCount: nodeCount,
NGFResourceCounts: graphResourceCount,
Expand All @@ -107,6 +116,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
Version: c.cfg.Version,
},
NGFReplicaCount: ngfReplicaCount,
ClusterID: clusterID,
}

return data, nil
Expand Down Expand Up @@ -193,3 +203,15 @@ func collectNGFReplicaCount(ctx context.Context, k8sClient client.Reader, podNSN

return int(*replicaSet.Spec.Replicas), nil
}

func collectClusterID(ctx context.Context, k8sClient client.Reader) (string, error) {
key := types.NamespacedName{
Name: kubeSystem,
}
var kubeNamespace v1.Namespace
err := k8sClient.Get(ctx, key, &kubeNamespace)
if err != nil {
return "", fmt.Errorf("failed to get namespace :%w", err)
salonichf5 marked this conversation as resolved.
Show resolved Hide resolved
}
salonichf5 marked this conversation as resolved.
Show resolved Hide resolved
return string(kubeNamespace.GetUID()), nil
}
Loading