Skip to content

Commit c0d65e5

Browse files
committed
feat: add deploymentID to telemetry object collector
1 parent 0d1d49a commit c0d65e5

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

internal/mode/static/telemetry/collector.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ type Data struct {
5454
ClusterID string
5555
ImageSource string
5656
Arch string
57-
NGFResourceCounts NGFResourceCounts
57+
DeploymentID string
5858
NodeCount int
59+
NGFResourceCounts NGFResourceCounts
5960
NGFReplicaCount int
6061
}
6162

@@ -101,7 +102,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
101102
return Data{}, fmt.Errorf("failed to collect NGF resource counts: %w", err)
102103
}
103104

104-
ngfReplicaCount, err := collectNGFReplicaCount(ctx, c.cfg.K8sClientReader, c.cfg.PodNSName)
105+
ngfReplicaCount, deploymentID, err := collectNGFReplicaData(ctx, c.cfg.K8sClientReader, c.cfg.PodNSName)
105106
if err != nil {
106107
return Data{}, fmt.Errorf("failed to collect NGF replica count: %w", err)
107108
}
@@ -122,6 +123,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
122123
ClusterID: clusterID,
123124
ImageSource: c.cfg.ImageSource,
124125
Arch: runtime.GOARCH,
126+
DeploymentID: deploymentID,
125127
}
126128

127129
return data, nil
@@ -175,23 +177,31 @@ func collectGraphResourceCount(
175177
return ngfResourceCounts, nil
176178
}
177179

178-
func collectNGFReplicaCount(ctx context.Context, k8sClient client.Reader, podNSName types.NamespacedName) (int, error) {
180+
func collectNGFReplicaData(
181+
ctx context.Context,
182+
k8sClient client.Reader,
183+
podNSName types.NamespacedName,
184+
) (int, string, error) {
179185
var pod v1.Pod
180186
if err := k8sClient.Get(
181187
ctx,
182188
types.NamespacedName{Namespace: podNSName.Namespace, Name: podNSName.Name},
183189
&pod,
184190
); err != nil {
185-
return 0, fmt.Errorf("failed to get NGF Pod: %w", err)
191+
return 0, "", fmt.Errorf("failed to get NGF Pod: %w", err)
186192
}
187193

188194
podOwnerRefs := pod.GetOwnerReferences()
189195
if len(podOwnerRefs) != 1 {
190-
return 0, fmt.Errorf("expected one owner reference of the NGF Pod, got %d", len(podOwnerRefs))
196+
return 0, "", fmt.Errorf("expected one owner reference of the NGF Pod, got %d", len(podOwnerRefs))
191197
}
192198

193199
if podOwnerRefs[0].Kind != "ReplicaSet" {
194-
return 0, fmt.Errorf("expected pod owner reference to be ReplicaSet, got %s", podOwnerRefs[0].Kind)
200+
return 0, "", fmt.Errorf("expected pod owner reference to be ReplicaSet, got %s", podOwnerRefs[0].Kind)
201+
}
202+
203+
if podOwnerRefs[0].UID == "" {
204+
return 0, "", fmt.Errorf("expected pod owner reference to have a UID: %v", podOwnerRefs[0])
195205
}
196206

197207
var replicaSet appsv1.ReplicaSet
@@ -200,14 +210,14 @@ func collectNGFReplicaCount(ctx context.Context, k8sClient client.Reader, podNSN
200210
types.NamespacedName{Namespace: podNSName.Namespace, Name: podOwnerRefs[0].Name},
201211
&replicaSet,
202212
); err != nil {
203-
return 0, fmt.Errorf("failed to get NGF Pod's ReplicaSet: %w", err)
213+
return 0, "", fmt.Errorf("failed to get NGF Pod's ReplicaSet: %w", err)
204214
}
205215

206216
if replicaSet.Spec.Replicas == nil {
207-
return 0, errors.New("replica set replicas was nil")
217+
return 0, "", errors.New("replica set replicas was nil")
208218
}
209219

210-
return int(*replicaSet.Spec.Replicas), nil
220+
return int(*replicaSet.Spec.Replicas), string(podOwnerRefs[0].UID), nil
211221
}
212222

213223
// CollectClusterID gets the UID of the kube-system namespace.

internal/mode/static/telemetry/collector_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ var _ = Describe("Collector", Ordered, func() {
9292
{
9393
Kind: "ReplicaSet",
9494
Name: "replicaset1",
95+
UID: "test-pod-owner-uid",
9596
},
9697
},
9798
},
@@ -126,6 +127,7 @@ var _ = Describe("Collector", Ordered, func() {
126127
ClusterID: string(kubeNamespace.GetUID()),
127128
ImageSource: "local",
128129
Arch: runtime.GOARCH,
130+
DeploymentID: string(ngfPod.OwnerReferences[0].UID),
129131
}
130132

131133
k8sClientReader = &eventsfakes.FakeReader{}

0 commit comments

Comments
 (0)