Skip to content

Commit c8e5fce

Browse files
committed
fix func
1 parent a745088 commit c8e5fce

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

internal/orchestrator/metrichandler.go

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,32 +103,33 @@ func (h *MetricHandler) projectionsMonitor(ctx context.Context, list *unstructur
103103
recordErrors = append(recordErrors, fmt.Errorf("projection error for %s: %w", pField.name, pField.error))
104104
}
105105
}
106-
107-
dataPoints = append(dataPoints, dataPoint)
108-
}
109106

110-
// Record all collected data points
111-
errRecord := h.gaugeMetric.RecordMetrics(ctx, dataPoints...)
112-
if errRecord != nil {
113-
recordErrors = append(recordErrors, errRecord)
114-
}
107+
dataPoints = append(dataPoints, dataPoint)
108+
}
115109

116-
// Update result based on errors during projection or recording
117-
if len(recordErrors) > 0 {
118-
// Combine errors for reporting
119-
combinedError := fmt.Errorf("errors during metric recording: %v", recordErrors)
120-
result.Error = combinedError
121-
result.Phase = v1alpha1.PhaseFailed
122-
result.Reason = "RecordMetricFailed"
123-
result.Message = fmt.Sprintf("failed to record metric value(s): %s", combinedError.Error())
124-
} else {
125-
result.Phase = v1alpha1.PhaseActive
126-
result.Reason = v1alpha1.ReasonMonitoringActive
127-
result.Message = fmt.Sprintf("metric values recorded for resource '%s'", h.metric.GvkToString())
128-
// Observation might need adjustment depending on how results should be represented in status
129-
result.Observation = &v1alpha1.MetricObservation{Timestamp: metav1.Now(), LatestValue: strconv.Itoa(len(list.Items))} // Report total count for now
110+
// Record all collected data points
111+
errRecord := h.gaugeMetric.RecordMetrics(ctx, dataPoints...)
112+
if errRecord != nil {
113+
recordErrors = append(recordErrors, errRecord)
114+
}
115+
116+
// Update result based on errors during projection or recording
117+
if len(recordErrors) > 0 {
118+
// Combine errors for reporting
119+
combinedError := fmt.Errorf("errors during metric recording: %v", recordErrors)
120+
result.Error = combinedError
121+
result.Phase = v1alpha1.PhaseFailed
122+
result.Reason = "RecordMetricFailed"
123+
result.Message = fmt.Sprintf("failed to record metric value(s): %s", combinedError.Error())
124+
} else {
125+
result.Phase = v1alpha1.PhaseActive
126+
result.Reason = v1alpha1.ReasonMonitoringActive
127+
result.Message = fmt.Sprintf("metric values recorded for resource '%s'", h.metric.GvkToString())
128+
// Observation might need adjustment depending on how results should be represented in status
129+
result.Observation = &v1alpha1.MetricObservation{Timestamp: metav1.Now(), LatestValue: strconv.Itoa(len(list.Items))} // Report total count for now
130+
}
131+
// Return the result, error indicates failure in Monitor execution, not necessarily metric export failure (handled by controller)
130132
}
131-
// Return the result, error indicates failure in Monitor execution, not necessarily metric export failure (handled by controller)
132133
return result, nil
133134
}
134135

0 commit comments

Comments
 (0)