diff --git a/metrics/metrics.go b/metrics/metrics.go index 53a404aee9b88..f1ead074c3711 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -74,6 +74,7 @@ func RegisterMetrics() { prometheus.MustRegister(GetTokenDurationHistogram) prometheus.MustRegister(HandShakeErrorCounter) prometheus.MustRegister(HandleJobHistogram) + prometheus.MustRegister(SignificantFeedbackCounter) prometheus.MustRegister(JobsGauge) prometheus.MustRegister(KeepAliveCounter) prometheus.MustRegister(LoadPrivilegeCounter) diff --git a/metrics/stats.go b/metrics/stats.go index 3095fef556d3d..8ce15590b8655 100644 --- a/metrics/stats.go +++ b/metrics/stats.go @@ -76,4 +76,12 @@ var ( Name: "store_query_feedback_total", Help: "Counter of storing query feedback.", }, []string{LblType}) + + SignificantFeedbackCounter = prometheus.NewCounter( + prometheus.CounterOpts{ + Namespace: "tidb", + Subsystem: "statistics", + Name: "high_error_rate_feedback_total", + Help: "Counter of query feedback whose actual count is much different than calculated by current statistics", + }) ) diff --git a/statistics/update.go b/statistics/update.go index 393d1615b270f..8fc2a0884abbb 100644 --- a/statistics/update.go +++ b/statistics/update.go @@ -193,8 +193,11 @@ func (s *SessionStatsCollector) StoreQueryFeedback(feedback interface{}, h *Hand } else { rate = math.Abs(expected-float64(q.actual)) / float64(q.actual) } - if rate >= MinLogErrorRate && (q.actual >= MinLogScanCount || q.expected >= MinLogScanCount) && log.GetLevel() == log.DebugLevel { - q.logDetailedInfo(h) + if rate >= MinLogErrorRate && (q.actual >= MinLogScanCount || q.expected >= MinLogScanCount) { + metrics.SignificantFeedbackCounter.Inc() + if log.GetLevel() == log.DebugLevel { + q.logDetailedInfo(h) + } } metrics.StatsInaccuracyRate.Observe(rate) s.Lock()