Skip to content

Commit

Permalink
metrics: replace histogram with counter for DistSQLCoprCache (#35514)
Browse files Browse the repository at this point in the history
close #32075
  • Loading branch information
AricSu authored Jun 23, 2022
1 parent 79add25 commit 028bdcf
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
8 changes: 4 additions & 4 deletions distsql/select_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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))
Expand Down
7 changes: 3 additions & 4 deletions infoschema/metric_table_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
5 changes: 2 additions & 3 deletions metrics/distsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
)
2 changes: 1 addition & 1 deletion metrics/grafana/tidb.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}}",
Expand Down
2 changes: 1 addition & 1 deletion metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions store/copr/coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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()))
}
}

Expand Down

0 comments on commit 028bdcf

Please sign in to comment.