@@ -462,9 +462,7 @@ func TestE2ENamespaceMetadata(t *testing.T) {
462462 defer shutdownSink ()
463463
464464 testID := uuid .NewString ()[:8 ]
465- collectorObjs := k8stest .CreateCollectorObjects (t , k8sClient , testID , filepath .Join ("." , "testdata" , "e2e" , "entities-test" , "collector" ), map [string ]string {
466- "FeatureGates" : entityEventsSpecificationFeatureGate ,
467- }, "" )
465+ collectorObjs := k8stest .CreateCollectorObjects (t , k8sClient , testID , filepath .Join ("." , "testdata" , "e2e" , "entities-test" , "collector" ), map [string ]string {}, "" )
468466
469467 t .Cleanup (func () {
470468 for _ , obj := range collectorObjs {
@@ -484,10 +482,10 @@ func TestE2ENamespaceMetadata(t *testing.T) {
484482 require .NoError (t , err )
485483
486484 commonReplacements := map [string ]map [string ]string {
487- "entity.description " : {
485+ "otel. entity.attributes " : {
488486 "k8s.namespace.creation_timestamp" : "2025-01-01T00:00:00Z" ,
489487 },
490- "entity.id" : {
488+ "otel. entity.id" : {
491489 "k8s.namespace.uid" : "entity-id" ,
492490 },
493491 }
@@ -512,7 +510,7 @@ func TestE2ENamespaceMetadata(t *testing.T) {
512510
513511 // update the phase in expected log to terminating
514512 replaceLogValues (t , expected , map [string ]map [string ]string {
515- "entity.description " : {
513+ "otel. entity.attributes " : {
516514 "k8s.namespace.phase" : "terminating" ,
517515 },
518516 })
@@ -535,9 +533,7 @@ func TestE2EPVCEntity(t *testing.T) {
535533 defer shutdownSink ()
536534
537535 testID := uuid .NewString ()[:8 ]
538- collectorObjs := k8stest .CreateCollectorObjects (t , k8sClient , testID , filepath .Join ("." , "testdata" , "e2e" , "entities-test" , "collector" ), map [string ]string {
539- "FeatureGates" : entityEventsSpecificationFeatureGate ,
540- }, "" )
536+ collectorObjs := k8stest .CreateCollectorObjects (t , k8sClient , testID , filepath .Join ("." , "testdata" , "e2e" , "entities-test" , "collector" ), map [string ]string {}, "" )
541537
542538 t .Cleanup (func () {
543539 for _ , obj := range collectorObjs {
@@ -560,10 +556,10 @@ func TestE2EPVCEntity(t *testing.T) {
560556 require .NoError (t , err )
561557
562558 commonReplacements := map [string ]map [string ]string {
563- "entity.description " : {
559+ "otel. entity.attributes " : {
564560 "k8s.persistentvolumeclaim.creation_timestamp" : "2025-01-01T00:00:00Z" ,
565561 },
566- "entity.id" : {
562+ "otel. entity.id" : {
567563 "k8s.persistentvolumeclaim.uid" : "entity-id" ,
568564 },
569565 }
@@ -578,8 +574,8 @@ func TestE2EPVCEntity(t *testing.T) {
578574 ))
579575}
580576
581- // TestE2ENamespaceMetadataLegacy tests legacy entity event exporting when the entity events specification feature gate is disabled .
582- func TestE2ENamespaceMetadataLegacy (t * testing.T ) {
577+ // TestE2ENamespaceMetadataWithEntityEventsSpecificationFeatureGate tests entity event exporting using the entity events specification.
578+ func TestE2ENamespaceMetadataWithEntityEventsSpecificationFeatureGate (t * testing.T ) {
583579 k8sClient , err := k8stest .NewK8sClient (testKubeConfig )
584580 require .NoError (t , err )
585581
@@ -589,7 +585,7 @@ func TestE2ENamespaceMetadataLegacy(t *testing.T) {
589585
590586 testID := uuid .NewString ()[:8 ]
591587 collectorObjs := k8stest .CreateCollectorObjects (t , k8sClient , testID , filepath .Join ("." , "testdata" , "e2e" , "entities-test" , "collector" ), map [string ]string {
592- "FeatureGates" : "-" + entityEventsSpecificationFeatureGate ,
588+ "FeatureGates" : entityEventsSpecificationFeatureGate ,
593589 }, "" )
594590
595591 t .Cleanup (func () {
@@ -598,27 +594,49 @@ func TestE2ENamespaceMetadataLegacy(t *testing.T) {
598594 }
599595 })
600596
601- namespaceObj , err := k8stest .CreateObjects (k8sClient , filepath .Join ("." , "testdata" , "e2e" , "entities-test" , "testobjects-legacy " ))
597+ namespaceObj , err := k8stest .CreateObjects (k8sClient , filepath .Join ("." , "testdata" , "e2e" , "entities-test" , "testobjects" ))
602598 require .NoErrorf (t , err , "failed to create test k8s objects" )
603- t .Cleanup (func () {
604- require .NoErrorf (t , k8stest .DeleteObjects (k8sClient , namespaceObj ), "failed to delete test k8s objects" )
605- })
606599
607600 entityType := "k8s.namespace"
608601 entityNameKey := "k8s.namespace.name"
609- entityName := "test-entities-ns-legacy "
602+ entityName := "test-entities-ns"
610603 namespaceLogs := waitForEntityLogs (t , entityType , entityNameKey , entityName , logsConsumer )
611604
612- expected , err := golden .ReadLogs ("./testdata/e2e/entities-test/expected-ns-legacy .yaml" )
605+ expected , err := golden .ReadLogs ("./testdata/e2e/entities-test/expected-ns-entity-events-spec .yaml" )
613606 require .NoError (t , err )
614607
615- replaceLogValues ( t , namespaceLogs [ 0 ], map [string ]map [string ]string {
616- "otel. entity.attributes " : {
608+ commonReplacements := map [string ]map [string ]string {
609+ "entity.description " : {
617610 "k8s.namespace.creation_timestamp" : "2025-01-01T00:00:00Z" ,
618611 },
619- "otel. entity.id" : {
612+ "entity.id" : {
620613 "k8s.namespace.uid" : "entity-id" ,
621614 },
615+ }
616+
617+ replaceLogValues (t , namespaceLogs [0 ], commonReplacements )
618+
619+ require .NoError (t , plogtest .CompareLogs (expected , namespaceLogs [0 ],
620+ plogtest .IgnoreTimestamp (),
621+ plogtest .IgnoreObservedTimestamp (),
622+ plogtest .IgnoreScopeLogsOrder (),
623+ plogtest .IgnoreLogRecordsOrder (),
624+ ))
625+
626+ logsConsumer .Reset ()
627+
628+ // Delete test namespace object to trigger terminating phase and check if new event log is generated with the correct phase
629+ require .NoErrorf (t , k8stest .DeleteObjects (k8sClient , namespaceObj ), "failed to delete test k8s objects" )
630+
631+ namespaceLogs = waitForEntityLogs (t , entityType , entityNameKey , entityName , logsConsumer )
632+
633+ replaceLogValues (t , namespaceLogs [0 ], commonReplacements )
634+
635+ // update the phase in expected log to terminating
636+ replaceLogValues (t , expected , map [string ]map [string ]string {
637+ "entity.description" : {
638+ "k8s.namespace.phase" : "terminating" ,
639+ },
622640 })
623641
624642 require .NoError (t , plogtest .CompareLogs (expected , namespaceLogs [0 ],
@@ -629,6 +647,59 @@ func TestE2ENamespaceMetadataLegacy(t *testing.T) {
629647 ))
630648}
631649
650+ // TestE2EPVCEntityWithEntityEventsSpecificationFeatureGate tests PVC entity exporting using the entity events specification.
651+ func TestE2EPVCEntityWithEntityEventsSpecificationFeatureGate (t * testing.T ) {
652+ k8sClient , err := k8stest .NewK8sClient (testKubeConfig )
653+ require .NoError (t , err )
654+
655+ logsConsumer := new (consumertest.LogsSink )
656+ shutdownSink := startUpSink (t , logsConsumer )
657+ defer shutdownSink ()
658+
659+ testID := uuid .NewString ()[:8 ]
660+ collectorObjs := k8stest .CreateCollectorObjects (t , k8sClient , testID , filepath .Join ("." , "testdata" , "e2e" , "entities-test" , "collector" ), map [string ]string {
661+ "FeatureGates" : entityEventsSpecificationFeatureGate ,
662+ }, "" )
663+
664+ t .Cleanup (func () {
665+ for _ , obj := range collectorObjs {
666+ require .NoErrorf (t , k8stest .DeleteObject (k8sClient , obj ), "failed to delete object %s" , obj .GetName ())
667+ }
668+ })
669+
670+ pvcObjs , err := k8stest .CreateObjects (k8sClient , filepath .Join ("." , "testdata" , "e2e" , "entities-test" , "testobjects-pvc" ))
671+ require .NoErrorf (t , err , "failed to create PVC test objects" )
672+ t .Cleanup (func () {
673+ require .NoErrorf (t , k8stest .DeleteObjects (k8sClient , pvcObjs ), "failed to delete PVC test objects" )
674+ })
675+
676+ entityType := "k8s.persistentvolumeclaim"
677+ entityNameKey := "k8s.persistentvolumeclaim.name"
678+ entityName := "test-entities-pvc"
679+ pvcLogs := waitForEntityLogs (t , entityType , entityNameKey , entityName , logsConsumer )
680+
681+ expected , err := golden .ReadLogs ("./testdata/e2e/entities-test/expected-pvc-entity-events-spec.yaml" )
682+ require .NoError (t , err )
683+
684+ commonReplacements := map [string ]map [string ]string {
685+ "entity.description" : {
686+ "k8s.persistentvolumeclaim.creation_timestamp" : "2025-01-01T00:00:00Z" ,
687+ },
688+ "entity.id" : {
689+ "k8s.persistentvolumeclaim.uid" : "entity-id" ,
690+ },
691+ }
692+
693+ replaceLogValues (t , pvcLogs [0 ], commonReplacements )
694+
695+ require .NoError (t , plogtest .CompareLogs (expected , pvcLogs [0 ],
696+ plogtest .IgnoreTimestamp (),
697+ plogtest .IgnoreObservedTimestamp (),
698+ plogtest .IgnoreScopeLogsOrder (),
699+ plogtest .IgnoreLogRecordsOrder (),
700+ ))
701+ }
702+
632703// filterEntityLogs returns logs that contain the entity with the given entityType and entityNameKey and entityName.
633704func filterEntityLogs (logs []plog.Logs , entityType , entityNameKey , entityName string ) []plog.Logs {
634705 var entityLogs []plog.Logs
0 commit comments