Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PT-2236 - pt-secure-collect, pt-pg-summary do not follow PT standard #652

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
)

require (
github.com/alecthomas/kingpin/v2 v2.3.2 // indirect
svetasmirnova marked this conversation as resolved.
Show resolved Hide resolved
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand All @@ -47,6 +48,7 @@ require (
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/net v0.10.0 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF0
github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0=
github.com/alecthomas/kingpin v2.2.6+incompatible h1:5svnBTFgJjZvGKyYBtMB0+m5wvrbUHiqye8wRJMlnYI=
github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE=
github.com/alecthomas/kingpin/v2 v2.3.2 h1:H0aULhgmSzN8xQ3nX1uxtdlTHYoPLu5AhHxWrKI6ocU=
github.com/alecthomas/kingpin/v2 v2.3.2/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE=
github.com/alecthomas/kong v0.8.0 h1:ryDCzutfIqJPnNn0omnrgHLbAggDQM2VWHikE1xqK7s=
github.com/alecthomas/kong v0.8.0/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
Expand Down Expand Up @@ -77,6 +79,7 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand All @@ -92,6 +95,8 @@ github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk=
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4=
Expand Down
6 changes: 3 additions & 3 deletions src/go/pt-k8s-debug-collector/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ func TestResourceOption(t *testing.T) {
Option --version
*/
func TestVersionOption(t *testing.T) {
out, err := exec.Command("../../../bin/pt-k8s-debug-collector", "--version").Output()
out, err := exec.Command("../../../bin/"+TOOLNAME, "--version").Output()
if err != nil {
t.Errorf("error executing pt-k8s-debug-collector --version: %s", err.Error())
t.Errorf("error executing %s --version: %s", TOOLNAME, err.Error())
}
// We are using MustCompile here, because hard-coded RE should not fail
re := regexp.MustCompile(TOOLNAME + `\n.*Version v?\d+\.\d+\.\d+\n`)
if !re.Match(out) {
t.Errorf("pt-k8s-debug-collector --version returns wrong result:\n%s", out)
t.Errorf("%s --version returns wrong result:\n%s", TOOLNAME, out)
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/go/pt-pg-summary/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (
"github.com/percona/percona-toolkit/src/go/pt-pg-summary/templates"
)

const (
TOOLNAME = "pt-pg-summary"
svetasmirnova marked this conversation as resolved.
Show resolved Hide resolved
)

// We do not set anything here, these variables are defined by the Makefile
var (
Build string //nolint
Expand Down Expand Up @@ -211,10 +215,11 @@ func safeConnString(opts connOpts, dbName string) string {
}

func parseCommandLineOpts(args []string) (cliOptions, error) {
app := kingpin.New("pt-pg-summary", "Percona Toolkit - PostgreSQL Summary")
app := kingpin.New(TOOLNAME, "Percona Toolkit - PostgreSQL Summary")
app.UsageWriter(os.Stdout)
// version, commit and date will be set at build time by the compiler -ldflags param
app.Version(fmt.Sprintf("%s version %s\nGIT commit %s\nDate: %s\nGo version: %s",
app.Name, Version, Commit, Build, GoVersion))
app.Version(fmt.Sprintf("%s\nVersion %s\nBuild: %s using %s\nCommit: %s",
app.Name, Version, Build, GoVersion, Commit))
opts := cliOptions{app: app}

app.Flag("ask-pass", "Prompt for a password when connecting to PostgreSQL").
Expand Down
17 changes: 17 additions & 0 deletions src/go/pt-pg-summary/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"fmt"
"os"
"os/exec"
"regexp"
"testing"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -122,3 +124,18 @@ func TestCollectPerDatabaseInfo(t *testing.T) {
})
}
}

/*
Option --version
*/
func TestVersionOption(t *testing.T) {
out, err := exec.Command("../../../bin/"+TOOLNAME, "--version").Output()
if err != nil {
t.Errorf("error executing %s --version: %s", TOOLNAME, err.Error())
}
// We are using MustCompile here, because hard-coded RE should not fail
re := regexp.MustCompile(TOOLNAME + `\n.*Version v?\d+\.\d+\.\d+\n`)
if !re.Match(out) {
t.Errorf("%s --version returns wrong result:\n%s", TOOLNAME, out)
}
}
4 changes: 3 additions & 1 deletion src/go/pt-secure-collect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,13 @@ func processCliParams(baseTempPath string, usageWriter io.Writer) (*cliOptions,
if usageWriter != nil {
app.UsageWriter(usageWriter)
app.Terminate(nil)
} else {
app.UsageWriter(os.Stdout)
}

// Add support for --version flag
app.Version(TOOLNAME + "\nVersion " + Version + "\nBuild: " + Build + " using " + GoVersion +
" Go version: " + GoVersion)
"\nCommit:" + Commit)

opts := &cliOptions{
CollectCommand: app.Command(collectCmd, "Collect, sanitize, pack and encrypt data from pt-tools."),
Expand Down
17 changes: 17 additions & 0 deletions src/go/pt-secure-collect/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"bufio"
"bytes"
"os"
"os/exec"
"reflect"
"regexp"
"testing"
)

Expand Down Expand Up @@ -38,3 +40,18 @@ func TestProcessCliParams(t *testing.T) {

func TestCollect(t *testing.T) {
}

/*
Option --version
*/
func TestVersionOption(t *testing.T) {
out, err := exec.Command("../../../bin/"+TOOLNAME, "--version").Output()
if err != nil {
t.Errorf("error executing %s --version: %s", TOOLNAME, err.Error())
}
// We are using MustCompile here, because hard-coded RE should not fail
re := regexp.MustCompile(TOOLNAME + `\n.*Version v?\d+\.\d+\.\d+\n`)
if !re.Match(out) {
t.Errorf("%s --version returns wrong result:\n%s", TOOLNAME, out)
}
}