Skip to content

Commit 0e566d7

Browse files
committed
Implement log collection for errored runners
1 parent a95334c commit 0e566d7

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

iterative/resource_runner.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,10 @@ func resourceRunnerCreate(ctx context.Context, d *schema.ResourceData, m interfa
204204

205205
if logError != nil {
206206
return resource.RetryableError(fmt.Errorf("Waiting for the machine to accept connections... %s", logError))
207-
} else if !utils.IsReady(logEvents) {
208-
return resource.RetryableError(fmt.Errorf("Waiting for the runner to be ready... %s", logError))
207+
} else if utils.HasStatus(logEvents, "terminated") {
208+
return resource.NonRetryableError(fmt.Errorf("Failed to launch the runner!"))
209+
} else if !utils.HasStatus(logEvents, "ready") {
210+
return resource.RetryableError(fmt.Errorf("Waiting for the runner to be ready..."))
209211
}
210212

211213
return nil // The runner is ready.

iterative/utils/runner.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ func ParseLogEvent(logEvent string) (LogEvent, error) {
2222
return result, err
2323
}
2424

25-
// IsReady checks whether a runner is ready or not by parsing the JSONL records from the logs it produces.
26-
func IsReady(logs string) bool {
25+
// HasStatus checks whether a runner is has reported the given status or not by parsing the JSONL records from the logs it produces
26+
func HasStatus(logs string, status string) bool {
2727
scanner := bufio.NewScanner(strings.NewReader(logs))
2828
for scanner.Scan() {
2929
line := scanner.Text()
3030
// Extract the JSON between curly braces from the log line.
3131
record := regexp.MustCompile(`\{.+\}`).Find([]byte(line))
3232
// Try to parse the retrieved JSON string into a LogEvent structure.
3333
if event, err := ParseLogEvent(string(record)); err == nil {
34-
if event.Status == "ready" {
34+
if event.Status == status {
3535
return true
3636
}
3737
}

iterative/utils/runner_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ func TestReadinessCheck(t *testing.T) {
1212
-- Logs begin at Wed 2021-01-20 00:25:37 UTC, end at Fri 2021-02-26 15:37:56 UTC. --
1313
Feb 26 15:37:20 ip-172-31-6-188 cml.sh[2203]: {"level":"info","time":"···","repo":"···","status":"ready"}
1414
`
15-
assert.True(t, IsReady(logString))
15+
assert.True(t, HasStatus(logString, "ready"))
1616
})
1717

1818
t.Run("Runner log not containing a readiness message should not be considered ready", func(t *testing.T) {
1919
logString := `
2020
-- Logs begin at Wed 2021-01-20 00:25:37 UTC, end at Fri 2021-02-26 15:37:56 UTC. --
2121
Feb 26 15:37:20 ip-172-31-6-188 cml.sh[2203]: {"level":"info","time":"···","repo":"···"}
2222
`
23-
assert.False(t, IsReady(logString))
23+
assert.False(t, HasStatus(logString, "ready"))
2424
})
2525
}

0 commit comments

Comments
 (0)