Skip to content

Commit c290de3

Browse files
BON4eslavyansky
authored andcommitted
PT-2421 - Adding further data collection to pt-k8s-debug-collector
This PR introduces additional files in to the final dump archive for pgv2. Tool logs: - patronictl list - pgbackrest info Log files from folders: - $PGDATA/log - pgdata/pgbackrest/log
1 parent 9a8e662 commit c290de3

4 files changed

Lines changed: 100 additions & 2 deletions

File tree

src/go/pt-k8s-debug-collector/dumper/dumper.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,18 @@ type Dumper struct {
6565
restConfig *rest.Config
6666
}
6767

68+
type toolLog struct {
69+
filename string
70+
args []string
71+
}
72+
6873
// individualFile struct is used to dump the necessary files from the containers
6974
type individualFile struct {
7075
resourceName string
7176
containerName string
7277
filepaths []string
7378
dirpaths map[string][]string // map[tarFolder][]dirPaths
79+
toolCmds map[string][]toolLog
7480
}
7581

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

9399
if clusterName == "" {
94-
_, clusterName = parseResourceSpec(resource)
100+
_, clusterName = parseResourceSpec(resource)
95101
}
96102

97103
config, err := buildRestConfig(kubeconfig, clusterName)

src/go/pt-k8s-debug-collector/dumper/individual_files.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,32 @@ func (d *Dumper) getIndividualFiles(ctx context.Context, job exportJob, crType s
6868
}
6969
}
7070
}
71+
72+
for tarFolder, cmds := range indf.toolCmds {
73+
for _, cmd := range cmds {
74+
if err := d.processToolOutput(ctx, job, indf.containerName, tarFolder, cmd); err != nil {
75+
log.Warnf("Skipping tool cmd %v: %v", cmd.args, err)
76+
}
77+
}
78+
}
7179
}
7280
}
7381

82+
func (d *Dumper) processToolOutput(
83+
ctx context.Context,
84+
job exportJob,
85+
container, tarFolder string, cmd toolLog,
86+
) error {
87+
out, stderr, err := d.executeInPod(ctx, cmd.args, job.Pod, container, nil)
88+
if err != nil {
89+
return fmt.Errorf("exec %s: %w (stderr: %s)", cmd, err, stderr.String())
90+
}
91+
92+
dst := d.PodIndividualFilesPath(job.Pod.Namespace, job.Pod.Name, path.Join(tarFolder, cmd.filename))
93+
94+
return d.archive.WriteVirtualFile(dst, out.Bytes())
95+
}
96+
7497
func (d *Dumper) processSingleFile(
7598
ctx context.Context,
7699
job exportJob,

src/go/pt-k8s-debug-collector/dumper/resources.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,28 @@ func (d *Dumper) addPg1() error {
2626

2727
func (d *Dumper) addPg2() error {
2828
dirpaths := map[string][]string{
29-
"pg_log": {"$PGDATA/log"},
29+
"pg_log": {"$PGDATA/log"},
30+
"pgbackrest_log": {"pgdata/pgbackrest/log"},
31+
}
32+
33+
tools := map[string][]toolLog{
34+
"": {
35+
{
36+
filename: "patronictl-list.log",
37+
args: []string{"patronictl", "list"},
38+
},
39+
{
40+
filename: "pgbackrest-info.log",
41+
args: []string{"pgbackrest", "info"},
42+
},
43+
},
3044
}
3145

3246
d.individualFiles = append(d.individualFiles, individualFile{
3347
resourceName: "pgv2",
3448
containerName: "database",
3549
dirpaths: dirpaths,
50+
toolCmds: tools,
3651
})
3752
return nil
3853
}

src/go/pt-k8s-debug-collector/main_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,60 @@ func (s *CollectorSuite) TestIndividualFiles() {
379379
return strings.Join(result, "")
380380
},
381381
},
382+
{
383+
namespace: "pgv2",
384+
name: "pgv2_pgbackrest_log_list",
385+
cmd: []string{"tar", "-tf", "cluster-dump.tar.gz", "--wildcards", "cluster-dump/*/*/pgbackrest_log/*"},
386+
want: []string{"db-archive-push-async.log", "db-stanza-create.log"},
387+
preprocessor: func(in string) string {
388+
required := map[string]struct{}{
389+
"db-archive-push-async.log": {},
390+
"db-stanza-create.log": {},
391+
}
392+
393+
files := strings.Split(in, "\n")
394+
var result []string
395+
for _, f := range files {
396+
b := path.Base(f)
397+
if _, ok := required[b]; !ok {
398+
continue
399+
}
400+
401+
if !slices.Contains(result, b) {
402+
result = append(result, b)
403+
}
404+
}
405+
slices.Sort(result)
406+
return strings.Join(result, "\n")
407+
},
408+
},
409+
{
410+
namespace: "pgv2",
411+
name: "pgv2_tools_log_list",
412+
cmd: []string{"tar", "-tf", "cluster-dump.tar.gz", "--wildcards", "cluster-dump/*/*/*"},
413+
want: []string{"patronictl-list.log", "pgbackrest-info.log"},
414+
preprocessor: func(in string) string {
415+
required := map[string]struct{}{
416+
"patronictl-list.log": {},
417+
"pgbackrest-info.log": {},
418+
}
419+
420+
files := strings.Split(in, "\n")
421+
var result []string
422+
for _, f := range files {
423+
b := path.Base(f)
424+
if _, ok := required[b]; !ok {
425+
continue
426+
}
427+
428+
if !slices.Contains(result, b) {
429+
result = append(result, b)
430+
}
431+
}
432+
slices.Sort(result)
433+
return strings.Join(result, "\n")
434+
},
435+
},
382436
{
383437
namespace: "pxc",
384438
// If pod logs are exported as one file per container

0 commit comments

Comments
 (0)