refactor code to utilize return fast to make code more readable
@@ -184,10 +184,17 @@ func (this *kubeletMetricsSource) decodeMetrics(c *cadvisor.ContainerInfo) (stri
}
}
- if c.Spec.HasCustomMetrics {
+ if !c.Spec.HasCustomMetrics {
+ return metricSetKey, cMetrics
+ }
+
metricloop:
for _, spec := range c.Spec.CustomMetrics {
- if cmValue, ok := c.Stats[0].CustomMetrics[spec.Name]; ok && cmValue != nil && len(cmValue) >= 1 {
+ cmValue, ok := c.Stats[0].CustomMetrics[spec.Name]
+ if !ok || cmValue == nil || len(cmValue) == 0 {
+ continue metricloop
+ }
+
newest := cmValue[0]
for _, metricVal := range cmValue {
if newest.Timestamp.Before(metricVal.Timestamp) {
@@ -219,8 +226,6 @@ func (this *kubeletMetricsSource) decodeMetrics(c *cadvisor.ContainerInfo) (stri
cMetrics.MetricValues[CustomMetricPrefix+spec.Name] = mv
}
- }
- }
return metricSetKey, cMetrics
}
