Skip to content

Commit

Permalink
Merge pull request #33 from rightscale/fix_run_log_issues
Browse files Browse the repository at this point in the history
Handle eventual consistency issues with fpt run log output
  • Loading branch information
douglaswth authored Mar 1, 2022
2 parents bcb580b + 1f7b1ac commit eefe3f8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
5 changes: 3 additions & 2 deletions cmd/fpt/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Unreleased Changes
------------------
v1.4.0 / 2022-03-01
-------------------
* Add support for `atob` and `btoa` JavaScript Base64 functions in `fpt script`
* Handle eventual consistency issues with `fpt run` log output which could result in panics

v1.3.0 / 2021-03-01
-------------------
Expand Down
37 changes: 20 additions & 17 deletions cmd/fpt/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,28 @@ func policyTemplateRun(ctx context.Context, cli policy.Client, file string, runO
}
lastStatus = status

log, logErr := cli.ShowAppliedPolicyLog(ctx, ap.ID, lastEtag)
if logErr != nil {
// technically the Goa client should not consider 304 an error
if strings.Contains(logErr.Error(), "invalid response code 304") {
goto checkStatus
if !noLog {
log, logErr := cli.ShowAppliedPolicyLog(ctx, ap.ID, lastEtag)
if logErr != nil {
// technically the Goa client should not consider 304 an error
if strings.Contains(logErr.Error(), "invalid response code 304") {
goto checkStatus
}
// the log may not be available yet so we retry 404s
if gse, ok := logErr.(*goa.ServiceError); ok && gse.Name == "not_found" {
goto checkStatus
}
return logErr
}
// the log may not be available yet so we retry 404s
if gse, ok := logErr.(*goa.ServiceError); ok && gse.Name == "not_found" {
goto checkStatus
}
return logErr
}

if *log.Etag != lastEtag {
lastSize := len(lastLog)
lastEtag = *log.Etag
lastLog = *log.ResponseBody
if !noLog {
fmt.Print(lastLog[lastSize:])
if *log.Etag != lastEtag {
lastSize := len(lastLog)
lastEtag = *log.Etag
// only print new log data (due to eventual consistency issues, a shorter log may be returned)
if lastSize <= len(*log.ResponseBody) {
lastLog = *log.ResponseBody
fmt.Print(lastLog[lastSize:])
}
}
}

Expand Down

0 comments on commit eefe3f8

Please sign in to comment.