diff --git a/internal/conditions/conditions.go b/internal/conditions/conditions.go index fe859a8717..9ca195eaaf 100644 --- a/internal/conditions/conditions.go +++ b/internal/conditions/conditions.go @@ -77,6 +77,18 @@ func CommonMessageFor(reason string) string { } func FetchReasonFromAlert(alert prometheus.Alerts) string { + if reason, found := alertMap[alert.Name]; found { + //fmt.Printf("PipelineName: %v\n", alert.PipelineInfo) + return reason + } + return "" +} + +func MessageForAlerts(alert prometheus.Alerts) string { + reason := FetchReasonFromAlert(alert) + if reason == "" { + return "" + } if reasonMsg, found := alertMap[alert.Name]; found { fmt.Printf("PipelineName: %v\n", alert.PipelineInfo) return strings.Replace(reasonMsg, "pipelineName", alert.PipelineInfo, 1) diff --git a/internal/reconciler/metricpipeline/status.go b/internal/reconciler/metricpipeline/status.go index c8aa394704..3e2802df0c 100644 --- a/internal/reconciler/metricpipeline/status.go +++ b/internal/reconciler/metricpipeline/status.go @@ -111,10 +111,11 @@ func (r *Reconciler) setMetricFlowHealthCondition(pipeline *telemetryv1alpha1.Me status = metav1.ConditionFalse reason = conditions.FetchReasonFromAlert(alert) } + msg := conditions.MessageForAlerts(alert) - fmt.Printf("Status is: %v, Reason: %v\n", status, reason) + fmt.Printf("Status is: %v, Reason: %v, msg: %v\n", status, reason) - meta.SetStatusCondition(&pipeline.Status.Conditions, newCondition(conditions.TypeMetricFlowHealthy, reason, status, pipeline.Generation)) + meta.SetStatusCondition(&pipeline.Status.Conditions, newConditionForAlerts(conditions.TypeMetricFlowHealthy, reason, status, msg, pipeline.Generation)) } func newCondition(condType, reason string, status metav1.ConditionStatus, generation int64) metav1.Condition { @@ -126,3 +127,13 @@ func newCondition(condType, reason string, status metav1.ConditionStatus, genera ObservedGeneration: generation, } } + +func newConditionForAlerts(condType, reason, msg string, status metav1.ConditionStatus, generation int64) metav1.Condition { + return metav1.Condition{ + Type: condType, + Status: status, + Reason: reason, + Message: msg, + ObservedGeneration: generation, + } +}