Skip to content

Conversation

@BON4
Copy link

@BON4 BON4 commented Jan 6, 2026

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

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.

switch resourceType(resource) {
case "pg":
dirPaths = append(dirPaths,
"$PGBACKREST_DB_PATH/pg_log",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where does the variable PGBACKREST_DB_PATH come from? It may not be set on the client machine where pt-k8s-debug-collector is running. Or could be set to a completely irrelevant value regarding the cluster it collects the data from.

Copy link
Author

Choose a reason for hiding this comment

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

This comes from pod manifest.

    Environment:
      MODE:                               postgres
      PGHA_PG_PORT:                       5432
      PGHA_USER:                          postgres
      PATRONI_POSTGRESQL_DATA_DIR:        /pgdata/cluster1-repl1
      PGBACKREST_STANZA:                  db
      PGBACKREST_REPO1_HOST:              cluster1-backrest-shared-repo
      BACKREST_SKIP_CREATE_STANZA:        true
      PGHA_PGBACKREST:                    true
      PGBACKREST_REPO1_PATH:              /backrestrepo/cluster1-backrest-shared-repo
      PGBACKREST_DB_PATH:                 /pgdata/cluster1-repl1
                                          ^

}()

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?

// 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.

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.

5 participants