Fix a panic I observed in a sealed node running CollectMetrics (#21249)

This commit is contained in:
Nick Cabatoff
2023-06-15 11:02:20 -04:00
committed by GitHub
parent fd1f95439d
commit 6b87a087af
2 changed files with 13 additions and 5 deletions

3
changelog/21249.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:bug
core: Fix panic in sealed nodes using raft storage trying to emit raft metrics
```

View File

@@ -624,10 +624,13 @@ func (b *RaftBackend) DisableUpgradeMigration() (bool, bool) {
}
func (b *RaftBackend) CollectMetrics(sink *metricsutil.ClusterMetricSink) {
var stats map[string]string
b.l.RLock()
logstoreStats := b.stableStore.(*raftboltdb.BoltStore).Stats()
fsmStats := b.fsm.Stats()
stats := b.raft.Stats()
if b.raft != nil {
stats = b.raft.Stats()
}
b.l.RUnlock()
b.collectMetricsWithStats(logstoreStats, sink, "logstore")
b.collectMetricsWithStats(fsmStats, sink, "fsm")
@@ -637,12 +640,14 @@ func (b *RaftBackend) CollectMetrics(sink *metricsutil.ClusterMetricSink) {
Value: b.localID,
},
}
if stats != nil {
for _, key := range []string{"term", "commit_index", "applied_index", "fsm_pending"} {
n, err := strconv.ParseUint(stats[key], 10, 64)
if err == nil {
sink.SetGaugeWithLabels([]string{"raft_storage", "stats", key}, float32(n), labels)
}
}
}
}
func (b *RaftBackend) collectMetricsWithStats(stats bolt.Stats, sink *metricsutil.ClusterMetricSink, database string) {