Skip to content

Commit

Permalink
kvserver/rangefeed: add UpdateMetricsOnRangefeedDisconnectBy
Browse files Browse the repository at this point in the history
This patch updates RangefeedMetricsRecorder to include
UpdateMetricsOnRangefeedDisconnectBy, which decrements rangefeed metrics by the
given argument. While the benefits remain unclear, future commits will use
this method to clean up metrics during multiple rangefeed disconnects.

Epic: none
Release note: none
  • Loading branch information
wenyihu6 committed Nov 15, 2024
1 parent 9ecb09a commit 6db61ed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion pkg/kv/kvserver/rangefeed/sender_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ func (c *testRangefeedCounter) UpdateMetricsOnRangefeedConnect() {
}

func (c *testRangefeedCounter) UpdateMetricsOnRangefeedDisconnect() {
c.count.Add(-1)
c.UpdateMetricsOnRangefeedDisconnectBy(1)
}

func (c *testRangefeedCounter) UpdateMetricsOnRangefeedDisconnectBy(num int64) {
c.count.Add(int32(-num))
}

func (c *testRangefeedCounter) get() int {
Expand Down
1 change: 1 addition & 0 deletions pkg/kv/kvserver/rangefeed/unbuffered_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
type RangefeedMetricsRecorder interface {
UpdateMetricsOnRangefeedConnect()
UpdateMetricsOnRangefeedDisconnect()
UpdateMetricsOnRangefeedDisconnectBy(num int64)
}

// ServerStreamSender forwards MuxRangefeedEvents from UnbufferedSender to the
Expand Down
12 changes: 9 additions & 3 deletions pkg/server/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,16 @@ func (nm *nodeMetrics) UpdateMetricsOnRangefeedConnect() {
nm.ActiveMuxRangeFeed.Inc(1)
}

// UpdateOnRangefeedDisconnect decrements rangefeed metrics when a server
// rangefeed is disconnected.
// UpdateMetricsOnRangefeedDisconnect decrements rangefeed metrics when one
// server rangefeed is disconnected.
func (nm *nodeMetrics) UpdateMetricsOnRangefeedDisconnect() {
nm.ActiveMuxRangeFeed.Dec(1)
nm.UpdateMetricsOnRangefeedDisconnectBy(1)
}

// UpdateMetricsOnRangefeedDisconnectBy decrements rangefeed metrics by the
// given num argument when there are multiple rangefeed disconnects.
func (nm *nodeMetrics) UpdateMetricsOnRangefeedDisconnectBy(num int64) {
nm.ActiveMuxRangeFeed.Dec(num)
}

// A Node manages a map of stores (by store ID) for which it serves
Expand Down

0 comments on commit 6db61ed

Please sign in to comment.