Skip to content

Commit cd0e9fa

Browse files
Improve composer sweeper logging, fallthrough to deletion case (#4243) (#2726)
Signed-off-by: Modular Magician <[email protected]>
1 parent 91342da commit cd0e9fa

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

.changelog/4243.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```

google-beta/resource_composer_environment_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -940,39 +940,45 @@ func testSweepComposerEnvironments(config *Config) error {
940940
}
941941

942942
if len(found.Environments) == 0 {
943-
log.Printf("No environment need to be cleaned up")
943+
log.Printf("composer: no environments need to be cleaned up")
944944
return nil
945945
}
946946

947+
log.Printf("composer: %d environments need to be cleaned up", len(found.Environments))
948+
947949
var allErrors error
948950
for _, e := range found.Environments {
949951
createdAt, err := time.Parse(time.RFC3339Nano, e.CreateTime)
950952
if err != nil {
951-
return fmt.Errorf("[ERROR] Environment %q has invalid create time %q", e.Name, e.CreateTime)
953+
return fmt.Errorf("composer: environment %q has invalid create time %q", e.Name, e.CreateTime)
952954
}
953955
// Skip environments that were created in same day
954956
// This sweeper should really only clean out very old environments.
955957
if time.Since(createdAt) < time.Hour*24 {
958+
log.Printf("composer: skipped environment %q, it was created today", e.Name)
956959
continue
957960
}
958961

959962
switch e.State {
960963
case "CREATING":
964+
fallthrough
961965
case "UPDATING":
962-
log.Printf("Skipping pending Environment %q with state %q", e.Name, e.State)
966+
log.Printf("composer: skipping pending Environment %q with state %q", e.Name, e.State)
963967
case "DELETING":
964-
log.Printf("Skipping pending Environment %q that is currently deleting", e.Name)
968+
log.Printf("composer: skipping pending Environment %q that is currently deleting", e.Name)
965969
case "RUNNING":
970+
fallthrough
966971
case "ERROR":
972+
fallthrough
967973
default:
968974
op, deleteErr := config.NewComposerClient(config.userAgent).Projects.Locations.Environments.Delete(e.Name).Do()
969975
if deleteErr != nil {
970-
allErrors = multierror.Append(allErrors, fmt.Errorf("Unable to delete environment %q: %s", e.Name, deleteErr))
976+
allErrors = multierror.Append(allErrors, fmt.Errorf("composer: unable to delete environment %q: %s", e.Name, deleteErr))
971977
continue
972978
}
973979
waitErr := composerOperationWaitTime(config, op, config.Project, "Sweeping old test environments", config.userAgent, 10*time.Minute)
974980
if waitErr != nil {
975-
allErrors = multierror.Append(allErrors, fmt.Errorf("Unable to delete environment %q: %s", e.Name, waitErr))
981+
allErrors = multierror.Append(allErrors, fmt.Errorf("composer: unable to delete environment %q: %s", e.Name, waitErr))
976982
}
977983
}
978984
}

0 commit comments

Comments
 (0)