From 199fac4b78dd2585264e7da1239d48e874687e4e Mon Sep 17 00:00:00 2001 From: lysu Date: Sat, 29 Dec 2018 19:36:16 +0800 Subject: [PATCH] metric: replace QueryDurationHistogram's "general" type to detail type (#8819) (#8875) --- executor/adapter.go | 2 ++ server/conn.go | 7 ++++++- sessionctx/stmtctx/stmtctx.go | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/executor/adapter.go b/executor/adapter.go index c313999e1c402..fa43702946a9d 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -41,6 +41,7 @@ import ( "golang.org/x/net/context" ) +// processinfoSetter is the interface use to set current running process info. type processinfoSetter interface { SetProcessInfo(string) } @@ -230,6 +231,7 @@ func (a *ExecStmt) Exec(ctx context.Context) (sqlexec.RecordSet, error) { } // Update processinfo, ShowProcess() will use it. pi.SetProcessInfo(sql) + a.Ctx.GetSessionVars().StmtCtx.StmtType = GetStmtLabel(a.StmtNode) } // If the executor doesn't return any result to the client, we execute it without delay. if e.Schema().Len() == 0 { diff --git a/server/conn.go b/server/conn.go index c6bdf41c8f3bc..e2a45b5b225c5 100644 --- a/server/conn.go +++ b/server/conn.go @@ -580,7 +580,12 @@ func (cc *clientConn) addMetrics(cmd byte, startTime time.Time, err error) { } else { metrics.QueryTotalCounter.WithLabelValues(label, "OK").Inc() } - metrics.QueryDurationHistogram.WithLabelValues(metrics.LblGeneral).Observe(time.Since(startTime).Seconds()) + stmtType := cc.ctx.GetSessionVars().StmtCtx.StmtType + sqlType := metrics.LblGeneral + if stmtType != "" { + sqlType = stmtType + } + metrics.QueryDurationHistogram.WithLabelValues(sqlType).Observe(time.Since(startTime).Seconds()) } // dispatch handles client request based on command which is the first byte of the data. diff --git a/sessionctx/stmtctx/stmtctx.go b/sessionctx/stmtctx/stmtctx.go index 1817f24396faf..eecb56d1ac05c 100644 --- a/sessionctx/stmtctx/stmtctx.go +++ b/sessionctx/stmtctx/stmtctx.go @@ -88,6 +88,7 @@ type StatementContext struct { RuntimeStatsColl *execdetails.RuntimeStatsColl TableIDs []int64 IndexIDs []int64 + StmtType string } // AddAffectedRows adds affected rows.