Skip to content

Commit

Permalink
plugin: add "exec start-time" to GeneralEvent (#11293) (#11322)
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored and zz-jason committed Jul 18, 2019
1 parent 7ef017f commit 3d7da06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,8 @@ func (a *ExecStmt) logAudit() {
audit := plugin.DeclareAuditManifest(p.Manifest)
if audit.OnGeneralEvent != nil {
cmd := mysql.Command2Str[byte(atomic.LoadUint32(&a.Ctx.GetSessionVars().CommandValue))]
audit.OnGeneralEvent(context.Background(), sessVars, plugin.Log, cmd)
ctx := context.WithValue(context.Background(), plugin.ExecStartTimeCtxKey, a.StartTime)
audit.OnGeneralEvent(ctx, sessVars, plugin.Log, cmd)
}
return nil
})
Expand Down
5 changes: 5 additions & 0 deletions plugin/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,8 @@ type AuditManifest struct {
// OnParseEvent will be called around parse logic.
OnParseEvent func(ctx context.Context, sctx *variable.SessionVars, event ParseEvent) error
}

const (
// ExecStartTimeCtxKey indicates stmt start execution time.
ExecStartTimeCtxKey = "ExecStartTime"
)

0 comments on commit 3d7da06

Please sign in to comment.