Skip to content

Expose instance AZ in ring via Prometheus metric #4681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## master / unreleased

* [FEATURE] Ruler: Add `external_labels` option to tag all alerts with a given set of labels.
* [ENHANCEMENT] Ring: Add `cortex_ring_availability_zone` metric to display which availability zone an instance is configured to run in. #4681
* [CHANGE] Fix incorrectly named `cortex_cache_fetched_keys` and `cortex_cache_hits` metrics. Renamed to `cortex_cache_fetched_keys_total` and `cortex_cache_hits_total` respectively. #4686

## 1.12.0 in progress
Expand Down
2 changes: 1 addition & 1 deletion pkg/ring/basic_lifecycler.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func NewBasicLifecycler(cfg BasicLifecyclerConfig, ringName, ringKey string, sto
logger: logger,
store: store,
delegate: delegate,
metrics: NewBasicLifecyclerMetrics(ringName, reg),
metrics: NewBasicLifecyclerMetrics(ringName, cfg.Zone, reg),
actorChan: make(chan func()),
}

Expand Down
10 changes: 9 additions & 1 deletion pkg/ring/basic_lifecycler_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ type BasicLifecyclerMetrics struct {
heartbeats prometheus.Counter
tokensOwned prometheus.Gauge
tokensToOwn prometheus.Gauge
zoneInfo prometheus.GaugeVec
}

func NewBasicLifecyclerMetrics(ringName string, reg prometheus.Registerer) *BasicLifecyclerMetrics {
func NewBasicLifecyclerMetrics(ringName string, zone string, reg prometheus.Registerer) *BasicLifecyclerMetrics {
zoneInfo := promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
Name: "ring_availability_zone",
Help: "The availability zone of the instance",
}, []string{"az"})
zoneInfo.WithLabelValues(zone).Set(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no zone (i.e. zone is empty string) should we skip on emitting this metric?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I agree


return &BasicLifecyclerMetrics{
heartbeats: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Name: "ring_member_heartbeats_total",
Expand All @@ -28,5 +35,6 @@ func NewBasicLifecyclerMetrics(ringName string, reg prometheus.Registerer) *Basi
Help: "The number of tokens to own in the ring.",
ConstLabels: prometheus.Labels{"name": ringName},
}),
zoneInfo: *zoneInfo,
}
}