diff --git a/integration-tests/pkg/collector/collector_docker.go b/integration-tests/pkg/collector/collector_docker.go index 3c961c1361..8e0e558235 100644 --- a/integration-tests/pkg/collector/collector_docker.go +++ b/integration-tests/pkg/collector/collector_docker.go @@ -2,6 +2,7 @@ package collector import ( "encoding/json" + "fmt" "strings" "golang.org/x/exp/maps" @@ -89,20 +90,26 @@ func (c *DockerCollectorManager) Launch() error { func (c *DockerCollectorManager) TearDown() error { isRunning, err := c.IsRunning() if err != nil { - return log.Error("Unable to check if container is running: %s", err) + return fmt.Errorf("Unable to check if container is running: %s", err) } 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") diff --git a/integration-tests/suites/base.go b/integration-tests/suites/base.go index a40037e111..e81a2a2da7 100644 --- a/integration-tests/suites/base.go +++ b/integration-tests/suites/base.go @@ -91,16 +91,7 @@ func (s *IntegrationTestSuiteBase) StartCollector(disableGRPC bool, options *col _, err := s.waitForContainerToBecomeHealthy( "collector", s.Collector().ContainerID(), - defaultWaitTickSeconds, 5*time.Minute) - if err != nil { - // try to grab logs - logs, logsErr := s.containerLogs(s.Collector().ContainerID()) - logsEnd := logs - if logsErr == nil { - logsEnd = strings.Join(strings.Split(logs, "\n")[max(0, len(strings.Split(logs, "\n"))-8):], "\n") - } - err = fmt.Errorf("%s\n: %w", logsEnd, err) - } + defaultWaitTickSeconds, 1*time.Minute) s.Require().NoError(err) } else { log.Error("No HealthCheck found, do not wait for collector to become healthy")