From 5eb6d7436b21df13067614e39411a45798e11a67 Mon Sep 17 00:00:00 2001 From: phanipadala Date: Mon, 13 Sep 2021 15:13:50 -0700 Subject: [PATCH 1/3] update alert object with additiobnal information field Signed-off-by: phanipadala --- pkg/wavefront/conversion.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/wavefront/conversion.go b/pkg/wavefront/conversion.go index cb1dbf6..29c439f 100644 --- a/pkg/wavefront/conversion.go +++ b/pkg/wavefront/conversion.go @@ -19,6 +19,7 @@ func ConvertAlertCRToWavefrontRequest(ctx context.Context, req v1alpha1.Wavefron alert.AlertType = string(req.AlertType) alert.Tags = req.Tags alert.DisplayExpression = req.DisplayExpression + alert.AdditionalInfo = req.AdditionalInformation if req.Minutes == nil || req.ResolveAfter == nil { err := errors.New("minutes and resolveAfter must be passed") log.Error(err, "error occurred in ConvertAlertCRToWavefrontRequest") From 7266bae421d29460677bfcddd0294d3791215994 Mon Sep 17 00:00:00 2001 From: phanipadala Date: Fri, 15 Oct 2021 07:37:35 -0700 Subject: [PATCH 2/3] initialize retryCount value to address issue 39 Signed-off-by: phanipadala --- controllers/alertsconfig_controller.go | 1 + 1 file changed, 1 insertion(+) diff --git a/controllers/alertsconfig_controller.go b/controllers/alertsconfig_controller.go index 5b3e1f2..c18167a 100644 --- a/controllers/alertsconfig_controller.go +++ b/controllers/alertsconfig_controller.go @@ -82,6 +82,7 @@ func (r *AlertsConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request // Get the CR var alertsConfig alertmanagerv1alpha1.AlertsConfig + alertsConfig.Status.RetryCount = 0 if err := r.Get(ctx, req.NamespacedName, &alertsConfig); err != nil { return ctrl.Result{}, client.IgnoreNotFound(err) } From d83c2df65c8324f99459b23b8a4dff868414c472 Mon Sep 17 00:00:00 2001 From: phanipadala Date: Mon, 18 Oct 2021 12:28:40 -0700 Subject: [PATCH 3/3] update patch with retryCount Signed-off-by: phanipadala --- controllers/alertsconfig_controller.go | 1 - controllers/common/common.go | 6 ++++-- go.mod | 2 +- go.sum | 2 ++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/controllers/alertsconfig_controller.go b/controllers/alertsconfig_controller.go index c18167a..5b3e1f2 100644 --- a/controllers/alertsconfig_controller.go +++ b/controllers/alertsconfig_controller.go @@ -82,7 +82,6 @@ func (r *AlertsConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request // Get the CR var alertsConfig alertmanagerv1alpha1.AlertsConfig - alertsConfig.Status.RetryCount = 0 if err := r.Get(ctx, req.NamespacedName, &alertsConfig); err != nil { return ctrl.Result{}, client.IgnoreNotFound(err) } diff --git a/controllers/common/common.go b/controllers/common/common.go index bd3c7c6..17a05fc 100644 --- a/controllers/common/common.go +++ b/controllers/common/common.go @@ -209,13 +209,15 @@ func (r *Client) PatchWfAlertAndAlertsConfigStatus( log = log.WithValues("wfAlertCR", wfAlert.Name, "alertsConfigCR", alertsConfig.Name) alertStatus.LastUpdatedTimestamp = metav1.Now() alertStatusBytes, _ := json.Marshal(alertStatus) - patch := []byte(fmt.Sprintf("{\"status\":{\"state\": \"%s\", \"alertsStatus\":{\"%s\":%s}}}", state, wfAlert.Name, string(alertStatusBytes))) + retryCount := alertsConfig.Status.RetryCount + patch := []byte(fmt.Sprintf("{\"status\":{\"state\": \"%s\", \"retryCount\": %d, \"alertsStatus\":{\"%s\":%s}}}", state, retryCount, wfAlert.Name, string(alertStatusBytes))) _, err := r.PatchStatus(ctx, alertsConfig, client.RawPatch(types.MergePatchType, patch), state, requeueTime...) if err != nil { log.Error(err, "unable to patch the status for alerts config object") return err } - wfAlertStatusPatch := []byte(fmt.Sprintf("{\"status\":{\"state\": \"%s\",\"alertsStatus\":{\"%s\":%s}}}", state, alertsConfig.Name, string(alertStatusBytes))) + wfRetryCount := wfAlert.Status.RetryCount + wfAlertStatusPatch := []byte(fmt.Sprintf("{\"status\":{\"state\": \"%s\", \"retryCount\": %d,\"alertsStatus\":{\"%s\":%s}}}", state, wfRetryCount, alertsConfig.Name, string(alertStatusBytes))) if err != nil { log.Error(err, "unable to patch the status for wavefront alert object") return err diff --git a/go.mod b/go.mod index 75fbb6e..ac315d7 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/onsi/ginkgo v1.16.4 github.com/onsi/gomega v1.16.0 golang.org/x/mod v0.5.1 // indirect - golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect + golang.org/x/sys v0.0.0-20211015200801-69063c4bb744 // indirect //golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect golang.org/x/tools v0.1.7 // indirect k8s.io/api v0.19.2 diff --git a/go.sum b/go.sum index 109ce39..a264450 100644 --- a/go.sum +++ b/go.sum @@ -609,6 +609,8 @@ golang.org/x/sys v0.0.0-20211004093028-2c5d950f24ef h1:fPxZ3Umkct3LZ8gK9nbk+DWDJ golang.org/x/sys v0.0.0-20211004093028-2c5d950f24ef/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac h1:oN6lz7iLW/YC7un8pq+9bOLyXrprv2+DKfkJY+2LJJw= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211015200801-69063c4bb744 h1:KzbpndAYEM+4oHRp9JmB2ewj0NHHxO3Z0g7Gus2O1kk= +golang.org/x/sys v0.0.0-20211015200801-69063c4bb744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=