@@ -135,48 +135,41 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
135135 ms := make ([]* metric.Metric , 0 , len (a .Spec .Metrics ))
136136 for _ , m := range a .Spec .Metrics {
137137 var metricName string
138-
138+ var metricTarget autoscaling. MetricTarget
139139 // The variable maps the type of metric to the corresponding value
140140 metricMap := make (map [metricTargetType ]float64 )
141141
142142 switch m .Type {
143143 case autoscaling .ObjectMetricSourceType :
144144 metricName = m .Object .Metric .Name
145-
146- if m .Object .Target .Value != nil {
147- metricMap [value ] = float64 (m .Object .Target .Value .MilliValue ()) / 1000
148- }
149- if m .Object .Target .AverageValue != nil {
150- metricMap [average ] = float64 (m .Object .Target .AverageValue .MilliValue ()) / 1000
151- }
145+ metricTarget = m .Object .Target
152146 case autoscaling .PodsMetricSourceType :
153147 metricName = m .Pods .Metric .Name
154-
155- metricMap [average ] = float64 (m .Pods .Target .AverageValue .MilliValue ()) / 1000
148+ metricTarget = m .Pods .Target
156149 case autoscaling .ResourceMetricSourceType :
157150 metricName = string (m .Resource .Name )
158-
159- if m .Resource .Target .AverageUtilization != nil {
160- metricMap [utilization ] = float64 (* m .Resource .Target .AverageUtilization )
161- }
162-
163- if m .Resource .Target .AverageValue != nil {
164- metricMap [average ] = float64 (m .Resource .Target .AverageValue .MilliValue ()) / 1000
165- }
151+ metricTarget = m .Resource .Target
152+ case autoscaling .ContainerResourceMetricSourceType :
153+ metricName = string (m .ContainerResource .Name )
154+ metricTarget = m .ContainerResource .Target
166155 case autoscaling .ExternalMetricSourceType :
167156 metricName = m .External .Metric .Name
168-
169- if m .External .Target .Value != nil {
170- metricMap [value ] = float64 (m .External .Target .Value .MilliValue ()) / 1000
171- }
172- if m .External .Target .AverageValue != nil {
173- metricMap [average ] = float64 (m .External .Target .AverageValue .MilliValue ()) / 1000
174- }
157+ metricTarget = m .External .Target
175158 default :
176159 // Skip unsupported metric type
177160 continue
178161 }
179162
163+ if metricTarget .Value != nil {
164+ metricMap [value ] = float64 (metricTarget .Value .MilliValue ()) / 1000
165+ }
166+ if metricTarget .AverageValue != nil {
167+ metricMap [average ] = float64 (metricTarget .AverageValue .MilliValue ()) / 1000
168+ }
169+ if metricTarget .AverageUtilization != nil {
170+ metricMap [utilization ] = float64 (* metricTarget .AverageUtilization )
171+ }
172+
180173 for metricTypeIndex , metricValue := range metricMap {
181174 ms = append (ms , & metric.Metric {
182175 LabelKeys : targetMetricLabels ,
@@ -197,48 +190,41 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
197190 ms := make ([]* metric.Metric , 0 , len (a .Status .CurrentMetrics ))
198191 for _ , m := range a .Status .CurrentMetrics {
199192 var metricName string
200-
193+ var currentMetric autoscaling. MetricValueStatus
201194 // The variable maps the type of metric to the corresponding value
202195 metricMap := make (map [metricTargetType ]float64 )
203196
204197 switch m .Type {
205198 case autoscaling .ObjectMetricSourceType :
206199 metricName = m .Object .Metric .Name
207-
208- if m .Object .Current .Value != nil {
209- metricMap [value ] = float64 (m .Object .Current .Value .MilliValue ()) / 1000
210- }
211- if m .Object .Current .AverageValue != nil {
212- metricMap [average ] = float64 (m .Object .Current .AverageValue .MilliValue ()) / 1000
213- }
200+ currentMetric = m .Object .Current
214201 case autoscaling .PodsMetricSourceType :
215202 metricName = m .Pods .Metric .Name
216-
217- metricMap [average ] = float64 (m .Pods .Current .AverageValue .MilliValue ()) / 1000
203+ currentMetric = m .Pods .Current
218204 case autoscaling .ResourceMetricSourceType :
219205 metricName = string (m .Resource .Name )
220-
221- if m .Resource .Current .AverageUtilization != nil {
222- metricMap [utilization ] = float64 (* m .Resource .Current .AverageUtilization )
223- }
224-
225- if m .Resource .Current .AverageValue != nil {
226- metricMap [average ] = float64 (m .Resource .Current .AverageValue .MilliValue ()) / 1000
227- }
206+ currentMetric = m .Resource .Current
207+ case autoscaling .ContainerResourceMetricSourceType :
208+ metricName = string (m .ContainerResource .Name )
209+ currentMetric = m .ContainerResource .Current
228210 case autoscaling .ExternalMetricSourceType :
229211 metricName = m .External .Metric .Name
230-
231- if m .External .Current .Value != nil {
232- metricMap [value ] = float64 (m .External .Current .Value .MilliValue ()) / 1000
233- }
234- if m .External .Current .AverageValue != nil {
235- metricMap [average ] = float64 (m .External .Current .AverageValue .MilliValue ()) / 1000
236- }
212+ currentMetric = m .External .Current
237213 default :
238214 // Skip unsupported metric type
239215 continue
240216 }
241217
218+ if currentMetric .Value != nil {
219+ metricMap [value ] = float64 (currentMetric .Value .MilliValue ()) / 1000
220+ }
221+ if currentMetric .AverageValue != nil {
222+ metricMap [average ] = float64 (currentMetric .AverageValue .MilliValue ()) / 1000
223+ }
224+ if currentMetric .AverageUtilization != nil {
225+ metricMap [utilization ] = float64 (* currentMetric .AverageUtilization )
226+ }
227+
242228 for metricTypeIndex , metricValue := range metricMap {
243229 ms = append (ms , & metric.Metric {
244230 LabelKeys : targetMetricLabels ,
0 commit comments