Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -165,6 +169,18 @@ Path to kubeconfig. Default configuration be used if none specified

Port to use when collecting database-specific summaries. By default, 3306 will be used for PXC and MySQL, 27017 for MongoDB, and 5432 for PostgreSQL

``--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 @@ -232,4 +248,3 @@ VERSION
=======

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

2 changes: 1 addition & 1 deletion src/go/pt-k8s-debug-collector/dumper/dumper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Unit test for non-existing logs container name error handling
*/

func TestGetIndividualFilesError(t *testing.T) {
d := New("", "", "psmdb", "", "")
d := New("", "", "psmdb", "", "", false)

err := d.getIndividualFiles("", "", "", "", nil)

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)
}
}
26 changes: 17 additions & 9 deletions src/go/pt-mongodb-query-digest/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Usage

.. code-block:: bash

pt-mongodb-query-digest [OPTIONS]
pt-mongodb-query-digest [OPTIONS] [host[:port]]

It runs the following command::

Expand All @@ -27,34 +27,43 @@ By default, the results are sorted by ascending query count.
Options
-------

``-?``, ``--help``
``--config``
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

``-a``, ``--authenticationDatabase``
Specifies the database used to establish credentials and privileges
with a MongoDB server.
By default, the ``admin`` database is used.

``-c``, ``--no-version-check``
Don't check for updates
``--version-check``
Check for updates (enabled by default).

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

``-d``, ``--database``
Specifies which database to profile

``host[:port]``
Optional positional host. If no scheme is provided, ``mongodb://`` is prepended automatically.

``-f``, ``--output-format``
Specifies the report output format. Valid options are: ``text``, ``json``.
The default value is ``text``.

``-l``, ``--log-level``
Specifies the log level:
``panic``, ``fatal``, ``error``, ``warn``, ``info``, ``debug error``
``panic``, ``fatal``, ``error``, ``warn``, ``info``, ``debug``

``-n``, ``--limit``
Limits the number of queries to show

``-o``, ``--order-by``
Specifies the sorting order using fields:
``count``, ``ratio``, ``query-time``, ``docs-examined``, ``docs-returned``.
``count``, ``ratio``, ``query-time``, ``docs-scanned``, ``docs-returned``.

Adding a hyphen (``-``) in front of a field denotes reverse order.
For example: ``--order-by="count,-ratio"``.
Expand All @@ -81,11 +90,11 @@ Options
``--sslPEMKeyFile``
Specifies SSL client PEM file used for authentication.

``-u``, ``--user``
``-u``, ``--username``
Specifies the user name for connecting to a server
with authentication enabled.

``-v``, ``--version``
``--version``
Show version and exit

Output Example
Expand Down Expand Up @@ -147,4 +156,3 @@ VERSION
=======

:program:`pt-mongodb-query-digest` 3.7.1

Loading
Loading