Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion src/go/pt-k8s-debug-collector/dumper/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,18 @@ type Dumper struct {
restConfig *rest.Config
}

type toolLog struct {
filename string
args []string
}

// individualFile struct is used to dump the necessary files from the containers
type individualFile struct {
resourceName string
containerName string
filepaths []string
dirpaths map[string][]string // map[tarFolder][]dirPaths
toolCmds map[string][]toolLog
}

// resourceMap struct is used to dump the resources from namespace scope or cluster scope
Expand All @@ -91,7 +97,7 @@ func New(location, namespace, kubeconfig, clusterName, forwardport, resource str
log.AddHook(&ErrorArchiveHook{safeLogger: safeLog})

if clusterName == "" {
_, clusterName = parseResourceSpec(resource)
_, clusterName = parseResourceSpec(resource)
}

config, err := buildRestConfig(kubeconfig, clusterName)
Expand Down
23 changes: 23 additions & 0 deletions src/go/pt-k8s-debug-collector/dumper/individual_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,32 @@ func (d *Dumper) getIndividualFiles(ctx context.Context, job exportJob, crType s
}
}
}

for tarFolder, cmds := range indf.toolCmds {
for _, cmd := range cmds {
if err := d.processToolOutput(ctx, job, indf.containerName, tarFolder, cmd); err != nil {
log.Warnf("Skipping tool cmd %v: %v", cmd.args, err)
}
}
}
}
}

func (d *Dumper) processToolOutput(
ctx context.Context,
job exportJob,
container, tarFolder string, cmd toolLog,
) error {
out, stderr, err := d.executeInPod(ctx, cmd.args, job.Pod, container, nil)
if err != nil {
return fmt.Errorf("exec %s: %w (stderr: %s)", cmd, err, stderr.String())
Comment thread
svetasmirnova marked this conversation as resolved.
Outdated
}

dst := d.PodIndividualFilesPath(job.Pod.Namespace, job.Pod.Name, path.Join(tarFolder, cmd.filename))

return d.archive.WriteVirtualFile(dst, out.Bytes())
}

func (d *Dumper) processSingleFile(
ctx context.Context,
job exportJob,
Expand Down
17 changes: 16 additions & 1 deletion src/go/pt-k8s-debug-collector/dumper/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,28 @@ func (d *Dumper) addPg1() error {

func (d *Dumper) addPg2() error {
dirpaths := map[string][]string{
"pg_log": {"$PGDATA/log"},
"pg_log": {"$PGDATA/log"},
"pgbackrest_log": {"pgdata/pgbackrest/log"},
}

tools := map[string][]toolLog{
"": {
{
filename: "patronictl-list.log",
args: []string{"patronictl", "list"},
},
{
filename: "pgbackrest-info.log",
args: []string{"pgbackrest", "info"},
},
},
}

d.individualFiles = append(d.individualFiles, individualFile{
resourceName: "pgv2",
containerName: "database",
dirpaths: dirpaths,
toolCmds: tools,
})
return nil
}
Expand Down
54 changes: 54 additions & 0 deletions src/go/pt-k8s-debug-collector/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,60 @@ func (s *CollectorSuite) TestIndividualFiles() {
return strings.Join(result, "")
},
},
{
namespace: "pgv2",
name: "pgv2_pgbackrest_log_list",
cmd: []string{"tar", "-tf", "cluster-dump.tar.gz", "--wildcards", "cluster-dump/*/*/pgbackrest_log/*"},
want: []string{"db-archive-push-async.log", "db-stanza-create.log"},
preprocessor: func(in string) string {
required := map[string]struct{}{
"db-archive-push-async.log": {},
"db-stanza-create.log": {},
}

files := strings.Split(in, "\n")
var result []string
for _, f := range files {
b := path.Base(f)
if _, ok := required[b]; !ok {
continue
}

if !slices.Contains(result, b) {
result = append(result, b)
}
}
slices.Sort(result)
return strings.Join(result, "\n")
},
},
{
namespace: "pgv2",
name: "pgv2_tools_log_list",
cmd: []string{"tar", "-tf", "cluster-dump.tar.gz", "--wildcards", "cluster-dump/*/*/*"},
want: []string{"patronictl-list.log", "pgbackrest-info.log"},
preprocessor: func(in string) string {
required := map[string]struct{}{
"patronictl-list.log": {},
"pgbackrest-info.log": {},
}

files := strings.Split(in, "\n")
var result []string
for _, f := range files {
b := path.Base(f)
if _, ok := required[b]; !ok {
continue
}

if !slices.Contains(result, b) {
result = append(result, b)
}
}
slices.Sort(result)
return strings.Join(result, "\n")
},
},
{
namespace: "pxc",
// If pod logs are exported as one file per container
Expand Down