Skip to content

Commit 9c173e2

Browse files
OTL-4372 Fix CI checks
Assisted-by: GPT-5 Codex
1 parent d0b893a commit 9c173e2

10 files changed

Lines changed: 165 additions & 65 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
change_type: enhancement
2+
component: pkg/experimentalmetricmetadata
3+
note: Add feature-gated support for emitting entity events using the OpenTelemetry entity events specification log record format.
4+
issues: [49140]
5+
change_logs: [user]

pkg/experimentalmetricmetadata/generated_package_test.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/k8sclusterreceiver/e2e_test.go

Lines changed: 94 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
633704
func filterEntityLogs(logs []plog.Logs, entityType, entityNameKey, entityName string) []plog.Logs {
634705
var entityLogs []plog.Logs

receiver/k8sclusterreceiver/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ require (
2626
go.opentelemetry.io/collector/confmap/xconfmap v0.154.1-0.20260622163853-d3d6e34700b7
2727
go.opentelemetry.io/collector/consumer v1.60.1-0.20260622163853-d3d6e34700b7
2828
go.opentelemetry.io/collector/consumer/consumertest v0.154.1-0.20260622163853-d3d6e34700b7
29+
go.opentelemetry.io/collector/featuregate v1.60.1-0.20260622163853-d3d6e34700b7
2930
go.opentelemetry.io/collector/filter v0.154.1-0.20260622163853-d3d6e34700b7
3031
go.opentelemetry.io/collector/pdata v1.60.1-0.20260622163853-d3d6e34700b7
3132
go.opentelemetry.io/collector/pdata/xpdata v0.154.1-0.20260622163853-d3d6e34700b7
@@ -116,7 +117,6 @@ require (
116117
go.opentelemetry.io/collector/extension v1.60.1-0.20260622163853-d3d6e34700b7 // indirect
117118
go.opentelemetry.io/collector/extension/extensionauth v1.60.1-0.20260622163853-d3d6e34700b7 // indirect
118119
go.opentelemetry.io/collector/extension/extensionmiddleware v0.154.1-0.20260622163853-d3d6e34700b7 // indirect
119-
go.opentelemetry.io/collector/featuregate v1.60.1-0.20260622163853-d3d6e34700b7 // indirect
120120
go.opentelemetry.io/collector/internal/componentalias v0.154.1-0.20260622163853-d3d6e34700b7 // indirect
121121
go.opentelemetry.io/collector/internal/sharedcomponent v0.154.1-0.20260622163853-d3d6e34700b7 // indirect
122122
go.opentelemetry.io/collector/internal/telemetry v0.154.1-0.20260622163853-d3d6e34700b7 // indirect

receiver/k8sclusterreceiver/testdata/e2e/entities-test/expected-ns-legacy.yaml renamed to receiver/k8sclusterreceiver/testdata/e2e/entities-test/expected-ns-entity-events-spec.yaml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,29 @@ resourceLogs:
77
boolValue: true
88
logRecords:
99
- timeUnixNano: "1738160303151735394"
10+
eventName: entity.state
1011
body: {}
1112
attributes:
12-
- key: otel.entity.id
13+
- key: entity.id
1314
value:
1415
kvlistValue:
1516
values:
1617
- key: k8s.namespace.uid
1718
value:
1819
stringValue: entity-id
19-
- key: otel.entity.event.type
20-
value:
21-
stringValue: entity_state
22-
- key: otel.entity.type
20+
- key: entity.type
2321
value:
2422
stringValue: k8s.namespace
25-
- key: otel.entity.interval
23+
- key: entity.report.interval
2624
value:
27-
intValue: "300000"
28-
- key: otel.entity.attributes
25+
intValue: "300"
26+
- key: entity.description
2927
value:
3028
kvlistValue:
3129
values:
3230
- key: k8s.namespace.name
3331
value:
34-
stringValue: test-entities-ns-legacy
32+
stringValue: test-entities-ns
3533
- key: k8s.namespace.phase
3634
value:
3735
stringValue: active

receiver/k8sclusterreceiver/testdata/e2e/entities-test/expected-ns.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,25 @@ resourceLogs:
77
boolValue: true
88
logRecords:
99
- timeUnixNano: "1738160303151735394"
10-
eventName: entity.state
1110
body: {}
1211
attributes:
13-
- key: entity.id
12+
- key: otel.entity.id
1413
value:
1514
kvlistValue:
1615
values:
1716
- key: k8s.namespace.uid
1817
value:
1918
stringValue: entity-id
20-
- key: entity.type
19+
- key: otel.entity.event.type
20+
value:
21+
stringValue: entity_state
22+
- key: otel.entity.type
2123
value:
2224
stringValue: k8s.namespace
23-
- key: entity.report.interval
25+
- key: otel.entity.interval
2426
value:
25-
intValue: "300"
26-
- key: entity.description
27+
intValue: "300000"
28+
- key: otel.entity.attributes
2729
value:
2830
kvlistValue:
2931
values:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
resourceLogs:
2+
- scopeLogs:
3+
- scope:
4+
attributes:
5+
- key: otel.entity.event_as_log
6+
value:
7+
boolValue: true
8+
logRecords:
9+
- timeUnixNano: "1738160303151735394"
10+
eventName: entity.state
11+
body: {}
12+
attributes:
13+
- key: entity.id
14+
value:
15+
kvlistValue:
16+
values:
17+
- key: k8s.persistentvolumeclaim.uid
18+
value:
19+
stringValue: entity-id
20+
- key: entity.type
21+
value:
22+
stringValue: k8s.persistentvolumeclaim
23+
- key: entity.report.interval
24+
value:
25+
intValue: "300"
26+
- key: entity.description
27+
value:
28+
kvlistValue:
29+
values:
30+
- key: k8s.persistentvolumeclaim.name
31+
value:
32+
stringValue: test-entities-pvc
33+
- key: k8s.namespace.name
34+
value:
35+
stringValue: default
36+
- key: k8s.persistentvolumeclaim.creation_timestamp
37+
value:
38+
stringValue: "2025-01-01T00:00:00Z"
39+
traceId: ""
40+
spanId: ""

receiver/k8sclusterreceiver/testdata/e2e/entities-test/expected-pvc.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,25 @@ resourceLogs:
77
boolValue: true
88
logRecords:
99
- timeUnixNano: "1738160303151735394"
10-
eventName: entity.state
1110
body: {}
1211
attributes:
13-
- key: entity.id
12+
- key: otel.entity.id
1413
value:
1514
kvlistValue:
1615
values:
1716
- key: k8s.persistentvolumeclaim.uid
1817
value:
1918
stringValue: entity-id
20-
- key: entity.type
19+
- key: otel.entity.event.type
20+
value:
21+
stringValue: entity_state
22+
- key: otel.entity.type
2123
value:
2224
stringValue: k8s.persistentvolumeclaim
23-
- key: entity.report.interval
25+
- key: otel.entity.interval
2426
value:
25-
intValue: "300"
26-
- key: entity.description
27+
intValue: "300000"
28+
- key: otel.entity.attributes
2729
value:
2830
kvlistValue:
2931
values:

receiver/k8sclusterreceiver/testdata/e2e/entities-test/testobjects-legacy/1-test-ns.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)