Skip to content

PT-2368 - refactor all tools cli#1096

Open
BON4 wants to merge 7 commits into
3.xfrom
PT-2368-new-config-support
Open

PT-2368 - refactor all tools cli#1096
BON4 wants to merge 7 commits into
3.xfrom
PT-2368-new-config-support

Conversation

@BON4

@BON4 BON4 commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR migrates CLI/config handling to the new Kong-based configuration layer across all affected Go tools.

The goal is to standardize flag parsing, config-file behavior, password prompts, and version/version-check flow using shared config primitives.

Changes

  • Switched shared version flag to Kong-native kong.VersionFlag in lib/config/commonFlags.go.
  • Migrated CLI bootstrap to config.Setup(...) in:
    • pt-mongodb-index-check
    • pt-mongodb-query-digest
    • pt-mongodb-summary
    • pt-pg-summary
    • pt-secure-collect
  • Replaced legacy parsers (getopt / kingpin) with Kong struct tags and hooks (AfterApply, command Run methods).
  • Unified version-check flow via config.VersionCheckFlag + versioncheck.CheckUpdates(...).
  • Unified interactive secret handling via config.StdinRequestString for DB/encryption passwords.
  • Refactored pt-secure-collect subcommands (collect, encrypt, decrypt, sanitize) to command structs with explicit validation and runtime handlers.

Notes

  • This is primarily a CLI/config refactor; no intended functional changes in business logic.

  • Main expected impact is behavior consistency across tools (flags, defaults, help/version output, password prompts).

  • The contributed code is licensed under GPL v2.0

  • Contributor Licence Agreement (CLA) is signed

  • util/update-modules has been ran

  • Documentation updated

  • Test suite update

BON4 added 2 commits March 12, 2026 15:27
This change intorduces refactoring of all tools to work
with new config implementation.

@svetasmirnova svetasmirnova left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please finish the merge of 3.x and resolve conflicts: pt-k8s-debug-collector tests fail.

@svetasmirnova svetasmirnova left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

pt-mongodb-summary test also fails. Looks like another conflict issue:

=== RUN   TestGetMongosInfo
    main_test.go:296: 
        	Error Trace:	/home/sveta/src/percona/percona-toolkit/src/go/pt-mongodb-summary/main_test.go:296
        	Error:      	Should not be: 0
        	Test:       	TestGetMongosInfo
--- FAIL: TestGetMongosInfo (0.00s)

@svetasmirnova

Copy link
Copy Markdown
Collaborator
$ ./bin/pt-k8s-debug-collector --version

This is not right.

Comment thread src/go/pt-k8s-debug-collector/README.rst Outdated
Comment thread src/go/pt-pg-summary/README.rst
Comment on lines +52 to +56
Encrypt bool `name:"collect" negatable:"" default:"true"`
Sanitize bool `name:"sanitize" negatable:"" default:"true"`
SanitizeHostnames bool `name:"encrypt" negatable:"" default:"true"`
SanitizeQueries bool `name:"sanitize-hostnames" negatable:"" default:"true"`
Collect bool `name:"sanitize-queries" negatable:"" default:"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.

There is a mess between field names and tags.

Comment on lines +86 to +88
for _, incDir := range c.IncludeDirs {
incDir = expandHomeDir(incDir)
}

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.

You just throwing away modified incDir here, c.IncludeDirs stays unmodified.

Comment on lines -125 to -130
if _, err = os.Stat(*opts.TempDir); os.IsNotExist(err) {
log.Infof("Creating temporary directory: %s", *opts.TempDir)
if err = os.Mkdir(*opts.TempDir, os.ModePerm); err != nil {
log.Fatalf("Cannot create temporary dirextory %q: %s", *opts.TempDir, err)
}
}

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.

Shouldn't we still create temp dir?

Comment on lines -135 to -138
if !*opts.NoRemoveTempFiles {
if err = removeTempFiles(*opts.TempDir, !*opts.NoEncrypt); err != nil {
log.Fatal(err)
}

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.

It seems that this functionality was missed. Temporary files never deleted and --remove-temp-files flag does nothing.

Comment thread src/go/pt-pg-summary/main.go Outdated
toolname, Version, Build, GoVersion, Commit,
),
},
) //TODO fix help

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.

What's wrong with the help?

)

var (
CLI = &cliOptions{}

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.

I would suggest to

Suggested change
CLI = &cliOptions{}
CLI cliOptions

And later refer it as &CLI

decryptCmd = "decrypt"
encryptCmd = "encrypt"
collectCmd = "collect"
sanitizeCmd = "sanitize"

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.

Some of these are unused

Comment on lines +105 to +107
if args.Version {
return
}

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.

It seems that this is redundant. Kong exits automatically for version flag.

Comment on lines 181 to +187
``--skip-pod-summary``
Skip the collection of pod-specific summary data.

``--skip-pod-summary``

Skip pod summary collection.

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.

Duplicate

Co-authored-by: Artem Gavrilov <artem.gavrilov@percona.com>
Co-authored-by: Sveta Smirnova <svetasmirnova@users.noreply.github.com>
Co-authored-by: Sveta Smirnova <svetasmirnova@users.noreply.github.com>
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