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

metrics: attach const label keyspace_id #41693

Merged
merged 6 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 br/cmd/br/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ go_library(
"//session",
"//util",
"//util/logutil",
"//util/metricsutil",
"@com_github_gogo_protobuf//proto",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_kvproto//pkg/brpb",
Expand Down
3 changes: 3 additions & 0 deletions br/cmd/br/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/pingcap/tidb/br/pkg/version/build"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/util/metricsutil"
"github.com/spf13/cobra"
"go.uber.org/zap"
"sourcegraph.com/sourcegraph/appdash"
Expand All @@ -25,6 +26,8 @@ func runBackupCommand(command *cobra.Command, cmdName string) error {
return errors.Trace(err)
}

metricsutil.RegisterMetricsForBR(cfg.PD, cfg.KeyspaceName)

ctx := GetDefaultContext()
if cfg.EnableOpenTracing {
var store *appdash.MemoryStore
Expand Down
3 changes: 3 additions & 0 deletions br/cmd/br/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/pingcap/tidb/br/pkg/utils"
"github.com/pingcap/tidb/br/pkg/version/build"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/util/metricsutil"
"github.com/spf13/cobra"
"go.uber.org/zap"
"sourcegraph.com/sourcegraph/appdash"
Expand All @@ -27,6 +28,8 @@ func runRestoreCommand(command *cobra.Command, cmdName string) error {
return errors.Trace(err)
}

metricsutil.RegisterMetricsForBR(cfg.PD, cfg.KeyspaceName)

if task.IsStreamRestore(cmdName) {
if err := cfg.ParseStreamRestoreFlags(command.Flags()); err != nil {
return errors.Trace(err)
Expand Down
2 changes: 2 additions & 0 deletions domain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ go_library(
"domainctx.go",
"extract.go",
"historical_stats.go",
"metrics.go",
"optimize_trace.go",
"plan_replayer.go",
"plan_replayer_dump.go",
Expand Down Expand Up @@ -76,6 +77,7 @@ go_library(
"@com_github_pingcap_kvproto//pkg/metapb",
"@com_github_pingcap_kvproto//pkg/pdpb",
"@com_github_pingcap_log//:log",
"@com_github_prometheus_client_golang//prometheus",
"@com_github_stretchr_testify//require",
"@com_github_tikv_client_go_v2//oracle",
"@com_github_tikv_client_go_v2//tikv",
Expand Down
6 changes: 0 additions & 6 deletions domain/historical_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,13 @@ package domain
import (
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/statistics/handle"
"github.com/pingcap/tidb/util/logutil"
"go.uber.org/zap"
)

var (
generateHistoricalStatsSuccessCounter = metrics.HistoricalStatsCounter.WithLabelValues("generate", "success")
generateHistoricalStatsFailedCounter = metrics.HistoricalStatsCounter.WithLabelValues("generate", "fail")
)

// HistoricalStatsWorker indicates for dump historical stats
type HistoricalStatsWorker struct {
tblCH chan int64
Expand Down
51 changes: 51 additions & 0 deletions domain/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2023 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package domain

import (
"github.com/pingcap/tidb/metrics"
"github.com/prometheus/client_golang/prometheus"
)

var (
generateHistoricalStatsSuccessCounter prometheus.Counter
generateHistoricalStatsFailedCounter prometheus.Counter

planReplayerDumpTaskSuccess prometheus.Counter
planReplayerDumpTaskFailed prometheus.Counter

planReplayerCaptureTaskSendCounter prometheus.Counter
planReplayerCaptureTaskDiscardCounter prometheus.Counter

planReplayerRegisterTaskGauge prometheus.Gauge
)

func init() {
InitMetricsVars()
}

// InitMetricsVars init domain metrics vars.
func InitMetricsVars() {
generateHistoricalStatsSuccessCounter = metrics.HistoricalStatsCounter.WithLabelValues("generate", "success")
generateHistoricalStatsFailedCounter = metrics.HistoricalStatsCounter.WithLabelValues("generate", "fail")

planReplayerDumpTaskSuccess = metrics.PlanReplayerTaskCounter.WithLabelValues("dump", "success")
planReplayerDumpTaskFailed = metrics.PlanReplayerTaskCounter.WithLabelValues("dump", "fail")

planReplayerCaptureTaskSendCounter = metrics.PlanReplayerTaskCounter.WithLabelValues("capture", "send")
planReplayerCaptureTaskDiscardCounter = metrics.PlanReplayerTaskCounter.WithLabelValues("capture", "discard")

planReplayerRegisterTaskGauge = metrics.PlanReplayerRegisterTaskGauge
}
7 changes: 0 additions & 7 deletions domain/plan_replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,6 @@ func insertPlanReplayerSuccessStatusRecord(ctx context.Context, sctx sessionctx.
}
}

var (
planReplayerCaptureTaskSendCounter = metrics.PlanReplayerTaskCounter.WithLabelValues("capture", "send")
planReplayerCaptureTaskDiscardCounter = metrics.PlanReplayerTaskCounter.WithLabelValues("capture", "discard")

planReplayerRegisterTaskGauge = metrics.PlanReplayerRegisterTaskGauge
)

type planReplayerHandle struct {
*planReplayerTaskCollectorHandle
*planReplayerTaskDumpHandle
Expand Down
6 changes: 0 additions & 6 deletions domain/plan_replayer_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/pingcap/tidb/bindinfo"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/sessionctx"
Expand Down Expand Up @@ -151,11 +150,6 @@ func (tne *tableNameExtractor) handleIsView(t *ast.TableName) (bool, error) {
return true, nil
}

var (
planReplayerDumpTaskSuccess = metrics.PlanReplayerTaskCounter.WithLabelValues("dump", "success")
planReplayerDumpTaskFailed = metrics.PlanReplayerTaskCounter.WithLabelValues("dump", "fail")
)

// DumpPlanReplayerInfo will dump the information about sqls.
// The files will be organized into the following format:
/*
Expand Down
1 change: 1 addition & 0 deletions executor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ go_library(
"mem_reader.go",
"memtable_reader.go",
"merge_join.go",
"metrics.go",
"metrics_reader.go",
"mpp_gather.go",
"opt_rule_blacklist.go",
Expand Down
126 changes: 0 additions & 126 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,32 +74,6 @@ import (
"go.uber.org/zap/zapcore"
)

// metrics option
var (
totalQueryProcHistogramGeneral = metrics.TotalQueryProcHistogram.WithLabelValues(metrics.LblGeneral)
totalCopProcHistogramGeneral = metrics.TotalCopProcHistogram.WithLabelValues(metrics.LblGeneral)
totalCopWaitHistogramGeneral = metrics.TotalCopWaitHistogram.WithLabelValues(metrics.LblGeneral)
totalQueryProcHistogramInternal = metrics.TotalQueryProcHistogram.WithLabelValues(metrics.LblInternal)
totalCopProcHistogramInternal = metrics.TotalCopProcHistogram.WithLabelValues(metrics.LblInternal)
totalCopWaitHistogramInternal = metrics.TotalCopWaitHistogram.WithLabelValues(metrics.LblInternal)

selectForUpdateFirstAttemptDuration = metrics.PessimisticDMLDurationByAttempt.WithLabelValues("select-for-update", "first-attempt")
selectForUpdateRetryDuration = metrics.PessimisticDMLDurationByAttempt.WithLabelValues("select-for-update", "retry")
dmlFirstAttemptDuration = metrics.PessimisticDMLDurationByAttempt.WithLabelValues("dml", "first-attempt")
dmlRetryDuration = metrics.PessimisticDMLDurationByAttempt.WithLabelValues("dml", "retry")

// aggressiveLockingTxnUsedCount counts transactions where at least one statement has aggressive locking enabled.
aggressiveLockingTxnUsedCount = metrics.AggressiveLockingUsageCount.WithLabelValues(metrics.LblAggressiveLockingTxnUsed)
// aggressiveLockingStmtUsedCount counts statements that have aggressive locking enabled.
aggressiveLockingStmtUsedCount = metrics.AggressiveLockingUsageCount.WithLabelValues(metrics.LblAggressiveLockingStmtUsed)
// aggressiveLockingTxnUsedCount counts transactions where at least one statement has aggressive locking enabled,
// and it takes effect (which is determined according to whether lock-with-conflict has occurred during execution).
aggressiveLockingTxnEffectiveCount = metrics.AggressiveLockingUsageCount.WithLabelValues(metrics.LblAggressiveLockingTxnEffective)
// aggressiveLockingTxnUsedCount counts statements where at least one statement has aggressive locking enabled,
// and it takes effect (which is determined according to whether lock-with-conflict has occurred during execution).
aggressiveLockingStmtEffectiveCount = metrics.AggressiveLockingUsageCount.WithLabelValues(metrics.LblAggressiveLockingStmtEffective)
)

// processinfoSetter is the interface use to set current running process info.
type processinfoSetter interface {
SetProcessInfo(string, time.Time, byte, uint64)
Expand Down Expand Up @@ -1272,106 +1246,6 @@ func FormatSQL(sql string) stringutil.StringerFunc {
}
}

const (
phaseBuildLocking = "build:locking"
phaseOpenLocking = "open:locking"
phaseNextLocking = "next:locking"
phaseLockLocking = "lock:locking"
phaseBuildFinal = "build:final"
phaseOpenFinal = "open:final"
phaseNextFinal = "next:final"
phaseLockFinal = "lock:final"
phaseCommitPrewrite = "commit:prewrite"
phaseCommitCommit = "commit:commit"
phaseCommitWaitCommitTS = "commit:wait:commit-ts"
phaseCommitWaitLatestTS = "commit:wait:latest-ts"
phaseCommitWaitLatch = "commit:wait:local-latch"
phaseCommitWaitBinlog = "commit:wait:prewrite-binlog"
phaseWriteResponse = "write-response"
)

var (
sessionExecuteRunDurationInternal = metrics.SessionExecuteRunDuration.WithLabelValues(metrics.LblInternal)
sessionExecuteRunDurationGeneral = metrics.SessionExecuteRunDuration.WithLabelValues(metrics.LblGeneral)
totalTiFlashQuerySuccCounter = metrics.TiFlashQueryTotalCounter.WithLabelValues("", metrics.LblOK)

// pre-define observers for non-internal queries
execBuildLocking = metrics.ExecPhaseDuration.WithLabelValues(phaseBuildLocking, "0")
execOpenLocking = metrics.ExecPhaseDuration.WithLabelValues(phaseOpenLocking, "0")
execNextLocking = metrics.ExecPhaseDuration.WithLabelValues(phaseNextLocking, "0")
execLockLocking = metrics.ExecPhaseDuration.WithLabelValues(phaseLockLocking, "0")
execBuildFinal = metrics.ExecPhaseDuration.WithLabelValues(phaseBuildFinal, "0")
execOpenFinal = metrics.ExecPhaseDuration.WithLabelValues(phaseOpenFinal, "0")
execNextFinal = metrics.ExecPhaseDuration.WithLabelValues(phaseNextFinal, "0")
execLockFinal = metrics.ExecPhaseDuration.WithLabelValues(phaseLockFinal, "0")
execCommitPrewrite = metrics.ExecPhaseDuration.WithLabelValues(phaseCommitPrewrite, "0")
execCommitCommit = metrics.ExecPhaseDuration.WithLabelValues(phaseCommitCommit, "0")
execCommitWaitCommitTS = metrics.ExecPhaseDuration.WithLabelValues(phaseCommitWaitCommitTS, "0")
execCommitWaitLatestTS = metrics.ExecPhaseDuration.WithLabelValues(phaseCommitWaitLatestTS, "0")
execCommitWaitLatch = metrics.ExecPhaseDuration.WithLabelValues(phaseCommitWaitLatch, "0")
execCommitWaitBinlog = metrics.ExecPhaseDuration.WithLabelValues(phaseCommitWaitBinlog, "0")
execWriteResponse = metrics.ExecPhaseDuration.WithLabelValues(phaseWriteResponse, "0")
execUnknown = metrics.ExecPhaseDuration.WithLabelValues("unknown", "0")

// pre-define observers for internal queries
execBuildLockingInternal = metrics.ExecPhaseDuration.WithLabelValues(phaseBuildLocking, "1")
execOpenLockingInternal = metrics.ExecPhaseDuration.WithLabelValues(phaseOpenLocking, "1")
execNextLockingInternal = metrics.ExecPhaseDuration.WithLabelValues(phaseNextLocking, "1")
execLockLockingInternal = metrics.ExecPhaseDuration.WithLabelValues(phaseLockLocking, "1")
execBuildFinalInternal = metrics.ExecPhaseDuration.WithLabelValues(phaseBuildFinal, "1")
execOpenFinalInternal = metrics.ExecPhaseDuration.WithLabelValues(phaseOpenFinal, "1")
execNextFinalInternal = metrics.ExecPhaseDuration.WithLabelValues(phaseNextFinal, "1")
execLockFinalInternal = metrics.ExecPhaseDuration.WithLabelValues(phaseLockFinal, "1")
execCommitPrewriteInternal = metrics.ExecPhaseDuration.WithLabelValues(phaseCommitPrewrite, "1")
execCommitCommitInternal = metrics.ExecPhaseDuration.WithLabelValues(phaseCommitCommit, "1")
execCommitWaitCommitTSInternal = metrics.ExecPhaseDuration.WithLabelValues(phaseCommitWaitCommitTS, "1")
execCommitWaitLatestTSInternal = metrics.ExecPhaseDuration.WithLabelValues(phaseCommitWaitLatestTS, "1")
execCommitWaitLatchInternal = metrics.ExecPhaseDuration.WithLabelValues(phaseCommitWaitLatch, "1")
execCommitWaitBinlogInternal = metrics.ExecPhaseDuration.WithLabelValues(phaseCommitWaitBinlog, "1")
execWriteResponseInternal = metrics.ExecPhaseDuration.WithLabelValues(phaseWriteResponse, "1")
execUnknownInternal = metrics.ExecPhaseDuration.WithLabelValues("unknown", "1")
)

var phaseDurationObserverMap map[string]prometheus.Observer
var phaseDurationObserverMapInternal map[string]prometheus.Observer

func init() {
phaseDurationObserverMap = map[string]prometheus.Observer{
phaseBuildLocking: execBuildLocking,
phaseOpenLocking: execOpenLocking,
phaseNextLocking: execNextLocking,
phaseLockLocking: execLockLocking,
phaseBuildFinal: execBuildFinal,
phaseOpenFinal: execOpenFinal,
phaseNextFinal: execNextFinal,
phaseLockFinal: execLockFinal,
phaseCommitPrewrite: execCommitPrewrite,
phaseCommitCommit: execCommitCommit,
phaseCommitWaitCommitTS: execCommitWaitCommitTS,
phaseCommitWaitLatestTS: execCommitWaitLatestTS,
phaseCommitWaitLatch: execCommitWaitLatch,
phaseCommitWaitBinlog: execCommitWaitBinlog,
phaseWriteResponse: execWriteResponse,
}
phaseDurationObserverMapInternal = map[string]prometheus.Observer{
phaseBuildLocking: execBuildLockingInternal,
phaseOpenLocking: execOpenLockingInternal,
phaseNextLocking: execNextLockingInternal,
phaseLockLocking: execLockLockingInternal,
phaseBuildFinal: execBuildFinalInternal,
phaseOpenFinal: execOpenFinalInternal,
phaseNextFinal: execNextFinalInternal,
phaseLockFinal: execLockFinalInternal,
phaseCommitPrewrite: execCommitPrewriteInternal,
phaseCommitCommit: execCommitCommitInternal,
phaseCommitWaitCommitTS: execCommitWaitCommitTSInternal,
phaseCommitWaitLatestTS: execCommitWaitLatestTSInternal,
phaseCommitWaitLatch: execCommitWaitLatchInternal,
phaseCommitWaitBinlog: execCommitWaitBinlogInternal,
phaseWriteResponse: execWriteResponseInternal,
}
}

func getPhaseDurationObserver(phase string, internal bool) prometheus.Observer {
if internal {
if ob, found := phaseDurationObserverMapInternal[phase]; found {
Expand Down
7 changes: 0 additions & 7 deletions executor/analyze_fast.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
Expand All @@ -46,12 +45,6 @@ import (
"github.com/tikv/client-go/v2/tikv"
)

var (
fastAnalyzeHistogramSample = metrics.FastAnalyzeHistogram.WithLabelValues(metrics.LblGeneral, "sample")
fastAnalyzeHistogramAccessRegions = metrics.FastAnalyzeHistogram.WithLabelValues(metrics.LblGeneral, "access_regions")
fastAnalyzeHistogramScanKeys = metrics.FastAnalyzeHistogram.WithLabelValues(metrics.LblGeneral, "scan_keys")
)

func analyzeFastExec(exec *AnalyzeFastExec) *statistics.AnalyzeResults {
hists, cms, topNs, fms, err := exec.buildStats()
if err != nil {
Expand Down
14 changes: 0 additions & 14 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"github.com/pingcap/tidb/expression/aggregation"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
Expand Down Expand Up @@ -75,19 +74,6 @@ import (
"golang.org/x/exp/slices"
)

var (
executorCounterMergeJoinExec = metrics.ExecutorCounter.WithLabelValues("MergeJoinExec")
executorCountHashJoinExec = metrics.ExecutorCounter.WithLabelValues("HashJoinExec")
executorCounterHashAggExec = metrics.ExecutorCounter.WithLabelValues("HashAggExec")
executorStreamAggExec = metrics.ExecutorCounter.WithLabelValues("StreamAggExec")
executorCounterSortExec = metrics.ExecutorCounter.WithLabelValues("SortExec")
executorCounterTopNExec = metrics.ExecutorCounter.WithLabelValues("TopNExec")
executorCounterNestedLoopApplyExec = metrics.ExecutorCounter.WithLabelValues("NestedLoopApplyExec")
executorCounterIndexLookUpJoin = metrics.ExecutorCounter.WithLabelValues("IndexLookUpJoin")
executorCounterIndexLookUpExecutor = metrics.ExecutorCounter.WithLabelValues("IndexLookUpExecutor")
executorCounterIndexMergeReaderExecutor = metrics.ExecutorCounter.WithLabelValues("IndexMergeReaderExecutor")
)

// executorBuilder builds an Executor from a Plan.
// The InfoSchema must not change during execution.
type executorBuilder struct {
Expand Down
Loading