diff --git a/distsql/select_result.go b/distsql/select_result.go index 58d0abf49d04c..2a41e318579b4 100644 --- a/distsql/select_result.go +++ b/distsql/select_result.go @@ -54,8 +54,8 @@ var ( ) var ( - coprCacheHistogramHit = metrics.DistSQLCoprCacheHistogram.WithLabelValues("hit") - coprCacheHistogramMiss = metrics.DistSQLCoprCacheHistogram.WithLabelValues("miss") + coprCacheCounterHit = metrics.DistSQLCoprCacheCounter.WithLabelValues("hit") + coprCacheCounterMiss = metrics.DistSQLCoprCacheCounter.WithLabelValues("miss") ) var ( @@ -158,8 +158,8 @@ type selectResult struct { func (r *selectResult) fetchResp(ctx context.Context) error { defer func() { if r.stats != nil { - coprCacheHistogramHit.Observe(float64(r.stats.CoprCacheHitNum)) - coprCacheHistogramMiss.Observe(float64(len(r.stats.copRespTime) - int(r.stats.CoprCacheHitNum))) + coprCacheCounterHit.Add(float64(r.stats.CoprCacheHitNum)) + coprCacheCounterMiss.Add(float64(len(r.stats.copRespTime) - int(r.stats.CoprCacheHitNum))) // Ignore internal sql. if !r.ctx.GetSessionVars().InRestrictedSQL && len(r.stats.copRespTime) > 0 { ratio := float64(r.stats.CoprCacheHitNum) / float64(len(r.stats.copRespTime)) diff --git a/infoschema/metric_table_def.go b/infoschema/metric_table_def.go index b27217a316c03..7487adadb6168 100644 --- a/infoschema/metric_table_def.go +++ b/infoschema/metric_table_def.go @@ -2513,10 +2513,9 @@ var MetricTableMap = map[string]MetricTableDef{ Comment: "The total time of distsql execution(second)", }, "tidb_distsql_copr_cache": { - Comment: "The quantile of TiDB distsql coprocessor cache", - PromQL: "histogram_quantile($QUANTILE, sum(rate(tidb_distsql_copr_cache_bucket{$LABEL_CONDITIONS}[$RANGE_DURATION])) by (type,instance))", - Labels: []string{"instance", "type"}, - Quantile: 0.95, + Comment: "The total count of TiDB distsql coprocessor cache", + PromQL: "sum(rate(tidb_distsql_copr_cache{$LABEL_CONDITIONS}[$RANGE_DURATION])) by (type,instance))", + Labels: []string{"instance", "type"}, }, "tidb_execute_total_count": { PromQL: "sum(increase(tidb_session_execute_duration_seconds_count{$LABEL_CONDITIONS}[$RANGE_DURATION])) by (instance,sql_type)", diff --git a/metrics/distsql.go b/metrics/distsql.go index 3a4527da510ae..0452f54ee9913 100644 --- a/metrics/distsql.go +++ b/metrics/distsql.go @@ -53,12 +53,11 @@ var ( Help: "number of partial results for each query.", }, ) - DistSQLCoprCacheHistogram = prometheus.NewHistogramVec( - prometheus.HistogramOpts{ + DistSQLCoprCacheCounter = prometheus.NewCounterVec( + prometheus.CounterOpts{ Namespace: "tidb", Subsystem: "distsql", Name: "copr_cache", Help: "coprocessor cache hit, evict and miss number", - Buckets: prometheus.ExponentialBuckets(1, 2, 16), }, []string{LblType}) ) diff --git a/metrics/grafana/tidb.json b/metrics/grafana/tidb.json index a9bbf1ab4b83f..fcb3dfa5b55ca 100644 --- a/metrics/grafana/tidb.json +++ b/metrics/grafana/tidb.json @@ -6855,7 +6855,7 @@ "steppedLine": false, "targets": [ { - "expr": "sum(rate(tidb_distsql_copr_cache_sum{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}[1m])) by (type)", + "expr": "sum(rate(tidb_distsql_copr_cache{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}[1m])) by (type)", "format": "time_series", "intervalFactor": 2, "legendFormat": "{{type}}", diff --git a/metrics/metrics.go b/metrics/metrics.go index 31217926b6c30..565790480c6c7 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -102,7 +102,7 @@ func RegisterMetrics() { prometheus.MustRegister(DDLWorkerHistogram) prometheus.MustRegister(DeploySyncerHistogram) prometheus.MustRegister(DistSQLPartialCountHistogram) - prometheus.MustRegister(DistSQLCoprCacheHistogram) + prometheus.MustRegister(DistSQLCoprCacheCounter) prometheus.MustRegister(DistSQLQueryHistogram) prometheus.MustRegister(DistSQLScanKeysHistogram) prometheus.MustRegister(DistSQLScanKeysPartialHistogram) diff --git a/store/copr/coprocessor.go b/store/copr/coprocessor.go index bef71c20aeb51..2832abe60ecb1 100644 --- a/store/copr/coprocessor.go +++ b/store/copr/coprocessor.go @@ -53,7 +53,7 @@ import ( "go.uber.org/zap" ) -var coprCacheHistogramEvict = tidbmetrics.DistSQLCoprCacheHistogram.WithLabelValues("evict") +var coprCacheCounterEvict = tidbmetrics.DistSQLCoprCacheCounter.WithLabelValues("evict") // Maximum total sleep time(in ms) for kv/cop commands. const ( @@ -687,7 +687,7 @@ func (worker *copIteratorWorker) handleTask(ctx context.Context, task *copTask, } } if worker.store.coprCache != nil && worker.store.coprCache.cache.Metrics != nil { - coprCacheHistogramEvict.Observe(float64(worker.store.coprCache.cache.Metrics.KeysEvicted())) + coprCacheCounterEvict.Add(float64(worker.store.coprCache.cache.Metrics.KeysEvicted())) } }