Skip to content

Commit fb6c99d

Browse files
committed
fixed tests in watcher_test.go
1 parent 65dd34e commit fb6c99d

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

receiver/k8sclusterreceiver/internal/container/containers_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/constants"
1110
"github.com/stretchr/testify/assert"
1211
"github.com/stretchr/testify/require"
1312
corev1 "k8s.io/api/core/v1"
1413
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1514
"k8s.io/apimachinery/pkg/types"
15+
16+
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/constants"
1617
)
1718

1819
func TestGetMetadata(t *testing.T) {

receiver/k8sclusterreceiver/watcher_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func TestSyncMetadataAndEmitEntityEvents(t *testing.T) {
270270
"otel.entity.interval": int64(7200000), // 2h in milliseconds
271271
"otel.entity.type": "k8s.pod",
272272
"otel.entity.id": map[string]any{"k8s.pod.uid": "pod0"},
273-
"otel.entity.attributes": map[string]any{"pod.creation_timestamp": "0001-01-01T00:00:00Z", "k8s.pod.phase": "Unknown"},
273+
"otel.entity.attributes": map[string]any{"pod.creation_timestamp": "0001-01-01T00:00:00Z", "k8s.pod.phase": "Unknown", "k8s.namespace.name": "test", "k8s.pod.name": "0"},
274274
}
275275
assert.EqualValues(t, expected, lr.Attributes().AsRaw())
276276
assert.WithinRange(t, lr.Timestamp().AsTime(), step1, step2)
@@ -324,7 +324,7 @@ func TestObjMetadata(t *testing.T) {
324324
EntityType: "k8s.pod",
325325
ResourceIDKey: "k8s.pod.uid",
326326
ResourceID: "test-pod-0-uid",
327-
Metadata: allPodMetadata(map[string]string{"k8s.pod.phase": "Succeeded"}),
327+
Metadata: allPodMetadata(map[string]string{"k8s.pod.phase": "Succeeded", "k8s.pod.name": "test-pod-0", "k8s.namespace.name": "test-namespace"}),
328328
},
329329
experimentalmetricmetadata.ResourceID("container-id"): {
330330
EntityType: "container",
@@ -333,6 +333,10 @@ func TestObjMetadata(t *testing.T) {
333333
Metadata: map[string]string{
334334
"container.status": "running",
335335
"container.creation_timestamp": "0001-01-01T01:01:01Z",
336+
"container.image": "container-image-name",
337+
"container.name": "container-name",
338+
"k8s.pod.name": "test-pod-0",
339+
"k8s.pod.uid": "test-pod-0-uid",
336340
},
337341
},
338342
},
@@ -359,6 +363,8 @@ func TestObjMetadata(t *testing.T) {
359363
"k8s.statefulset.uid": "test-statefulset-0-uid",
360364
"k8s.pod.phase": "Failed",
361365
"k8s.pod.status_reason": "Evicted",
366+
"k8s.pod.name": "test-pod-0",
367+
"k8s.namespace.name": "test-namespace",
362368
}),
363369
},
364370
},
@@ -398,6 +404,8 @@ func TestObjMetadata(t *testing.T) {
398404
"k8s.service.test-service": "",
399405
"k8s-app": "my-app",
400406
"k8s.pod.phase": "Running",
407+
"k8s.namespace.name": "test-namespace",
408+
"k8s.pod.name": "test-pod-0",
401409
}),
402410
},
403411
},
@@ -415,6 +423,7 @@ func TestObjMetadata(t *testing.T) {
415423
"k8s.workload.kind": "DaemonSet",
416424
"k8s.workload.name": "test-daemonset-1",
417425
"daemonset.creation_timestamp": "0001-01-01T00:00:00Z",
426+
"k8s.namespace.name": "test-namespace",
418427
},
419428
},
420429
},
@@ -433,6 +442,7 @@ func TestObjMetadata(t *testing.T) {
433442
"k8s.workload.name": "test-deployment-1",
434443
"k8s.deployment.name": "test-deployment-1",
435444
"deployment.creation_timestamp": "0001-01-01T00:00:00Z",
445+
"k8s.namespace.name": "test-namespace",
436446
},
437447
},
438448
},
@@ -450,6 +460,7 @@ func TestObjMetadata(t *testing.T) {
450460
"k8s.workload.kind": "HPA",
451461
"k8s.workload.name": "test-hpa-1",
452462
"hpa.creation_timestamp": "0001-01-01T00:00:00Z",
463+
"k8s.namespace.name": "test-namespace",
453464
},
454465
},
455466
},
@@ -469,6 +480,7 @@ func TestObjMetadata(t *testing.T) {
469480
"k8s.workload.kind": "Job",
470481
"k8s.workload.name": "test-job-1",
471482
"job.creation_timestamp": "0001-01-01T00:00:00Z",
483+
"k8s.namespace.name": "test-namespace",
472484
},
473485
},
474486
},
@@ -511,6 +523,7 @@ func TestObjMetadata(t *testing.T) {
511523
"k8s.workload.kind": "ReplicaSet",
512524
"k8s.workload.name": "test-replicaset-1",
513525
"replicaset.creation_timestamp": "0001-01-01T00:00:00Z",
526+
"k8s.namespace.name": "test-namespace",
514527
},
515528
},
516529
},
@@ -534,6 +547,7 @@ func TestObjMetadata(t *testing.T) {
534547
"k8s.workload.kind": "ReplicationController",
535548
"k8s.workload.name": "test-replicationcontroller-1",
536549
"replicationcontroller.creation_timestamp": "0001-01-01T00:00:00Z",
550+
"k8s.namespace.name": "test-namespace",
537551
},
538552
},
539553
},

0 commit comments

Comments
 (0)