Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#49424
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
bufferflies authored and ti-chi-bot committed Apr 18, 2024
1 parent 4c3389e commit a61bbbd
Show file tree
Hide file tree
Showing 13 changed files with 389 additions and 60 deletions.
10 changes: 5 additions & 5 deletions executor/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ func (c *Compiler) Compile(ctx context.Context, stmtNode ast.StmtNode) (_ *ExecS
})

if preparedObj != nil {
CountStmtNode(preparedObj.PreparedAst.Stmt, sessVars.InRestrictedSQL)
CountStmtNode(preparedObj.PreparedAst.Stmt, sessVars.InRestrictedSQL, stmtCtx.ResourceGroup)
} else {
CountStmtNode(stmtNode, sessVars.InRestrictedSQL)
CountStmtNode(stmtNode, sessVars.InRestrictedSQL, stmtCtx.ResourceGroup)
}
var lowerPriority bool
if c.Ctx.GetSessionVars().StmtCtx.Priority == mysql.NoPriority {
Expand Down Expand Up @@ -187,7 +187,7 @@ func isPhysicalPlanNeedLowerPriority(p plannercore.PhysicalPlan) bool {
}

// CountStmtNode records the number of statements with the same type.
func CountStmtNode(stmtNode ast.StmtNode, inRestrictedSQL bool) {
func CountStmtNode(stmtNode ast.StmtNode, inRestrictedSQL bool, resourceGroup string) {
if inRestrictedSQL {
return
}
Expand All @@ -203,11 +203,11 @@ func CountStmtNode(stmtNode ast.StmtNode, inRestrictedSQL bool) {
}
case config.GetGlobalConfig().Status.RecordDBLabel:
for dbLabel := range dbLabels {
metrics.StmtNodeCounter.WithLabelValues(typeLabel, dbLabel).Inc()
metrics.StmtNodeCounter.WithLabelValues(typeLabel, dbLabel, resourceGroup).Inc()
}
}
} else {
metrics.StmtNodeCounter.WithLabelValues(typeLabel, "").Inc()
metrics.StmtNodeCounter.WithLabelValues(typeLabel, "", resourceGroup).Inc()
}
}

Expand Down
2 changes: 1 addition & 1 deletion metrics/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func InitExecutorMetrics() {
Subsystem: "executor",
Name: "statement_total",
Help: "Counter of StmtNode.",
}, []string{LblType, LblDb})
}, []string{LblType, LblDb, LblResourceGroup})

DbStmtNodeCounter = NewCounterVec(
prometheus.CounterOpts{
Expand Down
10 changes: 5 additions & 5 deletions metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
QueryDurationHistogram *prometheus.HistogramVec
QueryTotalCounter *prometheus.CounterVec
AffectedRowsCounter *prometheus.CounterVec
ConnGauge prometheus.Gauge
ConnGauge *prometheus.GaugeVec
DisconnectionCounter *prometheus.CounterVec
PreparedStmtGauge prometheus.Gauge
ExecuteErrorCounter *prometheus.CounterVec
Expand Down Expand Up @@ -97,7 +97,7 @@ func InitServerMetrics() {
Subsystem: "server",
Name: "query_total",
Help: "Counter of queries.",
}, []string{LblType, LblResult})
}, []string{LblType, LblResult, LblResourceGroup})

AffectedRowsCounter = NewCounterVec(
prometheus.CounterOpts{
Expand All @@ -107,13 +107,13 @@ func InitServerMetrics() {
Help: "Counters of server affected rows.",
}, []string{LblSQLType})

ConnGauge = NewGauge(
ConnGauge = NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "tidb",
Subsystem: "server",
Name: "connections",
Help: "Number of connections.",
})
}, []string{LblResourceGroup})

DisconnectionCounter = NewCounterVec(
prometheus.CounterOpts{
Expand All @@ -136,7 +136,7 @@ func InitServerMetrics() {
Subsystem: "server",
Name: "execute_error_total",
Help: "Counter of execute errors.",
}, []string{LblType, LblDb})
}, []string{LblType, LblDb, LblResourceGroup})

