Skip to content

Commit

Permalink
Collect additional logs with CAPD log collector
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandr Demicev <alexandr.demicev@suse.com>
  • Loading branch information
alexander-demicev committed Aug 23, 2024
1 parent c62c864 commit 9b7acec
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions test/framework/docker_logcollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ import (
)

// DockerLogCollector collect logs from a CAPD workload cluster.
type DockerLogCollector struct{}
type DockerLogCollector struct {
AdditionalLogs []AdditionalLogs
}

// AdditionalLogs is a struct to hold instruction for additional logs that need to be collected.
type AdditionalLogs struct {
OutputFileName string
Command string
Args []string
}

// machineContainerName return a container name using the same rule used in CAPD.
// NOTE: if the cluster name is already included in the machine name, the cluster name is not add thus
Expand Down Expand Up @@ -149,7 +158,8 @@ func (k DockerLogCollector) collectLogsFromNode(ctx context.Context, outputPath
return osExec.Command("tar", "--extract", "--file", tempfileName, "--directory", outputDir).Run() //nolint:gosec // We don't care about command injection here.
}
}
return errors.AggregateConcurrent([]func() error{

collectFuncs := []func() error{
execToPathFn(
"journal.log",
"journalctl", "--no-pager", "--output=short-precise",
Expand All @@ -175,7 +185,13 @@ func (k DockerLogCollector) collectLogsFromNode(ctx context.Context, outputPath
"journalctl", "--no-pager", "--output=short-precise", "-u", "containerd.service",
),
copyDirFn("/var/log/pods", "pods"),
})
}

for _, additionalLogs := range k.AdditionalLogs {
collectFuncs = append(collectFuncs, execToPathFn(additionalLogs.OutputFileName, additionalLogs.Command, additionalLogs.Args...))
}

return errors.AggregateConcurrent(collectFuncs)
}

// fileOnHost is a helper to create a file at path
Expand Down

0 comments on commit 9b7acec

Please sign in to comment.