Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSami Hiltunen <shiltunen@gitlab.com>2020-06-09 16:03:54 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2020-06-09 16:03:54 +0300
commit5c49063cb05152e09e9fcf067b68b6de6a21d561 (patch)
treeeecc098d4df5388550b7f9325c61df77e37691ea
parent6a3f3a4bb4dce6543dfd448ac2c4deb5d36ac9a9 (diff)
parent0d5e6b09284f377c703bd96eb77c735f260b9ab4 (diff)
Merge branch 'smh-read-only-gauge' into 'master'
Export prometheus metric for read-only mode See merge request gitlab-org/gitaly!2224
-rw-r--r--internal/praefect/metrics/prometheus.go8
-rw-r--r--internal/praefect/metrics/util.go11
-rw-r--r--internal/praefect/nodes/local_elector.go2
-rw-r--r--internal/praefect/nodes/sql_elector.go1
4 files changed, 22 insertions, 0 deletions
diff --git a/internal/praefect/metrics/prometheus.go b/internal/praefect/metrics/prometheus.go
index 808fedc1c..7db03bf7b 100644
--- a/internal/praefect/metrics/prometheus.go
+++ b/internal/praefect/metrics/prometheus.go
@@ -105,6 +105,13 @@ var PrimaryGauge = prometheus.NewGaugeVec(
}, []string{"virtual_storage", "gitaly_storage"},
)
+var ReadOnlyGauge = prometheus.NewGaugeVec(
+ prometheus.GaugeOpts{
+ Name: "gitaly_praefect_read_only_mode",
+ Help: "Shows whether a virtual storage is in read-only mode.",
+ }, []string{"virtual_storage"},
+)
+
var NodeLastHealthcheckGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "gitaly",
@@ -136,6 +143,7 @@ func init() {
prometheus.MustRegister(
MethodTypeCounter,
PrimaryGauge,
+ ReadOnlyGauge,
ChecksumMismatchCounter,
NodeLastHealthcheckGauge,
ReadDistribution,
diff --git a/internal/praefect/metrics/util.go b/internal/praefect/metrics/util.go
new file mode 100644
index 000000000..804804454
--- /dev/null
+++ b/internal/praefect/metrics/util.go
@@ -0,0 +1,11 @@
+package metrics
+
+// BoolAsFloat is a utility for converting a boolean value to a float64
+// for Prometheus. Returns 1 if bool is true, else 0.
+func BoolAsFloat(b bool) float64 {
+ if b {
+ return 1
+ }
+
+ return 0
+}
diff --git a/internal/praefect/nodes/local_elector.go b/internal/praefect/nodes/local_elector.go
index d0ddbd0a9..c46491437 100644
--- a/internal/praefect/nodes/local_elector.go
+++ b/internal/praefect/nodes/local_elector.go
@@ -125,6 +125,8 @@ func (s *localElector) checkNodes(ctx context.Context) error {
s.previousWritablePrimary = previousWritablePrimary
s.isReadOnly = s.readOnlyAfterFailover
+ metrics.ReadOnlyGauge.WithLabelValues(s.shardName).Set(metrics.BoolAsFloat(s.isReadOnly))
+
return nil
}
diff --git a/internal/praefect/nodes/sql_elector.go b/internal/praefect/nodes/sql_elector.go
index 2ead9f7d6..38b74bbd2 100644
--- a/internal/praefect/nodes/sql_elector.go
+++ b/internal/praefect/nodes/sql_elector.go
@@ -546,6 +546,7 @@ func (s *sqlElector) lookupPrimary() (*sqlCandidate, bool, Node, error) {
var primaryNode *sqlCandidate
if primaryName != "" {
primaryNode = s.lookupNodeByName(primaryName)
+ metrics.ReadOnlyGauge.WithLabelValues(s.shardName).Set(metrics.BoolAsFloat(readOnly))
}
var prevWritablePrimary Node