Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion src/go/lib/config/commonFlags.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package config

import "github.com/alecthomas/kong"

// Config specifies a list of configuration files to read.
// Following the Percona Toolkit specification:
// 1. Position: The --config option must be the first argument on the command line.
Expand All @@ -31,7 +33,7 @@ type ConfigFlag struct {
// VersionFlag adds a --version flag that prints the tool version and exits.
// Embed this struct into the CLI struct to enable version reporting.
type VersionFlag struct {
Version bool `name:"version"`
Version kong.VersionFlag `name:"version" help:"Show version and exit"`
}

// VersionCheckFlag adds a --version-check / --no-version-check flag that controls
Expand Down
19 changes: 18 additions & 1 deletion src/go/pt-galera-log-explainer/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,29 @@ Available flags
``--version``
Show version and exit.

``--version-check``
Check for updates (enabled by default).

``--no-version-check``
Disable update checks.

``--custom-regexes``
Add custom regexes, printed in magenta. Format: (golang regex string)=[optional static message to display].
If the static message is left empty, the captured string will be printed instead. Custom regexes are separated using semi-colon.
Example: ``--custom-regexes="Page cleaner took [0-9]*ms to flush [0-9]* pages=;doesn't recommend.*pxc_strict_mode=unsafe query used"``

Command flags
~~~~~~~~~~~~~

``list``
``--skip-state-colored-column``, ``--all``, ``--states``, ``--views``, ``--events``, ``--sst``, ``--applicative``

``whois``
``--type {nodename|ip|uuid|auto}``, ``--json``

``conflicts``
``--yaml``, ``--json``


Example outputs
===============
Expand Down Expand Up @@ -286,4 +304,3 @@ VERSION
=======

:program:`pt-galera-log-explainer` 3.7.1

17 changes: 16 additions & 1 deletion src/go/pt-k8s-debug-collector/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ Supported Flags

List of Percona Toolkit configuration file(s) separated by a comma without an equal sign. Must be a first flag. Uses default config file locations if not specified.

``--help``

Show help and exit.

``--resource``

Targeted custom resource name. Supported values:
Expand Down Expand Up @@ -177,6 +181,18 @@ Default: ``auto``
``--skip-pod-summary``
Skip the collection of pod-specific summary data.

``--skip-pod-summary``

Skip pod summary collection.

``--version-check``

Check for updates (enabled by default).

``--no-version-check``

Disable update checks.

``--version``
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.

Suggested change
``--version``
``--version-check``
Check for updates (enabled by default).
``--no-version-check``
Disable update checks.

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.

  • No need to mention --skip-pod-summary two times.
  • Spaces matter, because they change formatting. Please follow style.

Print version info.

Expand Down Expand Up @@ -244,4 +260,3 @@ VERSION
=======

:program:`pt-k8s-debug-collector` 3.7.1

19 changes: 10 additions & 9 deletions src/go/pt-k8s-debug-collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"fmt"
"os"

"github.com/alecthomas/kong"
log "github.com/sirupsen/logrus"

"github.com/percona/percona-toolkit/src/go/lib/config"
Expand Down Expand Up @@ -52,14 +53,6 @@ type cliOptions struct {
}

func (c *cliOptions) AfterApply() error {
if c.Version {
fmt.Println(toolname)
fmt.Printf("Version %s\n", Version)
fmt.Printf("Build: %s using %s\n", Build, GoVersion)
fmt.Printf("Commit: %s\n", Commit)
return nil
}

if c.VersionCheck {
advice, err := versioncheck.CheckUpdates(toolname, Version)
if err != nil {
Expand Down Expand Up @@ -90,7 +83,15 @@ func (c *cliOptions) AfterApply() error {

func main() {
opts := &cliOptions{}
_, _, err := config.Setup(toolname, opts)
_, _, err := config.Setup(toolname, opts,
kong.Description("Collects debug data (logs, resource statuses etc.) from a k8s/OpenShift cluster"),
kong.Vars{
"version": fmt.Sprintf(
"%s\nVersion %s\nBuild: %s using %s\nCommit: %s",
toolname, Version, Build, GoVersion, Commit,
),
},
)
if err != nil {
log.Printf("cannot get parameters: %s", err.Error())
os.Exit(1)
Expand Down
66 changes: 38 additions & 28 deletions src/go/pt-mongodb-index-check/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,49 @@ Run the program as ``pt-mongodb-index-check <command> [flags]``
Available commands
~~~~~~~~~~~~~~~~~~

================ ==================================
================ ==========================================
Command Description
================ ==================================
check-duplicated Run checks for duplicated indexes.
check-unused Run check for unused indexes.
check-all Run all checks
================ ==================================
================ ==========================================
check-duplicates Run checks for duplicated indexes.
check-unused Run checks for unused indexes.
check-all Run checks for unused and duplicated indexes.
================ ==========================================

Available flags
~~~~~~~~~~~~~~~

+----------------------------+----------------------------------------+
| Flag | Description |
+============================+========================================+
| –all-databases | Check in all databases excluding |
| | system dbs. |
+----------------------------+----------------------------------------+
| –databases=DATABASES,… | Comma separated list of databases to |
| | check. |
+----------------------------+----------------------------------------+
| –all-collections | Check in all collections in the |
| | selected databases. |
+----------------------------+----------------------------------------+
| –collections=COLLECTIONS,… | Comma separated list of collections to |
| | check. |
+----------------------------+----------------------------------------+
| –mongodb.uri= | Connection URI |
+----------------------------+----------------------------------------+
| –json | Show output as JSON |
+----------------------------+----------------------------------------+
| –version | Show version information |
+----------------------------+----------------------------------------+
``--config=FILE[,FILE,...]``
List of Percona Toolkit config files. Must be the first flag.

``--all-databases``
Check in all databases excluding system DBs.

``--databases=DATABASES,...``
Comma-separated list of databases to check.

``--all-collections``
Check in all collections in selected databases.

``--collections=COLLECTIONS,...``
Comma-separated list of collections to check.

``--mongodb.uri=...``
Connection URI.

``--json``
Show output as JSON.

``--version-check``
Check for updates (enabled by default).

``--no-version-check``
Disable update checks.

``--help``
Show help and exit.

``--version``
Show version information and exit.

Authors
=======
Expand Down Expand Up @@ -108,4 +119,3 @@ VERSION
=======

:program:`pt-mongodb-index-check` 3.7.1

72 changes: 53 additions & 19 deletions src/go/pt-mongodb-index-check/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"strings"
"text/template"
"time"
Expand All @@ -29,16 +30,29 @@ import (
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"

"github.com/percona/percona-toolkit/src/go/lib/config"
"github.com/percona/percona-toolkit/src/go/lib/versioncheck"
"github.com/percona/percona-toolkit/src/go/pt-mongodb-index-check/indexes"
"github.com/percona/percona-toolkit/src/go/pt-mongodb-index-check/templates"
)

type cmdlineArgs struct {
const (
toolname = "pt-mongodb-index-check"
)

// We do not set anything here, these variables are defined by the Makefile
var (
Build string //nolint
GoVersion string //nolint
Version string //nolint
Commit string //nolint
)

type CmdlineArgs struct {
config.ConfigFlag
CheckUnused struct{} `cmd:"" name:"check-unused" help:"Check for unused indexes."`
CheckDuplicated struct{} `cmd:"" name:"check-duplicates" help:"Check for duplicated indexes."`
CheckAll struct{} `cmd:"" name:"check-all" help:"Check for unused and duplicated indexes."`
ShowHelp struct{} `cmd:"" default:"1"`
Version kong.VersionFlag

AllDatabases bool `name:"all-databases" xor:"db" help:"Check in all databases excluding system dbs"`
Databases []string `name:"databases" xor:"db" help:"Comma separated list of databases to check"`
Expand All @@ -47,30 +61,50 @@ type cmdlineArgs struct {
Collections []string `name:"collections" xor:"colls" help:"Comma separated list of collections to check"`
URI string `name:"mongodb.uri" required:"" placeholder:"mongodb://host:port/admindb?options" help:"Connection URI"`
JSON bool `name:"json" help:"Show output as JSON"`

config.VersionFlag
config.VersionCheckFlag
}

func (c *CmdlineArgs) AfterApply() error {
if c.VersionCheck {
advice, err := versioncheck.CheckUpdates(toolname, Version)
if err != nil {
log.Errorf("cannot check version updates: %s", err.Error())
} else if advice != "" {
log.Infof("%s", advice)
}
}

return nil
}

type response struct {
Unused []indexes.IndexStat
Duplicated []indexes.Duplicate
}

const (
toolname = "pt-mongodb-index-check"
)

// We do not set anything here, these variables are defined by the Makefile
var (
Build string //nolint
GoVersion string //nolint
Version string //nolint
Commit string //nolint
)

func main() {
var args cmdlineArgs
kongctx := kong.Parse(&args, kong.UsageOnError(),
kong.Vars{"version": fmt.Sprintf("%s\nVersion %s\nBuild: %s using %s\nCommit: %s",
toolname, Version, Build, GoVersion, Commit)})
var args CmdlineArgs
kongctx, _, err := config.Setup(
toolname,
&args,
kong.UsageOnError(),
kong.Vars{
"version": fmt.Sprintf(
"%s\nVersion %s\nBuild: %s using %s\nCommit: %s",
toolname, Version, Build, GoVersion, Commit,
),
},
)
if err != nil {
log.Errorf("cannot get parameters: %s", err.Error())
os.Exit(1)
}

if args.Version {
return
}

ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
Expand Down
10 changes: 5 additions & 5 deletions src/go/pt-mongodb-index-check/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ func TestVersionOption(t *testing.T) {

func TestNoCommand(t *testing.T) {
mockMongo := "mongodb://127.0.0.1:27017"
out, err := exec.Command("../../../bin/"+toolname, "--mongodb.uri", mockMongo).Output()
if err != nil {
t.Errorf("error executing %s with no command: %s", toolname, err.Error())
out, err := exec.Command("../../../bin/"+toolname, "--mongodb.uri", mockMongo).CombinedOutput()
if err == nil {
t.Fatalf("expected non-zero exit code when no command is provided")
}

want := "Usage: pt-mongodb-index-check show-help"
want := "Usage: pt-mongodb-index-check --mongodb.uri="
if !strings.Contains(string(out), want) {
t.Errorf("Output missmatch. Output %q should contain %q", string(out), want)
t.Errorf("Output mismatch. Output %q should contain %q", string(out), want)
}
}
Loading
Loading