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

infoschema,metrics: add a metric for infoschema v2 cache objects count #58781

Merged
merged 6 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion pkg/infoschema/infoschemav2_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (m *mockStatusHook) onMiss() {
func (m *mockStatusHook) onEvict() {
m.Called()
}
func (m *mockStatusHook) onUpdateSize(size uint64) {
func (m *mockStatusHook) onUpdate(size uint64, count uint64) {
m.Called()
}
func (m *mockStatusHook) onUpdateLimit(limit uint64) {
Expand Down
5 changes: 4 additions & 1 deletion pkg/infoschema/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type sieveStatusHookImpl struct {
hit prometheus.Counter
miss prometheus.Counter

objCnt prometheus.Gauge
memUsage prometheus.Gauge
memLimit prometheus.Gauge
}
Expand All @@ -34,6 +35,7 @@ func newSieveStatusHookImpl() *sieveStatusHookImpl {
hit: metrics.InfoSchemaV2CacheCounter.WithLabelValues("hit"),
miss: metrics.InfoSchemaV2CacheCounter.WithLabelValues("miss"),

objCnt: metrics.InfoSchemaV2CacheObjCnt,
memUsage: metrics.InfoSchemaV2CacheMemUsage,
memLimit: metrics.InfoSchemaV2CacheMemLimit,
}
Expand All @@ -51,8 +53,9 @@ func (s *sieveStatusHookImpl) onMiss() {
s.miss.Inc()
}

func (s *sieveStatusHookImpl) onUpdateSize(size uint64) {
func (s *sieveStatusHookImpl) onUpdate(size uint64, count uint64) {
s.memUsage.Set(float64(size))
s.objCnt.Set(float64(count))
}

func (s *sieveStatusHookImpl) onUpdateLimit(limit uint64) {
Expand Down
11 changes: 7 additions & 4 deletions pkg/infoschema/sieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Sieve[K comparable, V any] struct {
ctx context.Context
cancel context.CancelFunc
mu sync.Mutex
count uint64
size uint64
// capacity can be set to zero for disabling infoschema v2
capacity uint64
Expand All @@ -63,7 +64,7 @@ type sieveStatusHook interface {
onHit()
onMiss()
onEvict()
onUpdateSize(size uint64)
onUpdate(size uint64, count uint64)
onUpdateLimit(limit uint64)
}

Expand All @@ -75,7 +76,7 @@ func (e *emptySieveStatusHook) onMiss() {}

func (e *emptySieveStatusHook) onEvict() {}

func (e *emptySieveStatusHook) onUpdateSize(_ uint64) {}
func (e *emptySieveStatusHook) onUpdate(_, _ uint64) {}

func (e *emptySieveStatusHook) onUpdateLimit(_ uint64) {}

Expand Down Expand Up @@ -145,7 +146,8 @@ 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)
s.count += 1
s.hook.onUpdate(s.size, s.count)
e.element = s.ll.PushFront(key)

s.items[key] = e
Expand Down Expand Up @@ -239,7 +241,8 @@ 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)
s.count -= 1
s.hook.onUpdate(s.size, s.count)
}

func (s *Sieve[K, V]) evict() {
Expand Down
99 changes: 98 additions & 1 deletion pkg/metrics/grafana/tidb.json
Original file line number Diff line number Diff line change
Expand Up @@ -14604,7 +14604,104 @@
"align": false,
"alignLevel": null
}
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_TEST-CLUSTER}",
"description": "Cached table count of infoschema cache v2",
"fieldConfig": {
"defaults": {},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 46
},
"hiddenSeries": false,
"id": 23763572016,
"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_count{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\"}",
"interval": "",
"legendFormat": "used",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Infoschema v2 Cache Table Count",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": false
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
}
],
"repeat": null,
"title": "Schema Load",
Expand Down
9 changes: 9 additions & 0 deletions pkg/metrics/infoschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var (
InfoSchemaV2CacheCounter *prometheus.CounterVec
// InfoSchemaV2CacheMemUsage records the memory size of infoschema v2 cache.
InfoSchemaV2CacheMemUsage prometheus.Gauge
// InfoSchemaV2CacheObjCnt records the table count of infoschema v2 cache.
InfoSchemaV2CacheObjCnt prometheus.Gauge
// InfoSchemaV2CacheMemLimit records the memory limit of infoschema v2 cache.
InfoSchemaV2CacheMemLimit prometheus.Gauge
// TableByNameDuration records the duration of TableByName API for infoschema v2.
Expand All @@ -42,6 +44,13 @@ func InitInfoSchemaV2Metrics() {
Name: "infoschema_v2_cache",
Help: "infoschema cache v2 hit, evict and miss number",
}, []string{LblType})
InfoSchemaV2CacheObjCnt = NewGauge(
prometheus.GaugeOpts{
Namespace: "tidb",
Subsystem: "domain",
Name: "infoschema_v2_cache_count",
Help: "infoschema cache v2 table count",
})
InfoSchemaV2CacheMemUsage = NewGauge(
prometheus.GaugeOpts{
Namespace: "tidb",
Expand Down
1 change: 1 addition & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ func RegisterMetrics() {
prometheus.MustRegister(InfoSchemaV2CacheCounter)
prometheus.MustRegister(InfoSchemaV2CacheMemUsage)
prometheus.MustRegister(InfoSchemaV2CacheMemLimit)
prometheus.MustRegister(InfoSchemaV2CacheObjCnt)
prometheus.MustRegister(TableByNameDuration)

prometheus.MustRegister(BindingCacheHitCounter)
Expand Down