@@ -9,12 +9,10 @@ import (
99
1010 "github.com/stretchr/testify/assert"
1111 "github.com/stretchr/testify/require"
12- "go.opentelemetry.io/collector/featuregate"
1312 "k8s.io/apimachinery/pkg/selection"
1413
1514 "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"
1615 "github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/kube"
17- "github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/metadata"
1816)
1917
2018func TestWithAPIConfig (t * testing.T ) {
@@ -584,7 +582,7 @@ func Test_extractFieldRules(t *testing.T) {
584582 }},
585583 want : []kube.FieldExtractionRule {
586584 {
587- Name : "k8s.pod.labels.key" ,
585+ Name : "" , // Name is empty for dynamic resolution based on feature gates
588586 Key : "key" ,
589587 From : kube .MetadataFromPod ,
590588 },
@@ -641,86 +639,57 @@ func Test_extractFieldRules(t *testing.T) {
641639
642640func Test_extractFieldRules_FeatureGate (t * testing.T ) {
643641 tests := []struct {
644- name string
645- fieldType string
646- fields []FieldExtractConfig
647- featureGateValue bool
648- wantNamePattern string
642+ name string
643+ fieldType string
644+ fields []FieldExtractConfig
645+ wantNamePattern string
649646 }{
650647 {
651- name : "labels plural when feature gate disabled " ,
648+ name : "labels without custom tag_name leaves Name empty for dynamic resolution " ,
652649 fieldType : "labels" ,
653650 fields : []FieldExtractConfig {
654651 {
655652 Key : "app" ,
656653 From : kube .MetadataFromPod ,
657654 },
658655 },
659- featureGateValue : false ,
660- wantNamePattern : "k8s.pod.labels.app" ,
656+ wantNamePattern : "" ,
661657 },
662658 {
663- name : "labels singular when feature gate enabled" ,
664- fieldType : "labels" ,
665- fields : []FieldExtractConfig {
666- {
667- Key : "app" ,
668- From : kube .MetadataFromPod ,
669- },
670- },
671- featureGateValue : true ,
672- wantNamePattern : "k8s.pod.label.app" ,
673- },
674- {
675- name : "annotations plural when feature gate disabled" ,
659+ name : "annotations without custom tag_name leaves Name empty for dynamic resolution" ,
676660 fieldType : "annotations" ,
677661 fields : []FieldExtractConfig {
678662 {
679663 Key : "workload" ,
680664 From : kube .MetadataFromPod ,
681665 },
682666 },
683- featureGateValue : false ,
684- wantNamePattern : "k8s.pod.annotations.workload" ,
667+ wantNamePattern : "" ,
685668 },
686669 {
687- name : "annotations singular when feature gate enabled" ,
688- fieldType : "annotations" ,
689- fields : []FieldExtractConfig {
690- {
691- Key : "workload" ,
692- From : kube .MetadataFromPod ,
693- },
694- },
695- featureGateValue : true ,
696- wantNamePattern : "k8s.pod.annotation.workload" ,
697- },
698- {
699- name : "namespace labels singular when feature gate enabled" ,
670+ name : "namespace labels without custom tag_name leaves Name empty" ,
700671 fieldType : "labels" ,
701672 fields : []FieldExtractConfig {
702673 {
703674 Key : "env" ,
704675 From : kube .MetadataFromNamespace ,
705676 },
706677 },
707- featureGateValue : true ,
708- wantNamePattern : "k8s.namespace.label.env" ,
678+ wantNamePattern : "" ,
709679 },
710680 {
711- name : "node annotations singular when feature gate enabled " ,
681+ name : "node annotations without custom tag_name leaves Name empty " ,
712682 fieldType : "annotations" ,
713683 fields : []FieldExtractConfig {
714684 {
715685 Key : "zone" ,
716686 From : kube .MetadataFromNode ,
717687 },
718688 },
719- featureGateValue : true ,
720- wantNamePattern : "k8s.node.annotation.zone" ,
689+ wantNamePattern : "" ,
721690 },
722691 {
723- name : "explicit tag name not affected by feature gate " ,
692+ name : "explicit tag name preserved regardless of feature gates " ,
724693 fieldType : "labels" ,
725694 fields : []FieldExtractConfig {
726695 {
@@ -729,24 +698,12 @@ func Test_extractFieldRules_FeatureGate(t *testing.T) {
729698 From : kube .MetadataFromPod ,
730699 },
731700 },
732- featureGateValue : true ,
733- wantNamePattern : "custom.tag.name" ,
701+ wantNamePattern : "custom.tag.name" ,
734702 },
735703 }
736704
737705 for _ , tt := range tests {
738706 t .Run (tt .name , func (t * testing.T ) {
739- // Set feature gate state for stable and legacy attributes
740- if tt .featureGateValue {
741- require .NoError (t , featuregate .GlobalRegistry ().Set (metadata .ProcessorK8sattributesEmitV1K8sConventionsFeatureGate .ID (), true ))
742- require .NoError (t , featuregate .GlobalRegistry ().Set (metadata .ProcessorK8sattributesDontEmitV0K8sConventionsFeatureGate .ID (), true ))
743- }
744- defer func () {
745- // Reset to default
746- require .NoError (t , featuregate .GlobalRegistry ().Set (metadata .ProcessorK8sattributesEmitV1K8sConventionsFeatureGate .ID (), false ))
747- require .NoError (t , featuregate .GlobalRegistry ().Set (metadata .ProcessorK8sattributesDontEmitV0K8sConventionsFeatureGate .ID (), false ))
748- }()
749-
750707 got , err := extractFieldRules (tt .fieldType , tt .fields ... )
751708 require .NoError (t , err )
752709 require .Len (t , got , 1 )
0 commit comments