Skip to content

Commit

Permalink
update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
robbycochran committed Aug 21, 2024
1 parent fb27f7d commit 9c5385b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
15 changes: 11 additions & 4 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 @@ -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")
Expand Down
11 changes: 1 addition & 10 deletions integration-tests/suites/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 9c5385b

Please sign in to comment.