Skip to content

Commit

Permalink
metrics: add StaleRegionFromPDCounter (#1530)
Browse files Browse the repository at this point in the history
ref tikv/pd#7431

Signed-off-by: okJiang <[email protected]>
  • Loading branch information
okJiang authored Dec 19, 2024
1 parent 8e0275c commit 2572ee4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/locate/region_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,7 @@ func (mu *regionIndexMu) insertRegionToCache(cachedRegion *Region, invalidateOld
// and there is the synchronization time between the pd follower and the leader.
// So we should check the epoch.
if ok && (oldVer.GetVer() > newVer.GetVer() || oldVer.GetConfVer() > newVer.GetConfVer()) {
metrics.TiKVStaleRegionFromPDCounter.Inc()
logutil.BgLogger().Debug("get stale region",
zap.Uint64("region", newVer.GetID()), zap.Uint64("new-ver", newVer.GetVer()), zap.Uint64("new-conf", newVer.GetConfVer()),
zap.Uint64("old-ver", oldVer.GetVer()), zap.Uint64("old-conf", oldVer.GetConfVer()))
Expand Down
2 changes: 2 additions & 0 deletions internal/locate/sorted_btree.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (

"github.com/google/btree"
"github.com/tikv/client-go/v2/internal/logutil"
"github.com/tikv/client-go/v2/metrics"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -112,6 +113,7 @@ func (s *SortedRegions) removeIntersecting(r *Region, verID RegionVerID) ([]*btr
return false
}
if item.cachedRegion.meta.GetRegionEpoch().GetVersion() > verID.ver {
metrics.TiKVStaleRegionFromPDCounter.Inc()
logutil.BgLogger().Debug("get stale region",
zap.Uint64("region", verID.GetID()), zap.Uint64("ver", verID.GetVer()), zap.Uint64("conf", verID.GetConfVer()),
zap.Uint64("intersecting-ver", item.cachedRegion.meta.GetRegionEpoch().GetVersion()))
Expand Down
10 changes: 10 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ var (
TiKVPipelinedFlushDuration prometheus.Histogram
TiKVValidateReadTSFromPDCount prometheus.Counter
TiKVLowResolutionTSOUpdateIntervalSecondsGauge prometheus.Gauge
TiKVStaleRegionFromPDCounter prometheus.Counter
)

// Label constants.
Expand Down Expand Up @@ -852,6 +853,14 @@ func initMetrics(namespace, subsystem string, constLabels prometheus.Labels) {
Help: "The actual working update interval for the low resolution TSO. As there are adaptive mechanism internally, this value may differ from the config.",
})

TiKVStaleRegionFromPDCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "stale_region_from_pd",
Help: "Counter of stale region from PD",
})

initShortcuts()
}

Expand Down Expand Up @@ -948,6 +957,7 @@ func RegisterMetrics() {
prometheus.MustRegister(TiKVPipelinedFlushDuration)
prometheus.MustRegister(TiKVValidateReadTSFromPDCount)
prometheus.MustRegister(TiKVLowResolutionTSOUpdateIntervalSecondsGauge)
prometheus.MustRegister(TiKVStaleRegionFromPDCounter)
}

// readCounter reads the value of a prometheus.Counter.
Expand Down

0 comments on commit 2572ee4

Please sign in to comment.