Skip to content
Open
Changes from 1 commit
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
37 changes: 37 additions & 0 deletions src/go/pt-k8s-debug-collector/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,43 @@ func (s *CollectorSuite) TestIndividualFiles() {
return in[:nl]
},
},
{
namespace: "pxc",
// If pod logs are exported as one file per container
name: "pxc_container_logs_split_by_container",
// tar -tf cluster-dump.tar.gz --wildcards 'cluster-dump/pxc/*/*.log'
cmd: []string{"tar", "-tf", "cluster-dump.tar.gz", "--wildcards", "cluster-dump/pxc/*/*.log"},
want: []string{"logrotate.log", "logs.log", "pxc-init.log", "pxc.log"},
preprocessor: func(in string) string {
required := map[string]bool{
"logrotate.log": true,
"logs.log": true,
"pxc-init.log": true,
"pxc.log": true,
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: It's better to implement sets like map[string]struct{} and use _, ok := required[b] to check if value is there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


files := strings.Split(in, "\n")
var result []string
for _, f := range files {
rel := strings.TrimPrefix(f, "cluster-dump/pxc/")
parts := strings.Split(rel, "/")
if len(parts) != 2 {
continue
}

b := parts[1]
if !required[b] {
continue
}

if !slices.Contains(result, b) && b != "." && b != "" {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure under what circumstances b may be dot or empty here if we explicitly compare it with required few lines above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it is a excess defensive check. I will remove it.

result = append(result, b)
}
}
slices.Sort(result)
return strings.Join(result, "\n")
},
},
}

if s.Namespace != "pxc" {
Expand Down
Loading