@@ -293,93 +293,33 @@ func TerraformPlanImpl(ctx context.Context, cmd *cobra.Command, oi sdp.OvermindI
293
293
uploadChangesSpinner .Success ()
294
294
295
295
///////////////////////////////////////////////////////////////////
296
- // calculate blast radius and risks
296
+ // Upload the planned changes to the API
297
297
///////////////////////////////////////////////////////////////////
298
298
299
- blastRadiusSpinner , _ := pterm .DefaultSpinner .WithWriter (multi .NewWriter ()).Start ("Calculating Blast Radius " )
299
+ uploadPlannedChange , _ := pterm .DefaultSpinner .WithWriter (multi .NewWriter ()).Start ("Uploading planned changes " )
300
300
log .WithField ("change" , changeUuid ).Debug ("Uploading planned changes" )
301
301
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 {
304
304
ChangeUUID : changeUuid [:],
305
305
ChangingItems : mappingResponse .GetItemDiffs (),
306
306
},
307
307
})
308
308
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 ))
310
310
return nil
311
311
}
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" )
360
313
361
314
changeUrl := * oi .FrontendUrl
362
315
changeUrl .Path = fmt .Sprintf ("%v/changes/%v/blast-radius" , changeUrl .Path , changeUuid )
363
316
log .WithField ("change-url" , changeUrl .String ()).Info ("Change ready" )
364
317
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
-
378
318
///////////////////////////////////////////////////////////////////
379
- // wait for risk calculation to happen
319
+ // wait for change analysis to complete
380
320
///////////////////////////////////////////////////////////////////
381
321
382
- riskSpinner , _ := pterm .DefaultSpinner .WithWriter (multi .NewWriter ()).Start ("Calculating Risks " )
322
+ changeAnalysisSpinner , _ := pterm .DefaultSpinner .WithWriter (multi .NewWriter ()).Start ("Change Analysis " )
383
323
384
324
var riskRes * connect.Response [sdp.GetChangeRisksResponse ]
385
325
milestoneSpinners := []* pterm.SpinnerPrinter {}
@@ -390,7 +330,7 @@ func TerraformPlanImpl(ctx context.Context, cmd *cobra.Command, oi sdp.OvermindI
390
330
},
391
331
})
392
332
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 ))
394
334
return nil
395
335
}
396
336
@@ -421,37 +361,30 @@ func TerraformPlanImpl(ctx context.Context, cmd *cobra.Command, oi sdp.OvermindI
421
361
422
362
status := riskRes .Msg .GetChangeRiskMetadata ().GetChangeAnalysisStatus ().GetStatus ()
423
363
if status == sdp .ChangeAnalysisStatus_STATUS_UNSPECIFIED || status == sdp .ChangeAnalysisStatus_STATUS_INPROGRESS {
424
- if ! riskSpinner .IsActive {
364
+ if ! changeAnalysisSpinner .IsActive {
425
365
// restart after a Fail()
426
- riskSpinner , _ = riskSpinner .Start ("Calculating Risks " )
366
+ changeAnalysisSpinner , _ = changeAnalysisSpinner .Start ("Change Analysis " )
427
367
}
428
368
// retry
429
369
time .Sleep (time .Second )
430
370
431
371
} 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" )
433
373
} else {
434
374
// it's done
435
- skipChangeMessage .Store (true )
436
- riskSpinner .Success ()
375
+ changeAnalysisSpinner .Success ()
437
376
break
438
377
}
439
378
}
440
-
441
379
// Submit milestone for tracing
442
380
if cmdSpan != nil {
443
- cmdSpan .AddEvent ("Risk calculation finished" , trace .WithAttributes (
381
+ cmdSpan .AddEvent ("Change Analysis finished" , trace .WithAttributes (
444
382
attribute .Int ("ovm.risks.count" , len (riskRes .Msg .GetChangeRiskMetadata ().GetRisks ())),
445
383
attribute .String ("ovm.change.uuid" , changeUuid .String ()),
446
384
))
447
385
}
448
386
449
387
bits := []string {}
450
- if blastRadiusItems > 0 {
451
- bits = append (bits , styleH1 ().Render ("Blast Radius" ))
452
- bits = append (bits , fmt .Sprintf ("\n Items: %v\n Edges: %v\n " , blastRadiusItems , blastRadiusEdges ))
453
- }
454
-
455
388
risks := riskRes .Msg .GetChangeRiskMetadata ().GetRisks ()
456
389
bits = append (bits , "" )
457
390
bits = append (bits , "" )
0 commit comments