@@ -131,48 +131,41 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
131131 ms := make ([]* metric.Metric , 0 , len (a .Spec .Metrics ))
132132 for _ , m := range a .Spec .Metrics {
133133 var metricName string
134-
134+ var metricTarget autoscaling. MetricTarget
135135 // The variable maps the type of metric to the corresponding value
136136 metricMap := make (map [metricTargetType ]float64 )
137137
138138 switch m .Type {
139139 case autoscaling .ObjectMetricSourceType :
140140 metricName = m .Object .Metric .Name
141-
142- if m .Object .Target .Value != nil {
143- metricMap [value ] = float64 (m .Object .Target .Value .MilliValue ()) / 1000
144- }
145- if m .Object .Target .AverageValue != nil {
146- metricMap [average ] = float64 (m .Object .Target .AverageValue .MilliValue ()) / 1000
147- }
141+ metricTarget = m .Object .Target
148142 case autoscaling .PodsMetricSourceType :
149143 metricName = m .Pods .Metric .Name
150-
151- metricMap [average ] = float64 (m .Pods .Target .AverageValue .MilliValue ()) / 1000
144+ metricTarget = m .Pods .Target
152145 case autoscaling .ResourceMetricSourceType :
153146 metricName = string (m .Resource .Name )
154-
155- if m .Resource .Target .AverageUtilization != nil {
156- metricMap [utilization ] = float64 (* m .Resource .Target .AverageUtilization )
157- }
158-
159- if m .Resource .Target .AverageValue != nil {
160- metricMap [average ] = float64 (m .Resource .Target .AverageValue .MilliValue ()) / 1000
161- }
147+ metricTarget = m .Resource .Target
148+ case autoscaling .ContainerResourceMetricSourceType :
149+ metricName = string (m .ContainerResource .Name )
150+ metricTarget = m .ContainerResource .Target
162151 case autoscaling .ExternalMetricSourceType :
163152 metricName = m .External .Metric .Name
164-
165- if m .External .Target .Value != nil {
166- metricMap [value ] = float64 (m .External .Target .Value .MilliValue ()) / 1000
167- }
168- if m .External .Target .AverageValue != nil {
169- metricMap [average ] = float64 (m .External .Target .AverageValue .MilliValue ()) / 1000
170- }
153+ metricTarget = m .External .Target
171154 default :
172155 // Skip unsupported metric type
173156 continue
174157 }
175158
159+ if metricTarget .Value != nil {
160+ metricMap [value ] = float64 (metricTarget .Value .MilliValue ()) / 1000
161+ }
162+ if metricTarget .AverageValue != nil {
163+ metricMap [average ] = float64 (metricTarget .AverageValue .MilliValue ()) / 1000
164+ }
165+ if metricTarget .AverageUtilization != nil {
166+ metricMap [utilization ] = float64 (* metricTarget .AverageUtilization )
167+ }
168+
176169 for metricTypeIndex , metricValue := range metricMap {
177170 ms = append (ms , & metric.Metric {
178171 LabelKeys : targetMetricLabels ,
@@ -193,48 +186,41 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
193186 ms := make ([]* metric.Metric , 0 , len (a .Status .CurrentMetrics ))
194187 for _ , m := range a .Status .CurrentMetrics {
195188 var metricName string
196-
189+ var currentMetric autoscaling. MetricValueStatus
197190 // The variable maps the type of metric to the corresponding value
198191 metricMap := make (map [metricTargetType ]float64 )
199192
200193 switch m .Type {
201194 case autoscaling .ObjectMetricSourceType :
202195 metricName = m .Object .Metric .Name
203-
204- if m .Object .Current .Value != nil {
205- metricMap [value ] = float64 (m .Object .Current .Value .MilliValue ()) / 1000
206- }
207- if m .Object .Current .AverageValue != nil {
208- metricMap [average ] = float64 (m .Object .Current .AverageValue .MilliValue ()) / 1000
209- }
196+ currentMetric = m .Object .Current
210197 case autoscaling .PodsMetricSourceType :
211198 metricName = m .Pods .Metric .Name
212-
213- metricMap [average ] = float64 (m .Pods .Current .AverageValue .MilliValue ()) / 1000
199+ currentMetric = m .Pods .Current
214200 case autoscaling .ResourceMetricSourceType :
215201 metricName = string (m .Resource .Name )
216-
217- if m .Resource .Current .AverageUtilization != nil {
218- metricMap [utilization ] = float64 (* m .Resource .Current .AverageUtilization )
219- }
220-
221- if m .Resource .Current .AverageValue != nil {
222- metricMap [average ] = float64 (m .Resource .Current .AverageValue .MilliValue ()) / 1000
223- }
202+ currentMetric = m .Resource .Current
203+ case autoscaling .ContainerResourceMetricSourceType :
204+ metricName = string (m .ContainerResource .Name )
205+ currentMetric = m .ContainerResource .Current
224206 case autoscaling .ExternalMetricSourceType :
225207 metricName = m .External .Metric .Name
226-
227- if m .External .Current .Value != nil {
228- metricMap [value ] = float64 (m .External .Current .Value .MilliValue ()) / 1000
229- }
230- if m .External .Current .AverageValue != nil {
231- metricMap [average ] = float64 (m .External .Current .AverageValue .MilliValue ()) / 1000
232- }
208+ currentMetric = m .External .Current
233209 default :
234210 // Skip unsupported metric type
235211 continue
236212 }
237213
214+ if currentMetric .Value != nil {
215+ metricMap [value ] = float64 (currentMetric .Value .MilliValue ()) / 1000
216+ }
217+ if currentMetric .AverageValue != nil {
218+ metricMap [average ] = float64 (currentMetric .AverageValue .MilliValue ()) / 1000
219+ }
220+ if currentMetric .AverageUtilization != nil {
221+ metricMap [utilization ] = float64 (* currentMetric .AverageUtilization )
222+ }
223+
238224 for metricTypeIndex , metricValue := range metricMap {
239225 ms = append (ms , & metric.Metric {
240226 LabelKeys : targetMetricLabels ,
0 commit comments