From 9b157b77df88114a34fa3092f7b9e51aff3e321d Mon Sep 17 00:00:00 2001 From: shanth96 Date: Wed, 7 Aug 2024 12:48:10 -0400 Subject: [PATCH] add moar tracing --- go/vt/vtgate/executor.go | 4 ++++ go/vt/vtgate/planbuilder/builder.go | 6 ++++++ go/vt/vttablet/tabletserver/query_engine.go | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/go/vt/vtgate/executor.go b/go/vt/vtgate/executor.go index d1e555bf990..0854f74631a 100644 --- a/go/vt/vtgate/executor.go +++ b/go/vt/vtgate/executor.go @@ -1132,14 +1132,18 @@ func (e *Executor) buildStatement( reservedVars *sqlparser.ReservedVars, bindVarNeeds *sqlparser.BindVarNeeds, ) (*engine.Plan, error) { + buildSpan, ctx := trace.NewSpan(ctx, "buildStatement.build") plan, err := planbuilder.BuildFromStmt(ctx, query, stmt, reservedVars, vcursor, bindVarNeeds, enableOnlineDDL, enableDirectDDL) if err != nil { return nil, err } + buildSpan.Finish() plan.Warnings = vcursor.warnings vcursor.warnings = nil + validSpan, _ := trace.NewSpan(ctx, "buildStatement.valid") + defer validSpan.Finish() err = e.checkThatPlanIsValid(stmt, plan) return plan, err } diff --git a/go/vt/vtgate/planbuilder/builder.go b/go/vt/vtgate/planbuilder/builder.go index e79e19ee96b..c00e47496a4 100644 --- a/go/vt/vtgate/planbuilder/builder.go +++ b/go/vt/vtgate/planbuilder/builder.go @@ -23,6 +23,7 @@ import ( "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/test/vschemawrapper" + "vitess.io/vitess/go/trace" "vitess.io/vitess/go/vt/key" querypb "vitess.io/vitess/go/vt/proto/query" topodatapb "vitess.io/vitess/go/vt/proto/topodata" @@ -158,10 +159,15 @@ func buildRoutePlan(stmt sqlparser.Statement, reservedVars *sqlparser.ReservedVa func createInstructionFor(ctx context.Context, query string, stmt sqlparser.Statement, reservedVars *sqlparser.ReservedVars, vschema plancontext.VSchema, enableOnlineDDL, enableDirectDDL bool) (*planResult, error) { switch stmt := stmt.(type) { case *sqlparser.Select, *sqlparser.Insert, *sqlparser.Update, *sqlparser.Delete: + getSpan, ctx := trace.NewSpan(ctx, "createInstruction.getPlanner") configuredPlanner, err := getConfiguredPlanner(vschema, stmt, query) if err != nil { return nil, err } + getSpan.Finish() + + buildRouteSpan, _ := trace.NewSpan(ctx, "createInstruction.buildRoutePlan") + defer buildRouteSpan.Finish() return buildRoutePlan(stmt, reservedVars, vschema, configuredPlanner) case *sqlparser.Union: configuredPlanner, err := getConfiguredPlanner(vschema, stmt, query) diff --git a/go/vt/vttablet/tabletserver/query_engine.go b/go/vt/vttablet/tabletserver/query_engine.go index b87c5cf97ba..80f9e0b71be 100644 --- a/go/vt/vttablet/tabletserver/query_engine.go +++ b/go/vt/vttablet/tabletserver/query_engine.go @@ -385,9 +385,13 @@ func (qe *QueryEngine) GetPlan(ctx context.Context, logStats *tabletenv.LogStats var plan *TabletPlan var err error + schemaSpan, ctx := trace.NewSpan(ctx, "GetPlan.schemaLoad") curSchema := qe.schema.Load() + schemaSpan.Finish() if skipQueryPlanCache { + getPlanSpan, _ := trace.NewSpan(ctx, "GetPlan.getPlan") + defer getPlanSpan.Finish() plan, err = qe.getPlan(curSchema, sql) } else { plan, logStats.CachedPlan, err = qe.plans.GetOrLoad(PlanCacheKey(sql), curSchema.epoch, func() (*TabletPlan, error) {