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

[raft] add some metrics for range lease and leader #8049

Merged
merged 2 commits into from
Dec 13, 2024
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
21 changes: 19 additions & 2 deletions enterprise/server/raft/leasekeeper/leasekeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,13 @@ func (la *leaseAgent) doSingleInstruction(ctx context.Context, instruction *leas
valid := la.l.Valid(ctx)
start := time.Now()

rangeID := la.l.GetRangeDescriptor().GetRangeId()

switch instruction.action {
case Acquire:
err := la.l.Lease(ctx)
metrics.RaftLeaseActionCount.With(prometheus.Labels{
metrics.RaftRangeIDLabel: strconv.Itoa(int(la.l.GetRangeDescriptor().GetRangeId())),
metrics.RaftRangeIDLabel: strconv.Itoa(int(rangeID)),
metrics.RaftLeaseActionLabel: "Acquire",
metrics.StatusHumanReadableLabel: status.MetricsLabel(err),
}).Inc()
Expand All @@ -172,12 +174,15 @@ func (la *leaseAgent) doSingleInstruction(ctx context.Context, instruction *leas
if !valid {
la.log.Debugf("Acquired lease [%s] %s after callback (%s)", la.l.Desc(ctx), time.Since(start), instruction)
la.sendRangeEvent(events.EventRangeLeaseAcquired)
metrics.RaftLeases.With(prometheus.Labels{
metrics.RaftRangeIDLabel: strconv.Itoa(int(la.l.GetRangeDescriptor().GetRangeId())),
}).Inc()
}
case Drop:
// This is a no-op if we don't have the lease.
err := la.l.Release(ctx)
metrics.RaftLeaseActionCount.With(prometheus.Labels{
metrics.RaftRangeIDLabel: strconv.Itoa(int(la.l.GetRangeDescriptor().GetRangeId())),
metrics.RaftRangeIDLabel: strconv.Itoa(int(rangeID)),
metrics.RaftLeaseActionLabel: "Drop",
metrics.StatusHumanReadableLabel: status.MetricsLabel(err),
}).Inc()
Expand All @@ -188,6 +193,9 @@ func (la *leaseAgent) doSingleInstruction(ctx context.Context, instruction *leas
if valid {
la.log.Debugf("Dropped lease [%s] %s after callback (%s)", la.l.Desc(ctx), time.Since(start), instruction)
la.sendRangeEvent(events.EventRangeLeaseDropped)
metrics.RaftLeases.With(prometheus.Labels{
metrics.RaftRangeIDLabel: strconv.Itoa(int(rangeID)),
}).Dec()
}
}
}
Expand Down Expand Up @@ -250,6 +258,15 @@ func (lk *LeaseKeeper) watchLeases() {
leader := info.LeaderID == info.ReplicaID && info.Term > 0
rangeID := rangeID(info.ShardID)

rlGauge := metrics.RaftLeaders.With(prometheus.Labels{
metrics.RaftRangeIDLabel: strconv.Itoa(int(rangeID)),
})
if leader {
rlGauge.Inc()
} else {
rlGauge.Dec()
}

lk.mu.Lock()
open := lk.open[rangeID]
lk.leaders[rangeID] = leader
Expand Down
3 changes: 0 additions & 3 deletions enterprise/server/raft/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2613,9 +2613,6 @@ func (s *Store) refreshMetrics(ctx context.Context) {
metrics.DiskCacheFilesystemTotalBytes.With(prometheus.Labels{metrics.CacheNameLabel: constants.CacheName}).Set(float64(fsu.Total))
metrics.DiskCacheFilesystemAvailBytes.With(prometheus.Labels{metrics.CacheNameLabel: constants.CacheName}).Set(float64(fsu.Avail))
}

leaseCount := s.leaseKeeper.LeaseCount(ctx)
metrics.RaftLeases.With(prometheus.Labels{metrics.RaftNodeHostIDLabel: s.nodeHost.ID()}).Set(float64(leaseCount))
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion server/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2260,7 +2260,16 @@ var (
Name: "leases",
Help: "Number of raft leases on each nodehost.",
}, []string{
RaftNodeHostIDLabel,
RaftRangeIDLabel,
})

RaftLeaders = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: bbNamespace,
Subsystem: "raft",
Name: "leaders",
Help: "Number of raft leaders on each nodehost.",
}, []string{
RaftRangeIDLabel,
})

RaftRecords = promauto.NewGaugeVec(prometheus.GaugeOpts{
Expand Down
Loading