@@ -11,7 +11,6 @@ import (
11
11
12
12
"github.com/stretchr/testify/assert"
13
13
"github.com/stretchr/testify/require"
14
- "go.opentelemetry.io/collector/featuregate"
15
14
"go.uber.org/zap"
16
15
"go.uber.org/zap/zapcore"
17
16
"go.uber.org/zap/zaptest/observer"
@@ -643,136 +642,6 @@ func TestHandlerWrongType(t *testing.T) {
643
642
}
644
643
}
645
644
646
- func TestRFC3339FeatureGate (t * testing.T ) {
647
- err := featuregate .GlobalRegistry ().Set (enableRFC3339Timestamp .ID (), true )
648
- require .NoError (t , err )
649
-
650
- c , _ := newTestClientWithRulesAndFilters (t , Filters {})
651
- // Disable saving ip into k8s.pod.ip
652
- c .Associations [0 ].Sources [0 ].Name = ""
653
-
654
- pod := & api_v1.Pod {
655
- ObjectMeta : meta_v1.ObjectMeta {
656
- Name : "auth-service-abc12-xyz3" ,
657
- UID : "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" ,
658
- Namespace : "ns1" ,
659
- CreationTimestamp : meta_v1 .Now (),
660
- Labels : map [string ]string {
661
- "label1" : "lv1" ,
662
- "label2" : "k1=v1 k5=v5 extra!" ,
663
- },
664
- Annotations : map [string ]string {
665
- "annotation1" : "av1" ,
666
- },
667
- OwnerReferences : []meta_v1.OwnerReference {
668
- {
669
- APIVersion : "apps/v1" ,
670
- Kind : "ReplicaSet" ,
671
- Name : "auth-service-66f5996c7c" ,
672
- UID : "207ea729-c779-401d-8347-008ecbc137e3" ,
673
- },
674
- {
675
- APIVersion : "apps/v1" ,
676
- Kind : "DaemonSet" ,
677
- Name : "auth-daemonset" ,
678
- UID : "c94d3814-2253-427a-ab13-2cf609e4dafa" ,
679
- },
680
- {
681
- APIVersion : "batch/v1" ,
682
- Kind : "Job" ,
683
- Name : "auth-cronjob-27667920" ,
684
- UID : "59f27ac1-5c71-42e5-abe9-2c499d603706" ,
685
- },
686
- {
687
- APIVersion : "apps/v1" ,
688
- Kind : "StatefulSet" ,
689
- Name : "pi-statefulset" ,
690
- UID : "03755eb1-6175-47d5-afd5-05cfc30244d7" ,
691
- },
692
- },
693
- },
694
- Spec : api_v1.PodSpec {
695
- NodeName : "node1" ,
696
- Hostname : "host1" ,
697
- },
698
- Status : api_v1.PodStatus {
699
- PodIP : "1.1.1.1" ,
700
- },
701
- }
702
-
703
- isController := true
704
- replicaset := & apps_v1.ReplicaSet {
705
- ObjectMeta : meta_v1.ObjectMeta {
706
- Name : "auth-service-66f5996c7c" ,
707
- Namespace : "ns1" ,
708
- UID : "207ea729-c779-401d-8347-008ecbc137e3" ,
709
- OwnerReferences : []meta_v1.OwnerReference {
710
- {
711
- Name : "auth-service" ,
712
- Kind : "Deployment" ,
713
- UID : "ffff-gggg-hhhh-iiii-eeeeeeeeeeee" ,
714
- Controller : & isController ,
715
- },
716
- },
717
- },
718
- }
719
-
720
- rfc3339ts , err := pod .GetCreationTimestamp ().MarshalText ()
721
- require .NoError (t , err )
722
-
723
- testCases := []struct {
724
- name string
725
- rules ExtractionRules
726
- attributes map [string ]string
727
- }{{
728
- name : "metadata" ,
729
- rules : ExtractionRules {
730
- DeploymentName : true ,
731
- DeploymentUID : true ,
732
- Namespace : true ,
733
- PodName : true ,
734
- PodUID : true ,
735
- PodHostName : true ,
736
- Node : true ,
737
- StartTime : true ,
738
- },
739
- attributes : map [string ]string {
740
- "k8s.deployment.name" : "auth-service" ,
741
- "k8s.deployment.uid" : "ffff-gggg-hhhh-iiii-eeeeeeeeeeee" ,
742
- "k8s.namespace.name" : "ns1" ,
743
- "k8s.node.name" : "node1" ,
744
- "k8s.pod.name" : "auth-service-abc12-xyz3" ,
745
- "k8s.pod.hostname" : "host1" ,
746
- "k8s.pod.uid" : "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" ,
747
- "k8s.pod.start_time" : string (rfc3339ts ),
748
- },
749
- },
750
- }
751
- for _ , tc := range testCases {
752
- t .Run (tc .name , func (t * testing.T ) {
753
- c .Rules = tc .rules
754
-
755
- // manually call the data removal functions here
756
- // normally the informer does this, but fully emulating the informer in this test is annoying
757
- transformedPod := removeUnnecessaryPodData (pod , c .Rules )
758
- transformedReplicaset := removeUnnecessaryReplicaSetData (replicaset )
759
- c .handleReplicaSetAdd (transformedReplicaset )
760
- c .handlePodAdd (transformedPod )
761
- p , ok := c .GetPod (newPodIdentifier ("connection" , "" , pod .Status .PodIP ))
762
- require .True (t , ok )
763
-
764
- assert .Equal (t , len (tc .attributes ), len (p .Attributes ))
765
- for k , v := range tc .attributes {
766
- got , ok := p .Attributes [k ]
767
- assert .True (t , ok )
768
- assert .Equal (t , v , got )
769
- }
770
- })
771
- }
772
- err = featuregate .GlobalRegistry ().Set (enableRFC3339Timestamp .ID (), false )
773
- require .NoError (t , err )
774
- }
775
-
776
645
func TestExtractionRules (t * testing.T ) {
777
646
c , _ := newTestClientWithRulesAndFilters (t , Filters {})
778
647
@@ -955,7 +824,11 @@ func TestExtractionRules(t *testing.T) {
955
824
"k8s.pod.name" : "auth-service-abc12-xyz3" ,
956
825
"k8s.pod.hostname" : "host1" ,
957
826
"k8s.pod.uid" : "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" ,
958
- "k8s.pod.start_time" : pod .GetCreationTimestamp ().String (),
827
+ "k8s.pod.start_time" : func () string {
828
+ b , err := pod .GetCreationTimestamp ().MarshalText ()
829
+ require .NoError (t , err )
830
+ return string (b )
831
+ }(),
959
832
},
960
833
}, {
961
834
name : "labels" ,
0 commit comments