diff --git a/internal/controller/metrics.go b/internal/controller/metrics.go new file mode 100644 index 0000000..a3da0e9 --- /dev/null +++ b/internal/controller/metrics.go @@ -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) +} diff --git a/internal/controller/notificationservice_controller.go b/internal/controller/notificationservice_controller.go index a724a26..c576b29 100644 --- a/internal/controller/notificationservice_controller.go +++ b/internal/controller/notificationservice_controller.go @@ -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)