Skip to content

Commit 14dbae3

Browse files
committed
Expose instance AZ in ring via Prometheus metric
1 parent 45f043f commit 14dbae3

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## master / unreleased
44

55
* [FEATURE] Ruler: Add `external_labels` option to tag all alerts with a given set of labels.
6+
* [ENHANCEMENT] Ring: Add `cortex_ring_availability_zone` metric to display which availability zone an instance is configured to run in. #4681
67

78
## 1.12.0 in pgoress
89

pkg/ring/basic_lifecycler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func NewBasicLifecycler(cfg BasicLifecyclerConfig, ringName, ringKey string, sto
9292
logger: logger,
9393
store: store,
9494
delegate: delegate,
95-
metrics: NewBasicLifecyclerMetrics(ringName, reg),
95+
metrics: NewBasicLifecyclerMetrics(ringName, cfg.Zone, reg),
9696
actorChan: make(chan func()),
9797
}
9898

pkg/ring/basic_lifecycler_metrics.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ type BasicLifecyclerMetrics struct {
99
heartbeats prometheus.Counter
1010
tokensOwned prometheus.Gauge
1111
tokensToOwn prometheus.Gauge
12+
zoneInfo prometheus.GaugeVec
1213
}
1314

14-
func NewBasicLifecyclerMetrics(ringName string, reg prometheus.Registerer) *BasicLifecyclerMetrics {
15+
func NewBasicLifecyclerMetrics(ringName string, zone string, reg prometheus.Registerer) *BasicLifecyclerMetrics {
16+
zoneInfo := promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
17+
Name: "ring_availability_zone",
18+
Help: "The availability zone of the instance",
19+
}, []string{"az"})
20+
zoneInfo.WithLabelValues(zone).Set(1)
21+
1522
return &BasicLifecyclerMetrics{
1623
heartbeats: promauto.With(reg).NewCounter(prometheus.CounterOpts{
1724
Name: "ring_member_heartbeats_total",
@@ -28,5 +35,6 @@ func NewBasicLifecyclerMetrics(ringName string, reg prometheus.Registerer) *Basi
2835
Help: "The number of tokens to own in the ring.",
2936
ConstLabels: prometheus.Labels{"name": ringName},
3037
}),
38+
zoneInfo: *zoneInfo,
3139
}
3240
}

0 commit comments

Comments
 (0)