From bedd1b07b02932a3f73e241dbf63494dca20e600 Mon Sep 17 00:00:00 2001 From: lysu Date: Thu, 18 Jul 2019 19:21:01 +0800 Subject: [PATCH] plugin: add "exec start-time" to GeneralEvent (#11293) --- executor/adapter.go | 3 ++- plugin/audit.go | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/executor/adapter.go b/executor/adapter.go index ee7bc38441d1a..a08c26ab11abf 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -608,7 +608,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 }) diff --git a/plugin/audit.go b/plugin/audit.go index 603b7e0f8982f..f1471562fc657 100644 --- a/plugin/audit.go +++ b/plugin/audit.go @@ -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" +)