Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distsql: fix copr cache events metric #28656

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions distsql/select_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,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 @@ -156,9 +156,9 @@ 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)))
if config.GetGlobalConfig().TiKVClient.CoprCache.CapacityMB > 0 && r.stats != nil {
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,
PromQL: "sum(rate(tidb_distsql_copr_cache{$LABEL_CONDITIONS}[$RANGE_DURATION])) by (type,instance)",
Labels: []string{"instance", "type"},
Comment: "The counter of TiDB distsql coprocessor cache events",
},
"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 @@ -6657,7 +6657,7 @@
"steppedLine": false,
"targets": [
{
"expr": "sum(rate(tidb_distsql_copr_cache_count{tidb_cluster=\"$tidb_cluster\"}[1m])) by (type)",
"expr": "sum(rate(tidb_distsql_copr_cache{tidb_cluster=\"$tidb_cluster\"}[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 @@ -84,7 +84,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 @@ -52,7 +52,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 @@ -656,7 +656,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