Skip to content

Commit 271ac93

Browse files
authored
tso fallback add metrics (tikv#431)
* add metrics Signed-off-by: ystaticy <y_static_y@sina.com> * add metrics Signed-off-by: ystaticy <y_static_y@sina.com> --------- Signed-off-by: ystaticy <y_static_y@sina.com>
1 parent 3658afe commit 271ac93

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

pkg/tso/keyspace_group_manager.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,17 @@ func (s *state) getKeyspaceGroupMetaWithCheck(
316316
// Before fallback to default group, check if the keyspace has configured a group in its metadata.
317317
// If it has, don't fallback to avoid incorrect switching when state is inconsistent (e.g., after split).
318318
if kgm != nil && checkKeyspaceHasConfiguredGroup(kgm.legacySvcStorage, keyspaceID) {
319-
log.Info("[tso] keyspace has configured group but not found in lookup table, skip fallback to default group",
319+
kgm.metrics.keyspaceFallbackRejectedCounter.Inc()
320+
log.Debug("[tso] keyspace has configured group but not found in lookup table, skip fallback to default group",
320321
zap.Uint32("keyspace-id", keyspaceID),
321322
zap.Uint32("requested-group-id", keyspaceGroupID))
322323
return nil, nil, keyspaceGroupID, errs.ErrKeyspaceNotAssigned.FastGenByArgs(keyspaceID)
323324
}
324-
// Legacy keyspace without group configuration, fallback to default group.
325-
log.Info("[tso] keyspace not found in any group, fallback to default group for legacy keyspace",
325+
// The keyspace without group configuration, fallback to default group.
326+
if kgm != nil {
327+
kgm.metrics.keyspaceFallbackToDefaultCounter.Inc()
328+
}
329+
log.Debug("[tso] keyspace not found in any group, fallback to default group for legacy keyspace",
326330
zap.Uint32("keyspace-id", keyspaceID),
327331
zap.Uint32("requested-group-id", keyspaceGroupID))
328332
return s.ams[constant.DefaultKeyspaceGroupID],

pkg/tso/metrics.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ var (
8484
Help: "Bucketed histogram of processing time(s) of the Keyspace Group operations.",
8585
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 13),
8686
}, []string{typeLabel})
87+
88+
keyspaceFallbackCounter = prometheus.NewCounterVec(
89+
prometheus.CounterOpts{
90+
Namespace: tsoNamespace,
91+
Subsystem: "keyspace",
92+
Name: "fallback_events",
93+
Help: "Counter of keyspace fallback events",
94+
}, []string{typeLabel})
8795
)
8896

8997
func init() {
@@ -94,6 +102,7 @@ func init() {
94102
prometheus.MustRegister(tsoAllocatorRole)
95103
prometheus.MustRegister(keyspaceGroupStateGauge)
96104
prometheus.MustRegister(keyspaceGroupOpDuration)
105+
prometheus.MustRegister(keyspaceFallbackCounter)
97106
}
98107

99108
type tsoMetrics struct {
@@ -179,6 +188,9 @@ type keyspaceGroupMetrics struct {
179188
finishSplitDuration prometheus.Observer
180189
finishMergeSendDuration prometheus.Observer
181190
finishMergeDuration prometheus.Observer
191+
192+
keyspaceFallbackRejectedCounter prometheus.Counter
193+
keyspaceFallbackToDefaultCounter prometheus.Counter
182194
}
183195

184196
func newKeyspaceGroupMetrics() *keyspaceGroupMetrics {
@@ -193,5 +205,8 @@ func newKeyspaceGroupMetrics() *keyspaceGroupMetrics {
193205
finishSplitDuration: keyspaceGroupOpDuration.WithLabelValues("finish-split"),
194206
finishMergeSendDuration: keyspaceGroupOpDuration.WithLabelValues("finish-merge-send"),
195207
finishMergeDuration: keyspaceGroupOpDuration.WithLabelValues("finish-merge"),
208+
209+
keyspaceFallbackRejectedCounter: keyspaceFallbackCounter.WithLabelValues("rejected"),
210+
keyspaceFallbackToDefaultCounter: keyspaceFallbackCounter.WithLabelValues("to_default"),
196211
}
197212
}

0 commit comments

Comments
 (0)