Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Collect additional logs with CAPD log collector #11083

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading