Skip to content
Open
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
8 changes: 1 addition & 7 deletions provisioner/terraform/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion provisioner/terraform/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand All @@ -217,6 +221,7 @@ func (s *server) Apply(
Error: errorMessage,
}
}
resp.Timings = e.timings.aggregate()
return resp
}

Expand Down
Loading