CriticalErrorCounter = NewCounter(
prometheus.CounterOpts{
Expand Down
2 changes: 1 addition & 1 deletion metrics/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func InitSessionMetrics() {
Subsystem: "session",
Name: "resource_group_query_total",
Help: "Counter of the total number of queries for the resource group",
}, []string{LblName})
}, []string{LblName, LblResourceGroup})

FairLockingUsageCount = NewCounterVec(
prometheus.CounterOpts{
Expand Down
2 changes: 1 addition & 1 deletion metrics/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ func GetNonTransactionalStmtCounter() NonTransactionalStmtCounter {

// GetSavepointStmtCounter gets the savepoint statement executed counter.
func GetSavepointStmtCounter() int64 {
return readCounter(StmtNodeCounter.With(prometheus.Labels{LblType: "Savepoint", LblDb: ""}))
return readCounter(StmtNodeCounter.WithLabelValues("Savepoint", "", ""))
}

// GetLazyPessimisticUniqueCheckSetCounter returns the counter of setting tidb_constraint_check_in_place_pessimistic to false.
Expand Down
202 changes: 202 additions & 0 deletions pkg/server/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "server",
srcs = [
"conn.go",
"conn_stmt.go",
"conn_stmt_params.go",
"driver.go",
"driver_tidb.go",
"extension.go",
"extract.go",
"http_handler.go",
"http_status.go",
"mock_conn.go",
"rpc_server.go",
"server.go",
"stat.go",
"tokenlimiter.go",
],
importpath = "github.com/pingcap/tidb/pkg/server",
visibility = ["//visibility:public"],
deps = [
"//pkg/autoid_service",
"//pkg/config",
"//pkg/domain",
"//pkg/domain/infosync",
"//pkg/domain/resourcegroup",
"//pkg/errno",
"//pkg/executor",
"//pkg/executor/mppcoordmanager",
"//pkg/expression",
"//pkg/extension",
"//pkg/infoschema",
"//pkg/kv",
"//pkg/metrics",
"//pkg/param",
"//pkg/parser",
"//pkg/parser/ast",
"//pkg/parser/auth",
"//pkg/parser/charset",
"//pkg/parser/model",
"//pkg/parser/mysql",
"//pkg/parser/terror",
"//pkg/planner/core",
"//pkg/plugin",
"//pkg/privilege",
"//pkg/privilege/conn",
"//pkg/privilege/privileges",
"//pkg/privilege/privileges/ldap",
"//pkg/server/err",
"//pkg/server/handler",
"//pkg/server/handler/extractorhandler",
"//pkg/server/handler/optimizor",
"//pkg/server/handler/tikvhandler",
"//pkg/server/handler/ttlhandler",
"//pkg/server/internal",
"//pkg/server/internal/column",
"//pkg/server/internal/dump",
"//pkg/server/internal/handshake",
"//pkg/server/internal/parse",
"//pkg/server/internal/resultset",
"//pkg/server/internal/util",
"//pkg/server/metrics",
"//pkg/session",
"//pkg/session/txninfo",
"//pkg/session/types",
"//pkg/sessionctx",
"//pkg/sessionctx/sessionstates",
"//pkg/sessionctx/stmtctx",
"//pkg/sessionctx/variable",
"//pkg/sessiontxn",
"//pkg/statistics/handle",
"//pkg/store",
"//pkg/store/driver/error",
"//pkg/store/helper",
"//pkg/tablecodec",
"//pkg/types",
"//pkg/util",
"//pkg/util/arena",
"//pkg/util/chunk",
"//pkg/util/context",
"//pkg/util/cpuprofile",
"//pkg/util/dbterror",
"//pkg/util/dbterror/exeerrors",
"//pkg/util/execdetails",
"//pkg/util/fastrand",
"//pkg/util/hack",
"//pkg/util/intest",
"//pkg/util/logutil",
"//pkg/util/memory",
"//pkg/util/printer",
"//pkg/util/sqlexec",
"//pkg/util/sqlkiller",
"//pkg/util/sys/linux",
"//pkg/util/timeutil",
"//pkg/util/tls",
"//pkg/util/topsql",
"//pkg/util/topsql/state",
"//pkg/util/topsql/stmtstats",
"//pkg/util/tracing",
"//pkg/util/versioninfo",
"@com_github_blacktear23_go_proxyprotocol//:go-proxyprotocol",
"@com_github_gorilla_mux//:mux",
"@com_github_klauspost_compress//zstd",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_pingcap_fn//:fn",
"@com_github_pingcap_kvproto//pkg/autoid",
"@com_github_pingcap_kvproto//pkg/coprocessor",
"@com_github_pingcap_kvproto//pkg/diagnosticspb",
"@com_github_pingcap_kvproto//pkg/mpp",
"@com_github_pingcap_kvproto//pkg/tikvpb",
"@com_github_pingcap_sysutil//:sysutil",
"@com_github_prometheus_client_golang//prometheus",
"@com_github_prometheus_client_golang//prometheus/promhttp",
"@com_github_soheilhy_cmux//:cmux",
"@com_github_stretchr_testify//require",
"@com_github_tiancaiamao_appdash//traceapp",
"@com_github_tikv_client_go_v2//util",
"@com_sourcegraph_sourcegraph_appdash_data//:appdash-data",
"@org_golang_google_grpc//:grpc",
"@org_golang_google_grpc//channelz/service",
"@org_golang_google_grpc//keepalive",
"@org_golang_google_grpc//peer",
"@org_uber_go_atomic//:atomic",
"@org_uber_go_zap//:zap",
],
)

go_test(
name = "server_test",
timeout = "short",
srcs = [
"conn_stmt_params_test.go",
"conn_stmt_test.go",
"conn_test.go",
"driver_tidb_test.go",
"main_test.go",
"mock_conn_test.go",
"server_test.go",
"stat_test.go",
"tidb_library_test.go",
"tidb_test.go",
],
data = glob(["testdata/**"]),
embed = [":server"],
flaky = True,
shard_count = 50,
deps = [
"//pkg/config",
"//pkg/domain",
"//pkg/domain/infosync",
"//pkg/expression",
"//pkg/extension",
"//pkg/keyspace",
"//pkg/kv",
"//pkg/metrics",
"//pkg/param",
"//pkg/parser/ast",
"//pkg/parser/auth",
"//pkg/parser/charset",
"//pkg/parser/model",
"//pkg/parser/mysql",
"//pkg/parser/terror",
"//pkg/server/internal",
"//pkg/server/internal/column",
"//pkg/server/internal/handshake",
"//pkg/server/internal/parse",
"//pkg/server/internal/testutil",
"//pkg/server/internal/util",
"//pkg/session",
"//pkg/sessionctx/variable",
"//pkg/sessiontxn",
"//pkg/store/mockstore",
"//pkg/store/mockstore/unistore",
"//pkg/testkit",
"//pkg/testkit/external",
"//pkg/testkit/testdata",
"//pkg/testkit/testmain",
"//pkg/testkit/testsetup",
"//pkg/types",
"//pkg/util",
"//pkg/util/arena",
"//pkg/util/chunk",
"//pkg/util/context",
"//pkg/util/dbterror/exeerrors",
"//pkg/util/replayer",
"//pkg/util/sqlkiller",
"//pkg/util/syncutil",
"//pkg/util/topsql/state",
"@com_github_docker_go_units//:go-units",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_pingcap_kvproto//pkg/metapb",
"@com_github_stretchr_testify//require",
"@com_github_tikv_client_go_v2//error",
"@com_github_tikv_client_go_v2//testutils",
"@com_github_tikv_client_go_v2//tikv",
"@org_uber_go_goleak//:goleak",
],
)
Loading

0 comments on commit a61bbbd

Please sign in to comment.