@@ -143,6 +143,8 @@ func (c *Controller) Start(ctx context.Context) error {
143
143
return errors .New ("controller was started more than once. This is likely to be caused by being added to a manager multiple times" )
144
144
}
145
145
146
+ c .initMetrics ()
147
+
146
148
// Set the internal context.
147
149
c .ctx = ctx
148
150
@@ -202,7 +204,6 @@ func (c *Controller) Start(ctx context.Context) error {
202
204
203
205
// Launch workers to process resources
204
206
c .Log .Info ("Starting workers" , "worker count" , c .MaxConcurrentReconciles )
205
- ctrlmetrics .WorkerCount .WithLabelValues (c .Name ).Set (float64 (c .MaxConcurrentReconciles ))
206
207
for i := 0 ; i < c .MaxConcurrentReconciles ; i ++ {
207
208
go wait .UntilWithContext (ctx , func (ctx context.Context ) {
208
209
// 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 {
248
249
return true
249
250
}
250
251
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
+
251
262
func (c * Controller ) reconcileHandler (ctx context.Context , obj interface {}) {
252
263
// Update metrics after processing each item
253
264
reconcileStartTS := time .Now ()
0 commit comments