Skip to content

Commit

Permalink
metric: replace QueryDurationHistogram's "general" type to more detai…
Browse files Browse the repository at this point in the history
…l stmt type (pingcap#8819)
  • Loading branch information
lysu authored and yu34po committed Jan 2, 2019
1 parent 4ac064d commit 860e573
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
log "github.com/sirupsen/logrus"
)

// processinfoSetter is the interface use to set current running process info.
type processinfoSetter interface {
SetProcessInfo(string, time.Time, byte)
}
Expand Down Expand Up @@ -235,6 +236,7 @@ func (a *ExecStmt) Exec(ctx context.Context) (sqlexec.RecordSet, error) {
}
// Update processinfo, ShowProcess() will use it.
pi.SetProcessInfo(sql, time.Now(), cmd)
a.Ctx.GetSessionVars().StmtCtx.StmtType = GetStmtLabel(a.StmtNode)
}

// If the executor doesn't return any result to the client, we execute it without delay.
Expand Down
7 changes: 6 additions & 1 deletion server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,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.
Expand Down
1 change: 1 addition & 0 deletions sessionctx/stmtctx/stmtctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type StatementContext struct {
IndexIDs []int64
NowTs time.Time
SysTs time.Time
StmtType string
}

// AddAffectedRows adds affected rows.
Expand Down

0 comments on commit 860e573

Please sign in to comment.