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

metric: replace QueryDurationHistogram's "general" type to more detail stmt type #8819

Merged
merged 6 commits into from
Dec 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do QueryDurationHistogram and QueryTotalCounter use the different label

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a "historical reasons", old code choose COMMAND as count label and none label for the duration,

To add duration label, IMO stmtType(like insert/select) is more useful than command(like COM_QUERY).

why don't change QueryTotalCounter is maybe sometime we need that, and we also have another StmtNodeCounter to cover "count by stmtType" although has some litte different.

so after this we can see:

  • count of command -> QueryTotalCounter
  • count of stmt -> StmtNodeCounter
  • duration of query -> QueryDurationHistogram and optional switch to stmtType view

:D

}

// 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