From 5a566530f8d02d04738a28d874321b959c2f0039 Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Tue, 29 Jan 2019 13:24:12 +0800 Subject: [PATCH 1/2] stats: add metircs for high error rate feedback --- metrics/metrics.go | 1 + metrics/stats.go | 8 ++++++++ statistics/update.go | 7 +++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/metrics/metrics.go b/metrics/metrics.go index 53a404aee9b88..54f23a66725d0 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(HighErrorRateFeedBackCounter) prometheus.MustRegister(JobsGauge) prometheus.MustRegister(KeepAliveCounter) prometheus.MustRegister(LoadPrivilegeCounter) diff --git a/metrics/stats.go b/metrics/stats.go index 3095fef556d3d..ebf1ec1dddef3 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}) + + HighErrorRateFeedBackCounter = 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 bc1e03e739830..87ae668cfd9c7 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.HighErrorRateFeedBackCounter.Inc() + if log.GetLevel() == log.DebugLevel { + q.logDetailedInfo(h) + } } metrics.StatsInaccuracyRate.Observe(rate) s.Lock() From a7957f8692024c9f72f9db1897a80aadc407fda6 Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Tue, 12 Feb 2019 15:20:06 +0800 Subject: [PATCH 2/2] address comment --- metrics/metrics.go | 2 +- metrics/stats.go | 2 +- statistics/update.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/metrics/metrics.go b/metrics/metrics.go index 54f23a66725d0..f1ead074c3711 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -74,7 +74,7 @@ func RegisterMetrics() { prometheus.MustRegister(GetTokenDurationHistogram) prometheus.MustRegister(HandShakeErrorCounter) prometheus.MustRegister(HandleJobHistogram) - prometheus.MustRegister(HighErrorRateFeedBackCounter) + prometheus.MustRegister(SignificantFeedbackCounter) prometheus.MustRegister(JobsGauge) prometheus.MustRegister(KeepAliveCounter) prometheus.MustRegister(LoadPrivilegeCounter) diff --git a/metrics/stats.go b/metrics/stats.go index ebf1ec1dddef3..8ce15590b8655 100644 --- a/metrics/stats.go +++ b/metrics/stats.go @@ -77,7 +77,7 @@ var ( Help: "Counter of storing query feedback.", }, []string{LblType}) - HighErrorRateFeedBackCounter = prometheus.NewCounter( + SignificantFeedbackCounter = prometheus.NewCounter( prometheus.CounterOpts{ Namespace: "tidb", Subsystem: "statistics", diff --git a/statistics/update.go b/statistics/update.go index bbca5d6187b46..8fc2a0884abbb 100644 --- a/statistics/update.go +++ b/statistics/update.go @@ -194,7 +194,7 @@ func (s *SessionStatsCollector) StoreQueryFeedback(feedback interface{}, h *Hand rate = math.Abs(expected-float64(q.actual)) / float64(q.actual) } if rate >= MinLogErrorRate && (q.actual >= MinLogScanCount || q.expected >= MinLogScanCount) { - metrics.HighErrorRateFeedBackCounter.Inc() + metrics.SignificantFeedbackCounter.Inc() if log.GetLevel() == log.DebugLevel { q.logDetailedInfo(h) }