File tree 2 files changed +27
-17
lines changed
2 files changed +27
-17
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,16 @@ const (
16
16
Leaving
17
17
)
18
18
19
+ func (s IngesterState ) String () string {
20
+ switch s {
21
+ case Active :
22
+ return "Active"
23
+ case Leaving :
24
+ return "Leaving"
25
+ }
26
+ return ""
27
+ }
28
+
19
29
// Desc is the serialised state in Consul representing
20
30
// all ingesters (ie, the ring).
21
31
type Desc struct {
Original file line number Diff line number Diff line change @@ -14,8 +14,7 @@ import (
14
14
)
15
15
16
16
const (
17
- healthyLabel = "healthy"
18
- unhealthyLabel = "unhealthy"
17
+ unhealthy = "Unhealthy"
19
18
)
20
19
21
20
// Operation can be Read or Write
@@ -242,27 +241,28 @@ func (r *Ring) Collect(ch chan<- prometheus.Metric) {
242
241
)
243
242
}
244
243
245
- healthy , unhealthy := 0 , 0
244
+ // Initialised to zero so we emit zero-metrics (instead of not emitting anything)
245
+ byState := map [string ]int {
246
+ unhealthy : 0 ,
247
+ Active .String (): 0 ,
248
+ Leaving .String (): 0 ,
249
+ }
246
250
for _ , ingester := range r .ringDesc .Ingesters {
247
251
if time .Now ().Sub (ingester .Timestamp ) > r .heartbeatTimeout {
248
- unhealthy ++
252
+ byState [ unhealthy ] ++
249
253
} else {
250
- healthy ++
254
+ byState [ ingester . State . String ()] ++
251
255
}
252
256
}
253
257
254
- ch <- prometheus .MustNewConstMetric (
255
- r .numIngestersDesc ,
256
- prometheus .GaugeValue ,
257
- float64 (healthy ),
258
- healthyLabel ,
259
- )
260
- ch <- prometheus .MustNewConstMetric (
261
- r .numIngestersDesc ,
262
- prometheus .GaugeValue ,
263
- float64 (unhealthy ),
264
- unhealthyLabel ,
265
- )
258
+ for state , count := range byState {
259
+ ch <- prometheus .MustNewConstMetric (
260
+ r .numIngestersDesc ,
261
+ prometheus .GaugeValue ,
262
+ float64 (count ),
263
+ state ,
264
+ )
265
+ }
266
266
ch <- prometheus .MustNewConstMetric (
267
267
r .numTokensDesc ,
268
268
prometheus .GaugeValue ,
You can’t perform that action at this time.
0 commit comments