Skip to content

Commit fea9317

Browse files
committed
feat: add clusterID to telemetry objects
1 parent 25ea723 commit fea9317

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

internal/mode/static/telemetry/collector.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import (
1414
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/graph"
1515
)
1616

17+
// kubeSystem indicates the name of kube-system namespace
18+
const kubeSystem = "kube-system"
19+
1720
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . GraphGetter
1821

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

106+
var clusterID string
107+
if clusterID, err = collectClusterID(ctx, c.cfg.K8sClientReader); err != nil {
108+
return Data{}, fmt.Errorf("failed to collect clusterID: %w", err)
109+
}
110+
102111
data := Data{
103112
NodeCount: nodeCount,
104113
NGFResourceCounts: graphResourceCount,
@@ -107,6 +116,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
107116
Version: c.cfg.Version,
108117
},
109118
NGFReplicaCount: ngfReplicaCount,
119+
ClusterID: clusterID,
110120
}
111121

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

194204
return int(*replicaSet.Spec.Replicas), nil
195205
}
206+
207+
func collectClusterID(ctx context.Context, k8sClient client.Reader) (string, error) {
208+
key := types.NamespacedName{
209+
Name: kubeSystem,
210+
}
211+
var kubeNamespace v1.Namespace
212+
err := k8sClient.Get(ctx, key, &kubeNamespace)
213+
if err != nil {
214+
return "", fmt.Errorf("failed to get namespace :%w", err)
215+
}
216+
return string(kubeNamespace.GetUID()), nil
217+
}

0 commit comments

Comments
 (0)