Skip to content

Commit 5bdfd00

Browse files
tphoneyactions-user
authored andcommitted
(fix) cli doesnt wait on the blast radius calculation (#775)
re https://github.com/overmindtech/workspace/issues/766 Things of note, ### submit plan tested as part of the e2e interactive tests in lost pixel tested here https://api.df.overmind-demo.com/area51/api-server/changes/1c0eb6ad-bd7b-4c4c-bd5b-4fc6bb9da283 with https://df.overmind-demo.com/changes/1c0eb6ad-bd7b-4c4c-bd5b-4fc6bb9da283 - do not print the blast radius information - do not wait for blast radius calculation to complete ### terraform plan tested as part of the e2e interactive tests in lost pixel - do not print the blast radius information - wait for change analysis to complete ### get change - operates as normal ![image](https://github.com/user-attachments/assets/be12e985-630f-42ab-ba70-1d0f8c8740b8) ### Actions - submit plan + fetch change action, works as expected, we rely on unchanged behaviour, where submit plan prints the change url, then it is used by get change **### Please check lost pixel ⚠️** GitOrigin-RevId: 05470d7c4f975b346bfb69a49118ddf1e34826ec
1 parent ae53b54 commit 5bdfd00

File tree

3 files changed

+18
-108
lines changed

3 files changed

+18
-108
lines changed

.github/e2eplan.tape

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ Type@1ms "overmind terraform plan -- -out tfplan"
1717
Enter
1818
Sleep 2
1919
Enter
20-
Sleep 70
20+
Sleep 80
2121
Screenshot e2e/plan.png

cmd/changes_submit_plan.go

+3-26
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"os/exec"
99
"os/user"
1010
"strings"
11-
"time"
1211

1312
"connectrpc.com/connect"
1413
"github.com/google/uuid"
@@ -236,8 +235,8 @@ func SubmitPlan(cmd *cobra.Command, args []string) error {
236235
}
237236
}
238237

