cloud/bmaas/bmdb: implement BMDB client metrics
This implements some basic BMDB metrics exported by any client code
using the BMDB.
It also enables their use in the Shepherd and BMSRV.
Change-Id: I1d5e82fd2c34a7bfd42f37fad540d69f7b23f347
Reviewed-on: https://review.monogon.dev/c/monogon/+/1600
Tested-by: Jenkins CI
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
diff --git a/cloud/bmaas/bmdb/bmdb.go b/cloud/bmaas/bmdb/bmdb.go
index 5699381..242c3d9 100644
--- a/cloud/bmaas/bmdb/bmdb.go
+++ b/cloud/bmaas/bmdb/bmdb.go
@@ -7,7 +7,12 @@
// service over gRPC.
package bmdb
-import "source.monogon.dev/cloud/lib/component"
+import (
+ "github.com/prometheus/client_golang/prometheus"
+
+ "source.monogon.dev/cloud/bmaas/bmdb/metrics"
+ "source.monogon.dev/cloud/lib/component"
+)
// BMDB is the Bare Metal Database, a common schema to store information about
// bare metal machines in CockroachDB. This struct is supposed to be
@@ -30,6 +35,8 @@
// machines with some active work being performed on them.
type BMDB struct {
Config
+
+ metrics *metrics.MetricsSet
}
// Config is the configuration of the BMDB connector.
@@ -44,3 +51,11 @@
// ComponentName in active Sessions.
RuntimeInfo string
}
+
+// EnableMetrics configures BMDB metrics collection and registers it on the given
+// registry. This method should only be called once, and is not goroutine safe.
+func (b *BMDB) EnableMetrics(registry *prometheus.Registry) {
+ if b.metrics == nil {
+ b.metrics = metrics.New(registry)
+ }
+}