Skip to content

Comments

PT-2237 - fixed PostgreSQL DB logs collection#1051

Open
BON4 wants to merge 16 commits into3.xfrom
PT-2237_fix_pg_log_collector
Open

PT-2237 - fixed PostgreSQL DB logs collection#1051
BON4 wants to merge 16 commits into3.xfrom
PT-2237_fix_pg_log_collector

Conversation

@BON4
Copy link

@BON4 BON4 commented Jan 6, 2026

This fix ensures pt-k8s-debug-collector collects PostgreSQL database logs.

DO NOT MERGE BEFORE #1054 IS MERGED

What was added:

  • To keep changes minimal, the existing test TestIndividualFiles was modified to cover the new case.
    The test was refactored because the previous implementation couldn't handle files with variable names.
    In /pgdata/<cluster_name>/pg_log, logs are named according to the day/week, so filenames are not known at runtime.

  • A new function getAllFilesFromDirectory was added to dumper.go.
    Its purpose is the same as the existing getIndividualFiles, but it supports extracting multiple files from a directory. It is useful because pg log filenames can vary, and there can be multiple log files.

  • A new function parseEnvs was added to dumper.go.
    Its purpose is to load environment variables present in the pod into a string.
    It is used inside getAllFilesFromDirectory to load $PGBACKREST_DB_PATH, because there is no simpler way to determine the path /pgdata/<cluster_name>/pg_log, which can vary.

  • The contributed code is licensed under GPL v2.0
  • Contributor Licence Agreement (CLA) is signed
  • util/update-modules has been ran
    (/lib has not been changed)
  • Documentation updated
  • Test suite update

This fix ensures `pt-k8s-debug-collector` collects postgreSql databse
logs which is stored in `/pgdata/<cluster_name>/pg_log`.
A test `TestIndividualFiles` was refactored, and modified for a new
case with new feature.
@BON4 BON4 requested a review from svetasmirnova as a code owner January 6, 2026 14:46
@it-percona-cla
Copy link

it-percona-cla commented Jan 6, 2026

CLA assistant check
All committers have signed the CLA.

}()

time.Sleep(3 * time.Second) // wait for port-forward command
time.Sleep(10 * time.Second) // wait for port-forward command
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why sleep time increase?

Copy link
Author

Choose a reason for hiding this comment

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

It was too little on my machine. Maybe we should implement some tcp checker to confirm that port-forward is working?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This would be the best.

// runCmd run command (Dumper.cmd) with given args, return it output
func (d *Dumper) runCmd(args ...string) ([]byte, error) {
baseArgs := []string{"--kubeconfig", d.kubeconfig}
baseArgs = append(baseArgs, args...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you prefix arguments with --kubeconfig and d.kubeconfig is empty, the following argument will be treated as a path to --kubeconfig. This is wrong.

Copy link
Author

Choose a reason for hiding this comment

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

Added an if condition for that. We need this to be prefixed because exec command will be wrong.

BON4 added 7 commits January 8, 2026 14:59
This refactor includes replacing all of the `kubectl` cli calls
with golang sdk for k8s. Additionaly dumper now has new structure,
new logger, tar file path controll, and multithreaded approach
for downloading and exporting files form multiple pods.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants