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

kvserver: fix replicate queue metrics tracking bug #86844

Merged
merged 1 commit into from
Aug 26, 2022
Merged
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
34 changes: 20 additions & 14 deletions pkg/kv/kvserver/replicate_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func (metrics *ReplicateQueueMetrics) trackRebalanceReplicaCount(
// trackProcessResult increases the corresponding success/error count metric for
// processing a particular allocator action through the replicate queue.
func (metrics *ReplicateQueueMetrics) trackResultByAllocatorAction(
action allocatorimpl.AllocatorAction, err error, dryRun bool,
ctx context.Context, action allocatorimpl.AllocatorAction, err error, dryRun bool,
) {
if dryRun {
return
Expand All @@ -481,6 +481,12 @@ func (metrics *ReplicateQueueMetrics) trackResultByAllocatorAction(
} else {
metrics.ReplaceDeadReplicaErrorCount.Inc(1)
}
case allocatorimpl.AllocatorRemoveDeadVoter, allocatorimpl.AllocatorRemoveDeadNonVoter:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this case be folded into the one right above?

if err == nil {
metrics.RemoveDeadReplicaSuccessCount.Inc(1)
} else {
metrics.RemoveDeadReplicaErrorCount.Inc(1)
}
case allocatorimpl.AllocatorReplaceDecommissioningVoter, allocatorimpl.AllocatorReplaceDecommissioningNonVoter:
if err == nil {
metrics.ReplaceDecommissioningReplicaSuccessCount.Inc(1)
Expand All @@ -494,7 +500,7 @@ func (metrics *ReplicateQueueMetrics) trackResultByAllocatorAction(
metrics.RemoveDecommissioningReplicaErrorCount.Inc(1)
}
default:
panic(fmt.Sprintf("unsupported AllocatorAction: %v", action))
log.Errorf(ctx, "AllocatorAction %v unsupported in metrics tracking", action)
}
}

Expand Down Expand Up @@ -789,23 +795,23 @@ func (rq *replicateQueue) processOneChange(
requeue, err := rq.addOrReplaceVoters(
ctx, repl, liveVoterReplicas, liveNonVoterReplicas, -1 /* removeIdx */, allocatorimpl.Alive, allocatorPrio, dryRun,
)
rq.metrics.trackResultByAllocatorAction(action, err, dryRun)
rq.metrics.trackResultByAllocatorAction(ctx, action, err, dryRun)
return requeue, err
case allocatorimpl.AllocatorAddNonVoter:
requeue, err := rq.addOrReplaceNonVoters(
ctx, repl, liveVoterReplicas, liveNonVoterReplicas, -1 /* removeIdx */, allocatorimpl.Alive, allocatorPrio, dryRun,
)
rq.metrics.trackResultByAllocatorAction(action, err, dryRun)
rq.metrics.trackResultByAllocatorAction(ctx, action, err, dryRun)
return requeue, err

// Remove replicas.
case allocatorimpl.AllocatorRemoveVoter:
requeue, err := rq.removeVoter(ctx, repl, voterReplicas, nonVoterReplicas, dryRun)
rq.metrics.trackResultByAllocatorAction(action, err, dryRun)
rq.metrics.trackResultByAllocatorAction(ctx, action, err, dryRun)
return requeue, err
case allocatorimpl.AllocatorRemoveNonVoter:
requeue, err := rq.removeNonVoter(ctx, repl, voterReplicas, nonVoterReplicas, dryRun)
rq.metrics.trackResultByAllocatorAction(action, err, dryRun)
rq.metrics.trackResultByAllocatorAction(ctx, action, err, dryRun)
return requeue, err

// Replace dead replicas.
Expand All @@ -822,7 +828,7 @@ func (rq *replicateQueue) processOneChange(
}
requeue, err := rq.addOrReplaceVoters(
ctx, repl, liveVoterReplicas, liveNonVoterReplicas, removeIdx, allocatorimpl.Dead, allocatorPrio, dryRun)
rq.metrics.trackResultByAllocatorAction(action, err, dryRun)
rq.metrics.trackResultByAllocatorAction(ctx, action, err, dryRun)
return requeue, err
case allocatorimpl.AllocatorReplaceDeadNonVoter:
if len(deadNonVoterReplicas) == 0 {
Expand All @@ -837,7 +843,7 @@ func (rq *replicateQueue) processOneChange(
}
requeue, err := rq.addOrReplaceNonVoters(
ctx, repl, liveVoterReplicas, liveNonVoterReplicas, removeIdx, allocatorimpl.Dead, allocatorPrio, dryRun)
rq.metrics.trackResultByAllocatorAction(action, err, dryRun)
rq.metrics.trackResultByAllocatorAction(ctx, action, err, dryRun)
return requeue, err

// Replace decommissioning replicas.
Expand All @@ -855,7 +861,7 @@ func (rq *replicateQueue) processOneChange(
}
requeue, err := rq.addOrReplaceVoters(
ctx, repl, liveVoterReplicas, liveNonVoterReplicas, removeIdx, allocatorimpl.Decommissioning, allocatorPrio, dryRun)
rq.metrics.trackResultByAllocatorAction(action, err, dryRun)
rq.metrics.trackResultByAllocatorAction(ctx, action, err, dryRun)
if err != nil {
return requeue, decommissionPurgatoryError{err}
}
Expand All @@ -873,7 +879,7 @@ func (rq *replicateQueue) processOneChange(
}
requeue, err := rq.addOrReplaceNonVoters(
ctx, repl, liveVoterReplicas, liveNonVoterReplicas, removeIdx, allocatorimpl.Decommissioning, allocatorPrio, dryRun)
rq.metrics.trackResultByAllocatorAction(action, err, dryRun)
rq.metrics.trackResultByAllocatorAction(ctx, action, err, dryRun)
if err != nil {
return requeue, decommissionPurgatoryError{err}
}
Expand All @@ -886,14 +892,14 @@ func (rq *replicateQueue) processOneChange(
// AllocatorReplaceDecommissioning{Non}Voter above.
case allocatorimpl.AllocatorRemoveDecommissioningVoter:
requeue, err := rq.removeDecommissioning(ctx, repl, allocatorimpl.VoterTarget, dryRun)
rq.metrics.trackResultByAllocatorAction(action, err, dryRun)
rq.metrics.trackResultByAllocatorAction(ctx, action, err, dryRun)
if err != nil {
return requeue, decommissionPurgatoryError{err}
}
return requeue, nil
case allocatorimpl.AllocatorRemoveDecommissioningNonVoter:
requeue, err := rq.removeDecommissioning(ctx, repl, allocatorimpl.NonVoterTarget, dryRun)
rq.metrics.trackResultByAllocatorAction(action, err, dryRun)
rq.metrics.trackResultByAllocatorAction(ctx, action, err, dryRun)
if err != nil {
return requeue, decommissionPurgatoryError{err}
}
Expand All @@ -906,11 +912,11 @@ func (rq *replicateQueue) processOneChange(
// AllocatorReplaceDead{Non}Voter above.
case allocatorimpl.AllocatorRemoveDeadVoter:
requeue, err := rq.removeDead(ctx, repl, deadVoterReplicas, allocatorimpl.VoterTarget, dryRun)
rq.metrics.trackResultByAllocatorAction(action, err, dryRun)
rq.metrics.trackResultByAllocatorAction(ctx, action, err, dryRun)
return requeue, err
case allocatorimpl.AllocatorRemoveDeadNonVoter:
requeue, err := rq.removeDead(ctx, repl, deadNonVoterReplicas, allocatorimpl.NonVoterTarget, dryRun)
rq.metrics.trackResultByAllocatorAction(action, err, dryRun)
rq.metrics.trackResultByAllocatorAction(ctx, action, err, dryRun)
return requeue, err

case allocatorimpl.AllocatorConsiderRebalance:
Expand Down