239-
resultStream, err := client.UpdatePlannedChanges(ctx, &connect.Request[sdp.UpdatePlannedChangesRequest]{
240-
Msg: &sdp.UpdatePlannedChangesRequest{
238+
_, err = client.StartChangeAnalysis(ctx, &connect.Request[sdp.StartChangeAnalysisRequest]{
239+
Msg: &sdp.StartChangeAnalysisRequest{
241240
ChangeUUID: changeUuid[:],
242241
ChangingItems: plannedChanges,
243242
BlastRadiusConfigOverride: blastRadiusConfigOverride,
@@ -248,29 +247,7 @@ func SubmitPlan(cmd *cobra.Command, args []string) error {
248247
return loggedError{
249248
err: err,
250249
fields: lf,
251-
message: "Failed to update planned changes",
252-
}
253-
}
254-
255-
last_log := time.Now()
256-
first_log := true
257-
for resultStream.Receive() {
258-
msg := resultStream.Msg()
259-
260-
// log the first message and at most every 250ms during discovery
261-
// to avoid spanning the cli output
262-
time_since_last_log := time.Since(last_log)
263-
if first_log || msg.GetState() != sdp.UpdatePlannedChangesResponse_STATE_DISCOVERING || time_since_last_log > 250*time.Millisecond {
264-
log.WithContext(ctx).WithFields(lf).WithField("msg", msg).Info("Status update")
265-
last_log = time.Now()
266-
first_log = false
267-
}
268-
}
269-
if resultStream.Err() != nil {
270-
return loggedError{
271-
err: resultStream.Err(),
272-
fields: lf,
273-
message: "Error streaming results",
250+
message: "Failed to start change analysis",
274251
}
275252
}
276253

cmd/terraform_plan.go

+14-81
Original file line numberDiff line numberDiff line change
@@ -293,93 +293,33 @@ func TerraformPlanImpl(ctx context.Context, cmd *cobra.Command, oi sdp.OvermindI
293293
uploadChangesSpinner.Success()
294294

295295
///////////////////////////////////////////////////////////////////
296-
// calculate blast radius and risks
296+
// Upload the planned changes to the API
297297
///////////////////////////////////////////////////////////////////
298298

299-
blastRadiusSpinner, _ := pterm.DefaultSpinner.WithWriter(multi.NewWriter()).Start("Calculating Blast Radius")
299+
uploadPlannedChange, _ := pterm.DefaultSpinner.WithWriter(multi.NewWriter()).Start("Uploading planned changes")
300300
log.WithField("change", changeUuid).Debug("Uploading planned changes")
301301

302-
resultStream, err := client.UpdatePlannedChanges(ctx, &connect.Request[sdp.UpdatePlannedChangesRequest]{
303-
Msg: &sdp.UpdatePlannedChangesRequest{
302+
_, err = client.StartChangeAnalysis(ctx, &connect.Request[sdp.StartChangeAnalysisRequest]{
303+
Msg: &sdp.StartChangeAnalysisRequest{
304304
ChangeUUID: changeUuid[:],
305305
ChangingItems: mappingResponse.GetItemDiffs(),
306306
},
307307
})
308308
if err != nil {
309-
blastRadiusSpinner.Fail(fmt.Sprintf("Calculating Blast Radius: failed to update planned changes: %v", err))
309+
uploadPlannedChange.Fail(fmt.Sprintf("Uploading planned changes: failed to update: %v", err))
310310
return nil
311311
}
312-
313-
// log the first message and at most every 250ms during discovery to avoid
314-
// spamming the cli output
315-
last_log := time.Now()
316-
first_log := true
317-
var msg *sdp.UpdatePlannedChangesResponse
318-
var blastRadiusItems uint32
319-
var blastRadiusEdges uint32
320-
for resultStream.Receive() {
321-
msg = resultStream.Msg()
322-
323-
time_since_last_log := time.Since(last_log)
324-
if first_log || msg.GetState() != sdp.UpdatePlannedChangesResponse_STATE_DISCOVERING || time_since_last_log > 250*time.Millisecond {
325-
log.WithField("msg", msg).Trace("Status update")
326-
last_log = time.Now()
327-
first_log = false
328-
}
329-
stateLabel := "unknown"
330-
switch msg.GetState() {
331-
case sdp.UpdatePlannedChangesResponse_STATE_UNSPECIFIED:
332-
stateLabel = "unknown"
333-
case sdp.UpdatePlannedChangesResponse_STATE_DISCOVERING:
334-
stateLabel = "discovering blast radius"
335-
case sdp.UpdatePlannedChangesResponse_STATE_SAVING:
336-
stateLabel = "saving"
337-
case sdp.UpdatePlannedChangesResponse_STATE_DONE:
338-
stateLabel = "done"
339-
}
340-
blastRadiusItems = msg.GetNumItems()
341-
blastRadiusEdges = msg.GetNumEdges()
342-
blastRadiusSpinner.UpdateText(fmt.Sprintf("Calculating Blast Radius: %v", snapshotDetail(stateLabel, blastRadiusItems, blastRadiusEdges)))
343-
}
344-
if resultStream.Err() != nil {
345-
blastRadiusSpinner.Fail(fmt.Sprintf("Calculating Blast Radius: error streaming results: %v", resultStream.Err()))
346-
return nil
347-
}
348-
blastRadiusSpinner.Success("Calculating Blast Radius: done")
349-
350-
// Add tracing that the blast radius has finished
351-
if cmdSpan != nil {
352-
cmdSpan.AddEvent("Blast radius calculation finished", trace.WithAttributes(
353-
attribute.Int("ovm.blast_radius.items", int(msg.GetNumItems())),
354-
attribute.Int("ovm.blast_radius.edges", int(msg.GetNumEdges())),
355-
attribute.String("ovm.blast_radius.state", msg.GetState().String()),
356-
attribute.StringSlice("ovm.blast_radius.errors", msg.GetErrors()),
357-
attribute.String("ovm.change.uuid", changeUuid.String()),
358-
))
359-
}
312+
uploadPlannedChange.Success("Uploaded planned changes: Done")
360313

361314
changeUrl := *oi.FrontendUrl
362315
changeUrl.Path = fmt.Sprintf("%v/changes/%v/blast-radius", changeUrl.Path, changeUuid)
363316
log.WithField("change-url", changeUrl.String()).Info("Change ready")
364317

365-
skipChangeMessage := atomic.Bool{}
366-
go func() {
367-
time.Sleep(1500 * time.Millisecond)
368-
if !skipChangeMessage.Load() {
369-
changeWaitWriter := multi.NewWriter()
370-
// only show this if risk calculation hasn't already finished
371-
_, err := changeWaitWriter.Write([]byte(fmt.Sprintf(" │ Check the blast radius graph while you wait:\n │ %v\n", changeUrl.String())))
372-
if err != nil {
373-
log.WithError(err).Error("error writing to change wait writer")
374-
}
375-
}
376-
}()
377-
378318
///////////////////////////////////////////////////////////////////
379-
// wait for risk calculation to happen
319+
// wait for change analysis to complete
380320
///////////////////////////////////////////////////////////////////
381321

382-
riskSpinner, _ := pterm.DefaultSpinner.WithWriter(multi.NewWriter()).Start("Calculating Risks")
322+
changeAnalysisSpinner, _ := pterm.DefaultSpinner.WithWriter(multi.NewWriter()).Start("Change Analysis")
383323

384324
var riskRes *connect.Response[sdp.GetChangeRisksResponse]
385325
milestoneSpinners := []*pterm.SpinnerPrinter{}
@@ -390,7 +330,7 @@ func TerraformPlanImpl(ctx context.Context, cmd *cobra.Command, oi sdp.OvermindI
390330
},
391331
})
392332
if err != nil {
393-
riskSpinner.Fail(fmt.Sprintf("Calculating Risks: failed to get change risks: %v", err))
333+
changeAnalysisSpinner.Fail(fmt.Sprintf("Change Analysis failed to get change risks: %v", err))
394334
return nil
395335
}
396336

@@ -421,37 +361,30 @@ func TerraformPlanImpl(ctx context.Context, cmd *cobra.Command, oi sdp.OvermindI
421361

422362
status := riskRes.Msg.GetChangeRiskMetadata().GetChangeAnalysisStatus().GetStatus()
423363
if status == sdp.ChangeAnalysisStatus_STATUS_UNSPECIFIED || status == sdp.ChangeAnalysisStatus_STATUS_INPROGRESS {
424-
if !riskSpinner.IsActive {
364+
if !changeAnalysisSpinner.IsActive {
425365
// restart after a Fail()
426-
riskSpinner, _ = riskSpinner.Start("Calculating Risks")
366+
changeAnalysisSpinner, _ = changeAnalysisSpinner.Start("Change Analysis")
427367
}
428368
// retry
429369
time.Sleep(time.Second)
430370

431371
} else if status == sdp.ChangeAnalysisStatus_STATUS_ERROR {
432-
riskSpinner.Fail("Calculating Risks: waiting for a retry")
372+
changeAnalysisSpinner.Fail("Change Analysis: waiting for a retry")
433373
} else {
434374
// it's done
435-
skipChangeMessage.Store(true)
436-
riskSpinner.Success()
375+
changeAnalysisSpinner.Success()
437376
break
438377
}
439378
}
440-
441379
// Submit milestone for tracing
442380
if cmdSpan != nil {
443-
cmdSpan.AddEvent("Risk calculation finished", trace.WithAttributes(
381+
cmdSpan.AddEvent("Change Analysis finished", trace.WithAttributes(
444382
attribute.Int("ovm.risks.count", len(riskRes.Msg.GetChangeRiskMetadata().GetRisks())),
445383
attribute.String("ovm.change.uuid", changeUuid.String()),
446384
))
447385
}
448386

449387
bits := []string{}
450-
if blastRadiusItems > 0 {
451-
bits = append(bits, styleH1().Render("Blast Radius"))
452-
bits = append(bits, fmt.Sprintf("\nItems: %v\nEdges: %v\n", blastRadiusItems, blastRadiusEdges))
453-
}
454-
455388
risks := riskRes.Msg.GetChangeRiskMetadata().GetRisks()
456389
bits = append(bits, "")
457390
bits = append(bits, "")

0 commit comments

Comments
 (0)