Skip to content

Commit

Permalink
tail collector logs on non-zero exit
Browse files Browse the repository at this point in the history
  • Loading branch information
robbycochran committed Aug 21, 2024
1 parent 0c3ec53 commit c436b09
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions integration-tests/pkg/collector/collector_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package collector

import (
"encoding/json"
"fmt"
"strings"

"golang.org/x/exp/maps"
Expand Down Expand Up @@ -94,16 +95,22 @@ func (c *DockerCollectorManager) TearDown() error {
}

if !isRunning {
c.captureLogs("collector")
logs, logsErr := c.captureLogs("collector")
logsEnd := logs
if logsErr == nil {
logsSplit := strings.Split(logs, "\n")
logsEnd = strings.Join(logsSplit[max(0, len(logsSplit)-24):], "\n")
logsEnd = fmt.Sprintf("\ncollector logs:\n%s\n", logsEnd)
}
// Check if collector container segfaulted or exited with error
exitCode, err := c.executor.ExitCode(executor.ContainerFilter{
Name: "collector",
})
if err != nil {
return log.Error("Failed to get container exit code: %s", err)
return fmt.Errorf("Failed to get container exit code%s: %w", logsEnd, err)
}
if exitCode != 0 {
return log.Error("Collector container has non-zero exit code (%d)", exitCode)
return fmt.Errorf("Collector container has non-zero exit code (%d)%s", exitCode, logsEnd)
}
} else {
c.stopContainer("collector")
Expand Down

0 comments on commit c436b09

Please sign in to comment.