Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(metrics): Add metrics for size of applyCh and proposal size. #7069

Merged
merged 2 commits into from
Dec 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions worker/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,7 @@ func (n *node) InitAndStartNode() {
go n.processTabletSizes()
go n.processApplyCh()
go n.BatchAndSendMessages()
go n.monitorRaftMetrics()
// Ignoring the error since InitAndStartNode does not return an error and using x.Check would
// not be the right thing to do.
_, _ = n.startTask(opRollup)
Expand All @@ -1725,3 +1726,13 @@ func (n *node) AmLeader() bool {
r := n.Raft()
return r.Status().Lead == r.Status().ID
}

func (n *node) monitorRaftMetrics() {
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for range ticker.C {
curPendingSize := atomic.LoadInt64(&n.pendingSize)
ostats.Record(n.ctx, x.RaftPendingSize.M(curPendingSize))
ostats.Record(n.ctx, x.RaftApplyCh.M(int64(len(n.applyCh))))
}
}
18 changes: 18 additions & 0 deletions x/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ var (
// RaftAppliedIndex records the latest applied RAFT index.
RaftAppliedIndex = stats.Int64("raft_applied_index",
"Latest applied Raft index", stats.UnitDimensionless)
RaftApplyCh = stats.Int64("raft_applych_size",
"Number of proposals in Raft apply channel", stats.UnitDimensionless)
RaftPendingSize = stats.Int64("pending_proposal_bytes",
"Size of Raft pending proposal", stats.UnitBytes)
// MaxAssignedTs records the latest max assigned timestamp.
MaxAssignedTs = stats.Int64("max_assigned_ts",
"Latest max assigned timestamp", stats.UnitDimensionless)
Expand Down Expand Up @@ -165,6 +169,20 @@ var (
Aggregation: view.LastValue(),
TagKeys: allTagKeys,
},
{
Name: RaftApplyCh.Name(),
Measure: RaftApplyCh,
Description: RaftApplyCh.Description(),
Aggregation: view.LastValue(),
TagKeys: allTagKeys,
},
{
Name: RaftPendingSize.Name(),
Measure: RaftPendingSize,
Description: RaftPendingSize.Description(),
Aggregation: view.LastValue(),
TagKeys: allTagKeys,
},
{
Name: MaxAssignedTs.Name(),
Measure: MaxAssignedTs,
Expand Down