@@ -121,54 +121,41 @@ func endpointSliceMetricFamilies(allowAnnotationsList, allowLabelsList []string)
121
121
wrapEndpointSliceFunc (func (e * discoveryv1.EndpointSlice ) * metric.Family {
122
122
m := []* metric.Metric {}
123
123
for _ , ep := range e .Endpoints {
124
- var (
125
- labelKeys ,
126
- labelValues []string
127
- )
124
+
125
+ var ready , serving , terminating , hostname , targetrefKind , targetrefName , targetrefNamespace , endpointNodename , endpointZone string
128
126
129
127
if ep .Conditions .Ready != nil {
130
- labelKeys = append (labelKeys , "ready" )
131
- labelValues = append (labelValues , strconv .FormatBool (* ep .Conditions .Ready ))
128
+ ready = strconv .FormatBool (* ep .Conditions .Ready )
132
129
}
130
+
133
131
if ep .Conditions .Serving != nil {
134
- labelKeys = append (labelKeys , "serving" )
135
- labelValues = append (labelValues , strconv .FormatBool (* ep .Conditions .Serving ))
132
+ serving = strconv .FormatBool (* ep .Conditions .Serving )
136
133
}
134
+
137
135
if ep .Conditions .Terminating != nil {
138
- labelKeys = append (labelKeys , "terminating" )
139
- labelValues = append (labelValues , strconv .FormatBool (* ep .Conditions .Terminating ))
136
+ serving = strconv .FormatBool (* ep .Conditions .Terminating )
140
137
}
141
-
142
138
if ep .Hostname != nil {
143
- labelKeys = append (labelKeys , "hostname" )
144
- labelValues = append (labelValues , * ep .Hostname )
139
+ hostname = * ep .Hostname
145
140
}
146
141
147
142
if ep .TargetRef != nil {
148
- if ep .TargetRef .Kind != "" {
149
- labelKeys = append (labelKeys , "targetref_kind" )
150
- labelValues = append (labelValues , ep .TargetRef .Kind )
151
- }
152
- if ep .TargetRef .Name != "" {
153
- labelKeys = append (labelKeys , "targetref_name" )
154
- labelValues = append (labelValues , ep .TargetRef .Name )
155
- }
156
- if ep .TargetRef .Namespace != "" {
157
- labelKeys = append (labelKeys , "targetref_namespace" )
158
- labelValues = append (labelValues , ep .TargetRef .Namespace )
159
- }
143
+ targetrefKind = ep .TargetRef .Kind
144
+ targetrefName = ep .TargetRef .Name
145
+ targetrefNamespace = ep .TargetRef .Namespace
160
146
}
161
147
162
148
if ep .NodeName != nil {
163
- labelKeys = append (labelKeys , "endpoint_nodename" )
164
- labelValues = append (labelValues , * ep .NodeName )
149
+ endpointNodename = * ep .NodeName
165
150
}
166
151
167
152
if ep .Zone != nil {
168
- labelKeys = append (labelKeys , "endpoint_zone" )
169
- labelValues = append (labelValues , * ep .Zone )
153
+ endpointZone = * ep .Zone
170
154
}
171
- labelKeys = append (labelKeys , "address" )
155
+
156
+ labelKeys := []string {"ready" , "serving" , "hostname" , "terminating" , "targetref_kind" , "targetref_name" , "targetref_namespace" , "endpoint_nodename" , "endpoint_zone" , "address" }
157
+ labelValues := []string {ready , serving , terminating , hostname , targetrefKind , targetrefName , targetrefNamespace , endpointNodename , endpointZone }
158
+
172
159
for _ , address := range ep .Addresses {
173
160
newlabelValues := make ([]string , len (labelValues ))
174
161
copy (newlabelValues , labelValues )
0 commit comments