Skip to content

Commit

Permalink
move timer metrics to a standalone package
Browse files Browse the repository at this point in the history
  • Loading branch information
lcwangchao committed Jul 27, 2023
1 parent 542a514 commit 7d3da73
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion metrics/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ go_library(
"sli.go",
"stats.go",
"telemetry.go",
"timer.go",
"topsql.go",
"ttl.go",
"wrapper.go",
Expand All @@ -28,6 +27,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//parser/terror",
"//timer/metrics",
"//util/logutil",
"//util/mathutil",
"@com_github_pingcap_errors//:errors",
Expand Down
5 changes: 3 additions & 2 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package metrics
import (
"sync"

timermetrics "github.com/pingcap/tidb/timer/metrics"
"github.com/pingcap/tidb/util/logutil"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
Expand Down Expand Up @@ -91,7 +92,7 @@ func InitMetrics() {
InitTelemetryMetrics()
InitTopSQLMetrics()
InitTTLMetrics()
InitTimerMetrics()
timermetrics.InitTimerMetrics()

PanicCounter = NewCounterVec(
prometheus.CounterOpts{
Expand Down Expand Up @@ -258,7 +259,7 @@ func RegisterMetrics() {
prometheus.MustRegister(TTLWatermarkDelay)
prometheus.MustRegister(TTLEventCounter)

prometheus.MustRegister(TimerEventCounter)
prometheus.MustRegister(timermetrics.TimerEventCounter)

prometheus.MustRegister(EMACPUUsageGauge)
prometheus.MustRegister(PoolConcurrencyCounter)
Expand Down
9 changes: 9 additions & 0 deletions timer/metrics/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "metrics",
srcs = ["metrics.go"],
importpath = "github.com/pingcap/tidb/timer/metrics",
visibility = ["//visibility:public"],
deps = ["@com_github_prometheus_client_golang//prometheus"],
)
9 changes: 3 additions & 6 deletions metrics/timer.go → timer/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

const (
timerSysScope = "sys"
)

// Timer metrics
var (
TimerEventCounter *prometheus.CounterVec
Expand All @@ -34,19 +30,20 @@ var (

// InitTimerMetrics initializes timers metrics.
func InitTimerMetrics() {
TimerEventCounter = NewCounterVec(
TimerEventCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "tidb",
Subsystem: "server",
Name: "timer_event_count",
Help: "Counter of timer event.",
}, []string{LblScope, LblType})
}, []string{"scope", "type"})

rtScope := "runtime"
TimerFullRefreshCounter = TimerEventCounter.WithLabelValues(rtScope, "full_refresh_timers")
TimerPartialRefreshCounter = TimerEventCounter.WithLabelValues(rtScope, "partial_refresh_timers")
}

// TimerHookWorkerCounter creates a counter for a hook's event
func TimerHookWorkerCounter(hookClass string, event string) prometheus.Counter {
return TimerEventCounter.WithLabelValues(fmt.Sprintf("hook.%s", hookClass), event)
}
4 changes: 2 additions & 2 deletions timer/runtime/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ go_library(
importpath = "github.com/pingcap/tidb/timer/runtime",
visibility = ["//visibility:public"],
deps = [
"//metrics",
"//timer/api",
"//timer/metrics",
"//util/logutil",
"@com_github_google_uuid//:uuid",
"@com_github_pingcap_errors//:errors",
Expand All @@ -35,9 +35,9 @@ go_test(
race = "on",
shard_count = 19,
deps = [
"//metrics",
"//testkit/testsetup",
"//timer/api",
"//timer/metrics",
"//util/mock",
"@com_github_google_uuid//:uuid",
"@com_github_pingcap_errors//:errors",
Expand Down
2 changes: 1 addition & 1 deletion timer/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"time"

"github.com/google/uuid"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/timer/api"
"github.com/pingcap/tidb/timer/metrics"
"github.com/pingcap/tidb/util/logutil"
"go.uber.org/zap"
"golang.org/x/exp/maps"
Expand Down
2 changes: 1 addition & 1 deletion timer/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"unsafe"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/timer/api"
"github.com/pingcap/tidb/timer/metrics"
mockutil "github.com/pingcap/tidb/util/mock"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion timer/runtime/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"time"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/timer/api"
"github.com/pingcap/tidb/timer/metrics"
"github.com/pingcap/tidb/util/logutil"
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"
Expand Down

0 comments on commit 7d3da73

Please sign in to comment.