From 10d84ff8b063d560dea63d77a67faad8ba4908e3 Mon Sep 17 00:00:00 2001 From: Sergio Rua Date: Sat, 10 Jun 2023 21:19:38 +0100 Subject: [PATCH] More metrics and rules --- charts/vals-operator/Chart.yaml | 4 ++-- .../templates/prometheusrules.yaml | 18 ++++++++++++++++++ controllers/dbsecret_controller.go | 3 +++ controllers/valssecret_controller.go | 1 + 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/charts/vals-operator/Chart.yaml b/charts/vals-operator/Chart.yaml index 3ce5d81..fa59847 100644 --- a/charts/vals-operator/Chart.yaml +++ b/charts/vals-operator/Chart.yaml @@ -7,10 +7,10 @@ kubeVersion: ">= 1.19.0-0" type: application # Chart version -version: 0.7.5-beta1 +version: 0.7.5-beta2 # Latest container tag -appVersion: "v0.7.5-beta1" +appVersion: "v0.7.5-beta2" maintainers: - email: info@digitalis.io diff --git a/charts/vals-operator/templates/prometheusrules.yaml b/charts/vals-operator/templates/prometheusrules.yaml index 2f010c5..2494341 100644 --- a/charts/vals-operator/templates/prometheusrules.yaml +++ b/charts/vals-operator/templates/prometheusrules.yaml @@ -28,6 +28,24 @@ spec: {{- toYaml . | nindent 12 }} {{- end }} {{- end }} + - alert: ValsOperatorDbSecretExpired + expr: time() > vals_operator_dbsecret_expire_time + for: 30m + labels: + severity: warning + {{- if .Values.prometheusRules.additionalRuleLabels }} + {{- with .Values.prometheusRules.additionalRuleLabels }} + {{- toYaml . | nindent 12 }} + {{- end }} + {{- end }} + annotations: + summary: vals-operator database secret expired + description: "Vals operator database credentials for {{`{{`}}$labels.secret{{`}}`}} in namespace {{`{{`}}$labels.namespace{{`}}`}} expired" + {{- if .Values.prometheusRules.additionalRuleAnnotations }} + {{- with .Values.prometheusRules.additionalRuleAnnotations }} + {{- toYaml . | nindent 12 }} + {{- end }} + {{- end }} {{- end }} - alert: ValsOperatorSecretError expr: vals_operator_secret_error > time() - 300 diff --git a/controllers/dbsecret_controller.go b/controllers/dbsecret_controller.go index fa0afaf..801d5d0 100644 --- a/controllers/dbsecret_controller.go +++ b/controllers/dbsecret_controller.go @@ -126,6 +126,9 @@ func (r *DbSecretReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c if err := r.Update(context.Background(), &dbSecret); err != nil { return ctrl.Result{}, err } + /* mark as deleted in prom */ + dmetrics.DbSecretExpireTime.WithLabelValues(dbSecret.Name, dbSecret.Namespace).Set(0) + dmetrics.DbSecretInfo.WithLabelValues(dbSecret.Name, dbSecret.Namespace).Set(0) } // Stop reconciliation as the item is being deleted diff --git a/controllers/valssecret_controller.go b/controllers/valssecret_controller.go index 27a003b..db9fb15 100644 --- a/controllers/valssecret_controller.go +++ b/controllers/valssecret_controller.go @@ -121,6 +121,7 @@ func (r *ValsSecretReconciler) Reconcile(ctx context.Context, req ctrl.Request) // Stop reconciliation as the item is being deleted r.Log.Info(fmt.Sprintf("Secret %s deleted", secret.Name)) + dmetrics.SecretInfo.WithLabelValues(secret.Name, secret.Namespace).Set(0) return ctrl.Result{}, nil } //! [finalizer]