Skip to content

Commit fc11162

Browse files
committed
feat: initialize reconciler metrics when controller is started
1 parent 66537ca commit fc11162

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pkg/internal/controller/controller.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ func (c *Controller) Start(ctx context.Context) error {
143143
return errors.New("controller was started more than once. This is likely to be caused by being added to a manager multiple times")
144144
}
145145

146+
c.initMetrics()
147+
146148
// Set the internal context.
147149
c.ctx = ctx
148150

@@ -202,7 +204,6 @@ func (c *Controller) Start(ctx context.Context) error {
202204

203205
// Launch workers to process resources
204206
c.Log.Info("Starting workers", "worker count", c.MaxConcurrentReconciles)
205-
ctrlmetrics.WorkerCount.WithLabelValues(c.Name).Set(float64(c.MaxConcurrentReconciles))
206207
for i := 0; i < c.MaxConcurrentReconciles; i++ {
207208
go wait.UntilWithContext(ctx, func(ctx context.Context) {
208209
// Run a worker thread that just dequeues items, processes them, and marks them done.
@@ -248,6 +249,16 @@ func (c *Controller) processNextWorkItem(ctx context.Context) bool {
248249
return true
249250
}
250251

252+
func (c *Controller) initMetrics() {
253+
ctrlmetrics.ActiveWorkers.WithLabelValues(c.Name).Set(0)
254+
ctrlmetrics.ReconcileErrors.WithLabelValues(c.Name).Add(0)
255+
ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, "error").Add(0)
256+
ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, "requeue_after").Add(0)
257+
ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, "requeue").Add(0)
258+
ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, "success").Add(0)
259+
ctrlmetrics.WorkerCount.WithLabelValues(c.Name).Set(float64(c.MaxConcurrentReconciles))
260+
}
261+
251262
func (c *Controller) reconcileHandler(ctx context.Context, obj interface{}) {
252263
// Update metrics after processing each item
253264
reconcileStartTS := time.Now()

0 commit comments

Comments
 (0)