Skip to content

Commit

Permalink
add metrics for reconciles machine time
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Dudas authored and lukas016 committed Sep 23, 2024
1 parent a9a273e commit b8bc0cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions internal/controllers/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,15 @@ func (r *MachineReconciler) processNextWorkItem(ctx context.Context, log logr.Lo
log = log.WithValues("machineID", id)
ctx = logr.NewContext(ctx, log)

start := time.Now()
defer func() {
metrics.OpsTime.Observe(float64(time.Now().Sub(start).Milliseconds()) / 1000)
}()

if err := r.reconcileMachine(ctx, id); err != nil {
log.Error(err, "failed to reconcile machine")
r.queue.AddRateLimited(item)
metrics.OpsFailed.Inc()

return true
}
Expand Down
12 changes: 6 additions & 6 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ const (
)

var (
OpsProcessed = prometheus.NewCounter(prometheus.CounterOpts{
Name: "reconcile_total_number_loops_counter",
Help: "The total number of processed events",
})

OpsFailed = prometheus.NewCounter(prometheus.CounterOpts{
Name: "reconcile_total_number_failed_loops_counter",
Help: "How many errors happened during run time of loop",
})

OpsTime = prometheus.NewSummary(prometheus.SummaryOpts{
Name: "reconcile_total_duration_sec",
Help: "How long it took for method to run",
})

depth = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Subsystem: WorkQueueSubsystem,
Name: DepthKey,
Expand Down Expand Up @@ -81,7 +81,7 @@ var (

func init() {
prometheus.MustRegister(OpsFailed)
prometheus.MustRegister(OpsProcessed)
prometheus.MustRegister(OpsTime)
prometheus.MustRegister(depth)
prometheus.MustRegister(adds)
prometheus.MustRegister(latency)
Expand Down

0 comments on commit b8bc0cc

Please sign in to comment.