From 433197bf2b2d04e49b1bab67984d84eda0f828cc Mon Sep 17 00:00:00 2001 From: hc-github-team-secure-vault-core <82990506+hc-github-team-secure-vault-core@users.noreply.github.com> Date: Thu, 15 Jun 2023 11:53:16 -0400 Subject: [PATCH] backport of commit 6b87a087afe24e8bd52a2b9ada4b506b20d4fc7e (#21254) Co-authored-by: Nick Cabatoff --- changelog/21249.txt | 3 +++ physical/raft/raft.go | 15 ++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 changelog/21249.txt diff --git a/changelog/21249.txt b/changelog/21249.txt new file mode 100644 index 000000000..a088677ad --- /dev/null +++ b/changelog/21249.txt @@ -0,0 +1,3 @@ +```release-note:bug +core: Fix panic in sealed nodes using raft storage trying to emit raft metrics +``` diff --git a/physical/raft/raft.go b/physical/raft/raft.go index 1060eda7a..fa98b4e6f 100644 --- a/physical/raft/raft.go +++ b/physical/raft/raft.go @@ -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,10 +640,12 @@ func (b *RaftBackend) CollectMetrics(sink *metricsutil.ClusterMetricSink) { Value: b.localID, }, } - 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) + 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) + } } } }