metrics: add infoschema v2 cache size and limit (#54364)

ref pingcap/tidb#50959
This commit is contained in:
tangenta
2024-07-01 21:53:56 +08:00
committed by GitHub
parent 600682265b
commit 80d392be06
5 changed files with 152 additions and 2 deletions

View File

@ -23,6 +23,9 @@ type sieveStatusHookImpl struct {
evict prometheus.Counter
hit prometheus.Counter
miss prometheus.Counter
memUsage prometheus.Gauge
memLimit prometheus.Gauge
}
func newSieveStatusHookImpl() *sieveStatusHookImpl {
@ -30,6 +33,9 @@ func newSieveStatusHookImpl() *sieveStatusHookImpl {
evict: metrics.InfoSchemaV2CacheCounter.WithLabelValues("evict"),
hit: metrics.InfoSchemaV2CacheCounter.WithLabelValues("hit"),
miss: metrics.InfoSchemaV2CacheCounter.WithLabelValues("miss"),
memUsage: metrics.InfoSchemaV2CacheMemUsage,
memLimit: metrics.InfoSchemaV2CacheMemLimit,
}
}
@ -44,3 +50,11 @@ func (s *sieveStatusHookImpl) onHit() {
func (s *sieveStatusHookImpl) onMiss() {
s.miss.Inc()
}
func (s *sieveStatusHookImpl) onUpdateSize(size uint64) {
s.memUsage.Set(float64(size))
}
func (s *sieveStatusHookImpl) onUpdateLimit(limit uint64) {
s.memLimit.Set(float64(limit))
}

View File

@ -61,6 +61,8 @@ type sieveStatusHook interface {
onHit()
onMiss()
onEvict()
onUpdateSize(size uint64)
onUpdateLimit(limit uint64)
}
type emptySieveStatusHook struct{}
@ -71,6 +73,10 @@ func (e *emptySieveStatusHook) onMiss() {}
func (e *emptySieveStatusHook) onEvict() {}
func (e *emptySieveStatusHook) onUpdateSize(_ uint64) {}
func (e *emptySieveStatusHook) onUpdateLimit(_ uint64) {}
func newSieve[K comparable, V any](capacity uint64) *Sieve[K, V] {
ctx, cancel := context.WithCancel(context.Background())
@ -94,6 +100,7 @@ func (s *Sieve[K, V]) SetCapacity(capacity uint64) {
s.mu.Lock()
defer s.mu.Unlock()
s.capacity = capacity
s.hook.onUpdateLimit(capacity)
}
func (s *Sieve[K, V]) Capacity() uint64 {
@ -121,6 +128,7 @@ func (s *Sieve[K, V]) Set(key K, value V) {
value: value,
}
s.size += e.Size() // calculate the size first without putting to the list.
s.hook.onUpdateSize(s.size)
e.element = s.ll.PushFront(key)
s.items[key] = e
@ -210,6 +218,7 @@ func (s *Sieve[K, V]) removeEntry(e *entry[K, V]) {
s.ll.Remove(e.element)
delete(s.items, e.key)
s.size -= e.Size()
s.hook.onUpdateSize(s.size)
}
func (s *Sieve[K, V]) evict() {

View File

@ -13907,7 +13907,7 @@
"aliasColors": {},
"dashLength": 10,
"datasource": "${DS_TEST-CLUSTER}",
"description": "Infoschema cache v2 hit, evict and miss number",
"description": "Infoschema v2 cache hit, evict and miss number",
"fieldConfig": {
"defaults": {},
"overrides": []
@ -13972,7 +13972,7 @@
],
"thresholds": [],
"timeRegions": [],
"title": "Infoschema Cache v2",
"title": "Infoschema v2 Cache Operation",
"tooltip": {
"shared": true,
"sort": 2,
@ -14020,6 +14020,113 @@
"steppedLine": false,
"timeFrom": null,
"timeShift": null
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_TEST-CLUSTER}",
"description": "Memory size of infoschema cache v2",
"fieldConfig": {
"defaults": {},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 38
},
"hiddenSeries": false,
"id": 23763572014,
"legend": {
"alignAsTable": false,
"avg": false,
"current": true,
"max": false,
"min": false,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 2,
"nullPointMode": "null",
"options": {
"alertThreshold": false
},
"percentage": false,
"pluginVersion": "7.5.17",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"exemplar": true,
"expr": "tidb_domain_infoschema_v2_cache_size{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\"}",
"interval": "",
"legendFormat": "used",
"refId": "A"
},
{
"exemplar": true,
"expr": "tidb_domain_infoschema_v2_cache_limit{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\"}",
"hide": false,
"interval": "",
"legendFormat": "limit",
"refId": "B"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Infoschema v2 Cache Size",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"$$hashKey": "object:90",
"format": "bytes",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"$$hashKey": "object:91",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": false
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
}
],
"repeat": null,

View File

@ -21,6 +21,10 @@ import (
var (
// InfoSchemaV2CacheCounter records the counter of infoschema v2 cache hit/miss/evict.
InfoSchemaV2CacheCounter *prometheus.CounterVec
// InfoSchemaV2CacheMemUsage records the memory size of infoschema v2 cache.
InfoSchemaV2CacheMemUsage prometheus.Gauge
// InfoSchemaV2CacheMemLimit records the memory limit of infoschema v2 cache.
InfoSchemaV2CacheMemLimit prometheus.Gauge
)
// InitInfoSchemaV2Metrics intializes infoschema v2 related metrics.
@ -32,4 +36,18 @@ func InitInfoSchemaV2Metrics() {
Name: "infoschema_v2_cache",
Help: "infoschema cache v2 hit, evict and miss number",
}, []string{LblType})
InfoSchemaV2CacheMemUsage = NewGauge(
prometheus.GaugeOpts{
Namespace: "tidb",
Subsystem: "domain",
Name: "infoschema_v2_cache_size",
Help: "infoschema cache v2 size",
})
InfoSchemaV2CacheMemLimit = NewGauge(
prometheus.GaugeOpts{
Namespace: "tidb",
Subsystem: "domain",
Name: "infoschema_v2_cache_limit",
Help: "infoschema cache v2 limit",
})
}

View File

@ -282,6 +282,8 @@ func RegisterMetrics() {
prometheus.MustRegister(AddIndexScanRate)
prometheus.MustRegister(InfoSchemaV2CacheCounter)
prometheus.MustRegister(InfoSchemaV2CacheMemUsage)
prometheus.MustRegister(InfoSchemaV2CacheMemLimit)
prometheus.MustRegister(BindingCacheHitCounter)
prometheus.MustRegister(BindingCacheMissCounter)