Skip to content

Commit

Permalink
feat: initialize reconciler metrics when controller is started
Browse files Browse the repository at this point in the history
  • Loading branch information
joelanford committed Jan 8, 2021
1 parent 66537ca commit fc11162
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/internal/controller/controller.go
Expand Up @@ -143,6 +143,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

Expand Down Expand Up @@ -202,7 +204,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.
Expand Down Expand Up @@ -248,6 +249,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()
Expand Down

0 comments on commit fc11162

Please sign in to comment.