From e86025aa8269edfe7e821b75ff5fe69fff74e386 Mon Sep 17 00:00:00 2001 From: Rakesh Garimella Date: Wed, 31 Jan 2024 11:29:22 +0100 Subject: [PATCH] fix --- internal/conditions/conditions.go | 12 ++++++++++++ internal/reconciler/metricpipeline/status.go | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) 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, + } +}