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

domain/metrics: add a metric for lease expired time (#47730) #52932

Merged
Merged
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
1 change: 1 addition & 0 deletions pkg/domain/schema_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (s *schemaValidator) Update(leaseGrantTS uint64, oldVer, currVer int64, cha
leaseGrantTime := oracle.GetTimeFromTS(leaseGrantTS)
leaseExpire := leaseGrantTime.Add(s.lease - time.Millisecond)
s.latestSchemaExpire = leaseExpire
metrics.LeaseExpireTime.Set(float64(leaseExpire.Unix()))

// Update the schema deltaItem information.
if currVer != oldVer {
Expand Down
11 changes: 11 additions & 0 deletions pkg/metrics/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (

// Metrics for the domain package.
var (
// LeaseExpireTime records the lease expire time.
LeaseExpireTime prometheus.Gauge

// LoadSchemaCounter records the counter of load schema.
LoadSchemaCounter *prometheus.CounterVec

Expand Down Expand Up @@ -51,6 +54,14 @@ var (

// InitDomainMetrics initializes domain metrics.
func InitDomainMetrics() {
LeaseExpireTime = NewGauge(
prometheus.GaugeOpts{
Namespace: "tidb",
Subsystem: "domain",
Name: "lease_expire_time",
Help: "When the last time the lease is expired, it is in seconds",
})

LoadSchemaCounter = NewCounterVec(
prometheus.CounterOpts{
Namespace: "tidb",
Expand Down
108 changes: 108 additions & 0 deletions pkg/metrics/grafana/tidb.json
Original file line number Diff line number Diff line change
Expand Up @@ -12901,6 +12901,114 @@
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_TEST-CLUSTER}",
"description": "How much longer until the lease expires?",
"editable": true,
"error": false,
"fieldConfig": {
"defaults": {},
"overrides": []
},
"fill": 0,
"fillGradient": 0,
"grid": {},
"gridPos": {
"h": 7,
"w": 12,
"x": 0,
"y": 31
},
"hiddenSeries": false,
"id": 23763572002,
"legend": {
"alignAsTable": true,
"avg": false,
"current": true,
"max": false,
"min": false,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null as zero",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.5.11",
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"exemplar": true,
"expr": "tidb_domain_lease_expire_time{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\"} - time()",
"format": "time_series",
"interval": "",
"intervalFactor": 2,
"legendFormat": "{{instance}}",
"metric": "tidb_domain_load_schema_duration_count",
"refId": "A",
"step": 10
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Lease Duration",
"tooltip": {
"msResolution": false,
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"$$hashKey": "object:541",
"format": "dtdurations",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"$$hashKey": "object:542",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": false
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
}
],
"repeat": null,
Expand Down
1 change: 1 addition & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func RegisterMetrics() {
prometheus.MustRegister(JobsGauge)
prometheus.MustRegister(LoadPrivilegeCounter)
prometheus.MustRegister(InfoCacheCounters)
prometheus.MustRegister(LeaseExpireTime)
prometheus.MustRegister(LoadSchemaCounter)
prometheus.MustRegister(LoadSchemaDuration)
prometheus.MustRegister(MetaHistogram)
Expand Down