Skip to content

Commit

Permalink
chore(RHTAPWATCH-1207):Add metrics for total and failed notifications
Browse files Browse the repository at this point in the history
- Add metric for total notifications
- Add metric for total failed notifications

Signed-off-by: Avi Biton <[email protected]>
  • Loading branch information
avi-biton committed Aug 12, 2024
1 parent c76ea89 commit ed65e0a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions internal/controller/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package controller

import (
"github.com/prometheus/client_golang/prometheus"
"sigs.k8s.io/controller-runtime/pkg/metrics"
)

var (
notifications = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "notification_controller_notifications_total",
Help: "Number of total notification actions",
},
)
notificationsFailures = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "notification_controller_notifications_failures_total",
Help: "Number of failed notifications",
},
)
)

func init() {
// Register custom metrics with the global prometheus registry
metrics.Registry.MustRegister(notifications, notificationsFailures)
}
2 changes: 2 additions & 0 deletions internal/controller/notificationservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ func (r *NotificationServiceReconciler) Reconcile(ctx context.Context, req ctrl.
return ctrl.Result{}, err
}
err = r.Notifier.Notify(ctx, string(results))
notifications.Inc()
if err != nil {
logger.Error(err, "Failed to Notify")
notificationsFailures.Inc()
return ctrl.Result{}, err
}
logger.Info("SNS Notified", "pipelinerun", pipelineRun.Name, "namespace", pipelineRun.Namespace)
Expand Down

0 comments on commit ed65e0a

Please sign in to comment.