From 7b33feab75439ebd8f646ab51aa9d1b69aef8b8e Mon Sep 17 00:00:00 2001 From: Joe Lanford Date: Fri, 8 Jan 2021 13:00:41 -0500 Subject: [PATCH] feat: initialize reconciler metrics when controller is started --- pkg/internal/controller/controller.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/internal/controller/controller.go b/pkg/internal/controller/controller.go index 113b6ff91b..2a7b43838d 100644 --- a/pkg/internal/controller/controller.go +++ b/pkg/internal/controller/controller.go @@ -139,6 +139,8 @@ func (c *Controller) Start(ctx context.Context) error { return errors.New("controller was started more than once. This is likely to be caused by being added to a manager multiple times") } + c.initMetrics() + // Set the internal context. c.ctx = ctx @@ -190,7 +192,6 @@ func (c *Controller) Start(ctx context.Context) error { // Launch workers to process resources c.Log.Info("Starting workers", "worker count", c.MaxConcurrentReconciles) - ctrlmetrics.WorkerCount.WithLabelValues(c.Name).Set(float64(c.MaxConcurrentReconciles)) for i := 0; i < c.MaxConcurrentReconciles; i++ { go wait.UntilWithContext(ctx, func(ctx context.Context) { // Run a worker thread that just dequeues items, processes them, and marks them done. @@ -236,6 +237,16 @@ func (c *Controller) processNextWorkItem(ctx context.Context) bool { return true } +func (c *Controller) initMetrics() { + ctrlmetrics.ActiveWorkers.WithLabelValues(c.Name).Set(0) + ctrlmetrics.ReconcileErrors.WithLabelValues(c.Name).Add(0) + ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, "error").Add(0) + ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, "requeue_after").Add(0) + ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, "requeue").Add(0) + ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, "success").Add(0) + ctrlmetrics.WorkerCount.WithLabelValues(c.Name).Set(float64(c.MaxConcurrentReconciles)) +} + func (c *Controller) reconcileHandler(ctx context.Context, obj interface{}) { // Update metrics after processing each item reconcileStartTS := time.Now()