diff --git a/provisioner/terraform/executor.go b/provisioner/terraform/executor.go index 3d9270a6ddbab..b132b78982bea 100644 --- a/provisioner/terraform/executor.go +++ b/provisioner/terraform/executor.go @@ -325,9 +325,7 @@ func (e *executor) plan(ctx, killCtx context.Context, env, vars []string, logr l <-doneErr }() - endStage := e.timings.startStage(database.ProvisionerJobTimingStagePlan) err := e.execWriteOutput(ctx, killCtx, args, env, outWriter, errWriter) - endStage(err) if err != nil { return nil, xerrors.Errorf("terraform plan: %w", err) } @@ -390,7 +388,7 @@ func (e *executor) plan(ctx, killCtx context.Context, env, vars []string, logr l Parameters: state.Parameters, Resources: state.Resources, ExternalAuthProviders: state.ExternalAuthProviders, - Timings: append(e.timings.aggregate(), graphTimings.aggregate()...), + Timings: graphTimings.aggregate(), Presets: state.Presets, Plan: planJSON, ResourceReplacements: resReps, @@ -599,9 +597,7 @@ func (e *executor) apply( }() // `terraform apply` - endStage := e.timings.startStage(database.ProvisionerJobTimingStageApply) err := e.execWriteOutput(ctx, killCtx, args, env, outWriter, errWriter) - endStage(err) if err != nil { return nil, xerrors.Errorf("terraform apply: %w", err) } @@ -617,13 +613,11 @@ func (e *executor) apply( return nil, xerrors.Errorf("read statefile %q: %w", statefilePath, err) } - agg := e.timings.aggregate() return &proto.ApplyComplete{ Parameters: state.Parameters, Resources: state.Resources, ExternalAuthProviders: state.ExternalAuthProviders, State: stateContent, - Timings: agg, AiTasks: state.AITasks, }, nil } diff --git a/provisioner/terraform/provision.go b/provisioner/terraform/provision.go index c99ee55ad8cc6..5fedf16c21eb1 100644 --- a/provisioner/terraform/provision.go +++ b/provisioner/terraform/provision.go @@ -160,14 +160,16 @@ func (s *server) Plan( return provisionersdk.PlanErrorf("plan vars: %s", err) } + endPlanStage := e.timings.startStage(database.ProvisionerJobTimingStagePlan) resp, err := e.plan(ctx, killCtx, env, vars, sess, request) + endPlanStage(err) if err != nil { return provisionersdk.PlanErrorf("%s", err.Error()) } // Prepend init timings since they occur prior to plan timings. // Order is irrelevant; this is merely indicative. - resp.Timings = append(initTimings.aggregate(), resp.Timings...) // mergeInitTimings(initTimings.aggregate(), resp.Timings) + resp.Timings = append(resp.Timings, append(initTimings.aggregate(), e.timings.aggregate()...)...) resp.Modules = modules return resp } @@ -204,9 +206,11 @@ func (s *server) Apply( return provisionersdk.ApplyErrorf("provision env: %s", err) } env = otelEnvInject(ctx, env) + endStage := e.timings.startStage(database.ProvisionerJobTimingStageApply) resp, err := e.apply( ctx, killCtx, env, sess, ) + endStage(err) if err != nil { errorMessage := err.Error() // Terraform can fail and apply and still need to store it's state. @@ -217,6 +221,7 @@ func (s *server) Apply( Error: errorMessage, } } + resp.Timings = e.timings.aggregate() return resp }