From 0415d9fb05a21b22eab8c3af314b8ba24e4a57c6 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Thu, 18 Jul 2024 12:24:37 +0200 Subject: [PATCH] feat: Track when builders are doing work with a gauge --- pkg/bloombuild/builder/builder.go | 4 ++++ pkg/bloombuild/builder/metrics.go | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/bloombuild/builder/builder.go b/pkg/bloombuild/builder/builder.go index 982d14388e28..5f2c3b5ab5fd 100644 --- a/pkg/bloombuild/builder/builder.go +++ b/pkg/bloombuild/builder/builder.go @@ -191,6 +191,7 @@ func (b *Builder) builderLoop(c protos.PlannerForBuilder_BuilderLoopClient) erro return fmt.Errorf("failed to receive task from planner: %w", err) } + b.metrics.processingTask.Set(1) b.metrics.taskStarted.Inc() start := time.Now() @@ -212,8 +213,11 @@ func (b *Builder) builderLoop(c protos.PlannerForBuilder_BuilderLoopClient) erro b.logTaskCompleted(task, newMetas, err, start) if err = b.notifyTaskCompletedToPlanner(c, task, newMetas, err); err != nil { + b.metrics.processingTask.Set(0) return fmt.Errorf("failed to notify task completion to planner: %w", err) } + + b.metrics.processingTask.Set(0) } level.Debug(b.logger).Log("msg", "builder loop stopped") diff --git a/pkg/bloombuild/builder/metrics.go b/pkg/bloombuild/builder/metrics.go index f94d92353ee1..8d4545c00bf5 100644 --- a/pkg/bloombuild/builder/metrics.go +++ b/pkg/bloombuild/builder/metrics.go @@ -14,7 +14,8 @@ const ( ) type Metrics struct { - running prometheus.Gauge + running prometheus.Gauge + processingTask prometheus.Gauge taskStarted prometheus.Counter taskCompleted *prometheus.CounterVec @@ -38,6 +39,12 @@ func NewMetrics(r prometheus.Registerer) *Metrics { Name: "running", Help: "Value will be 1 if the bloom builder is currently running on this instance", }), + processingTask: promauto.With(r).NewGauge(prometheus.GaugeOpts{ + Namespace: metricsNamespace, + Subsystem: metricsSubsystem, + Name: "processing_task", + Help: "Value will be 1 if the bloom builder is currently processing a task", + }), taskStarted: promauto.With(r).NewCounter(prometheus.CounterOpts{ Namespace: metricsNamespace,