Skip to content

Commit

Permalink
Fixed active nodes metrics for etcdraft when a node is evicted. Inste…
Browse files Browse the repository at this point in the history
…ad of being frozen we set it to 0 once halt is called. Tests. (#3536)

Signed-off-by: Vladyslav Kopaihorodskyi <vlad.kopaygorodsky@gmail.com>
(cherry picked from commit ba61a1b)
  • Loading branch information
kopaygorodsky authored and denyeart committed Jul 26, 2022
1 parent ce3679d commit eaa807a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions orderer/consensus/etcdraft/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ func (c *Chain) halt() {
// StatusReport.
c.consensusRelation = types.ConsensusRelationConfigTracker
}

// active nodes metric shouldn't be frozen once a channel is stopped.
c.Metrics.ActiveNodes.Set(float64(0))
}

func (c *Chain) isRunning() error {
Expand Down
8 changes: 8 additions & 0 deletions orderer/consensus/etcdraft/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,7 @@ var _ = Describe("Chain", func() {
c1.clock.Increment(interval)
return c2.fakeFields.fakeActiveNodes.SetCallCount()
}, LongEventualTimeout).Should(Equal(2))
Expect(c1.fakeFields.fakeActiveNodes.SetArgsForCall(1)).To(Equal(float64(2)))
Expect(c2.fakeFields.fakeActiveNodes.SetArgsForCall(1)).To(Equal(float64(2)))

By("Configuring cluster to remove node")
Expand Down Expand Up @@ -1459,6 +1460,8 @@ var _ = Describe("Chain", func() {
c2.cutter.CutNext = true
Expect(c2.Order(env, 0)).To(Succeed())
Eventually(c2.support.WriteBlockCallCount, LongEventualTimeout).Should(Equal(1))
Expect(c1.fakeFields.fakeActiveNodes.SetArgsForCall(2)).To(Equal(float64(0))) // was halted
Expect(c2.fakeFields.fakeActiveNodes.SetArgsForCall(1)).To(Equal(float64(2)))
})

It("remove leader by reconfiguring cluster, but Halt before eviction", func() {
Expand All @@ -1469,6 +1472,7 @@ var _ = Describe("Chain", func() {
c1.clock.Increment(interval)
return c2.fakeFields.fakeActiveNodes.SetCallCount()
}, LongEventualTimeout).Should(Equal(2))
Expect(c1.fakeFields.fakeActiveNodes.SetArgsForCall(1)).To(Equal(float64(2)))
Expect(c2.fakeFields.fakeActiveNodes.SetArgsForCall(1)).To(Equal(float64(2)))

By("Configuring cluster to remove node")
Expand Down Expand Up @@ -1499,6 +1503,10 @@ var _ = Describe("Chain", func() {
).Should(Equal(orderer_types.StatusInactive))
cRel, _ := c1.StatusReport()
Expect(cRel).To(Equal(orderer_types.ConsensusRelationConsenter))

// active nodes metric hasn't changed because c.halt() wasn't called
Expect(c1.fakeFields.fakeActiveNodes.SetArgsForCall(1)).To(Equal(float64(2)))
Expect(c2.fakeFields.fakeActiveNodes.SetArgsForCall(1)).To(Equal(float64(2)))
})

It("can remove leader by reconfiguring cluster even if leadership transfer fails", func() {
Expand Down

0 comments on commit eaa807a

Please sign in to comment.