@@ -62,6 +62,16 @@ var rawGroupWithReplicaSet = definition.RawGroups{
6262 "replicaset" : "kube-state-metrics-4044341274" ,
6363 },
6464 },
65+ "kube_replicaset_owner" : prometheus.Metric {
66+ Value : prometheus .GaugeValue (1 ),
67+ Labels : map [string ]string {
68+ "namespace" : "kube-system" ,
69+ "replicaset" : "kube-state-metrics-4044341274" ,
70+ "owner_kind" : "Deployment" ,
71+ "owner_name" : "kube-state-metrics" ,
72+ "owner_is_controller" : "true" ,
73+ },
74+ },
6575 },
6676 },
6777}
@@ -73,22 +83,98 @@ func TestGetDeploymentNameForReplicaSet_ValidName(t *testing.T) {
7383 assert .Equal (t , expectedValue , fetchedValue )
7484}
7585
76- func TestGetDeploymentNameForReplicaSet_ErrorOnEmptyData (t * testing.T ) {
86+ func TestGetDeploymentNameForReplicaSet_ErrorOnNonDeploymentOwnerKind (t * testing.T ) {
87+ t .Parallel ()
88+ raw := definition.RawGroups {
89+ "replicaset" : {
90+ "kube-state-metrics-4044341274" : definition.RawMetrics {
91+ "kube_replicaset_owner" : prometheus.Metric {
92+ Value : prometheus .GaugeValue (1 ),
93+ Labels : map [string ]string {
94+ "namespace" : "kube-system" ,
95+ "replicaset" : "kube-state-metrics-4044341274" ,
96+ "owner_kind" : "Rollout" , // like argo rollout
97+ "owner_name" : "rollout-jf9sdja" ,
98+ "owner_is_controller" : "true" ,
99+ },
100+ },
101+ },
102+ },
103+ }
104+ fetchedValue , err := GetDeploymentNameForReplicaSet ()("replicaset" , "kube-state-metrics-4044341274" , raw )
105+ assert .EqualError (t , err , "owner_kind of ReplicaSet is not " + deploymentOwnerKind )
106+ assert .Empty (t , fetchedValue )
107+ }
108+
109+ func TestGetDeploymentNameForReplicaSet_ErrorOnEmptyOwnerName (t * testing.T ) {
110+ t .Parallel ()
111+ raw := definition.RawGroups {
112+ "replicaset" : {
113+ "kube-state-metrics-4044341274" : definition.RawMetrics {
114+ "kube_replicaset_owner" : prometheus.Metric {
115+ Value : prometheus .GaugeValue (1 ),
116+ Labels : map [string ]string {
117+ "namespace" : "kube-system" ,
118+ "replicaset" : "kube-state-metrics-4044341274" ,
119+ "owner_kind" : "Deployment" ,
120+ "owner_name" : "" ,
121+ "owner_is_controller" : "true" ,
122+ },
123+ },
124+ },
125+ },
126+ }
127+ fetchedValue , err := GetDeploymentNameForReplicaSet ()("replicaset" , "kube-state-metrics-4044341274" , raw )
128+ assert .EqualError (t , err , "owner_name of ReplicaSet is empty" )
129+ assert .Empty (t , fetchedValue )
130+ }
131+
132+ func TestGetDeploymentNameForReplicaSet_ErrorOnMissingOwnerMetric (t * testing.T ) {
133+ t .Parallel ()
77134 raw := definition.RawGroups {
78135 "replicaset" : {
79136 "kube-state-metrics-4044341274" : definition.RawMetrics {
80137 "kube_replicaset_created" : prometheus.Metric {
81- Value : prometheus .GaugeValue (1507117436 ),
138+ Value : prometheus .GaugeValue (1 ),
139+ Labels : map [string ]string {
140+ "namespace" : "kube-system" ,
141+ "replicaset" : "kube-state-metrics-4044341274" ,
142+ },
143+ },
144+ },
145+ },
146+ }
147+ fetchedValue , err := GetDeploymentNameForReplicaSet ()("replicaset" , "kube-state-metrics-4044341274" , raw )
148+ assert .EqualError (t , err , "failed to fetch owner_kind of ReplicaSet: metric \" kube_replicaset_owner\" not found" )
149+ assert .Empty (t , fetchedValue )
150+ }
151+
152+ func TestGetDeploymentNameForReplicaSet_ErrorOnMissingOwnerNameMetric (t * testing.T ) {
153+ t .Parallel ()
154+ raw := definition.RawGroups {
155+ "replicaset" : {
156+ "kube-state-metrics-4044341274" : definition.RawMetrics {
157+ "kube_replicaset_created" : prometheus.Metric {
158+ Value : prometheus .GaugeValue (1 ),
159+ Labels : map [string ]string {
160+ "namespace" : "kube-system" ,
161+ "replicaset" : "kube-state-metrics-4044341274" ,
162+ },
163+ },
164+ "kube_replicaset_owner" : prometheus.Metric {
165+ Value : prometheus .GaugeValue (1 ),
82166 Labels : map [string ]string {
83167 "namespace" : "kube-system" ,
84- "replicaset" : "" ,
168+ "replicaset" : "kube-state-metrics-4044341274" ,
169+ "owner_kind" : "Deployment" ,
170+ // unexpected: this metric should have owner_name but it's missing
85171 },
86172 },
87173 },
88174 },
89175 }
90176 fetchedValue , err := GetDeploymentNameForReplicaSet ()("replicaset" , "kube-state-metrics-4044341274" , raw )
91- assert .EqualError (t , err , "error generating deployment name for replica set. replicaset field is empty " )
177+ assert .EqualError (t , err , "failed to fetch owner_name of ReplicaSet: label \" owner_name \" not found on metric \" kube_replicaset_owner \" : label not found on metric " )
92178 assert .Empty (t , fetchedValue )
93179}
94180
0 commit comments