diff --git a/.github/workflows/toolkit.yml b/.github/workflows/toolkit.yml index 02b2bf77..7561f626 100644 --- a/.github/workflows/toolkit.yml +++ b/.github/workflows/toolkit.yml @@ -25,7 +25,7 @@ jobs: run: cd src/go; make linux-amd64; cd ../../ - name: Build the Docker image - run: echo "FROM oraclelinux:9-slim" > Dockerfile; echo "COPY bin/* /usr/bin/" >> Dockerfile; docker build . --file Dockerfile --tag percona-toolkit:${{ github.sha }} + run: echo "FROM oraclelinux:9-slim" > Dockerfile; echo "RUN microdnf -y update" >> Dockerfile; echo "COPY bin/* /usr/bin/" >> Dockerfile; docker build . --file Dockerfile --tag percona-toolkit:${{ github.sha }} - name: Run Trivy vulnerability scanner uses: aquasecurity/trivy-action@0.14.0 with: diff --git a/Makefile.PL b/Makefile.PL index 485e715b..0e8e8280 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,22 +1,40 @@ use ExtUtils::MakeMaker; +use ExtUtils::MY; + +sub MY::postamble { + return <<'MAKE_GOTOOLS'; +gotools: + cd src/go && $(MAKE) build + +MAKE_GOTOOLS +} WriteMakefile( NAME => 'Percona::Toolkit', VERSION => '3.5.5', - EXE_FILES => [ ], + EXE_FILES => [ + map { + (my $name = $_) =~ s/^bin.//; + my $file_name = $_; + if ( ( $file_name !~ m/mongo/ ) || ( $file_name !~ m/pg/ ) || ( $file_name !~ m/pt-stalk/ ) || ( $file_name !~ m/pt-k8s/ ) ) { + $_; + } + } + ], MAN1PODS => { 'docs/percona-toolkit.pod' => 'blib/man1/percona-toolkit.1p', map { (my $name = $_) =~ s/^bin.//; my $file_name = $_; - if ( ( $file_name !~ m/mongo/ ) || ( $file_name !~ m/pg/ ) || ( $file_name !~ m/pt-stalk/ ) ) { + if ( ( $file_name !~ m/mongo/ ) || ( $file_name !~ m/pg/ ) || ( $file_name !~ m/pt-stalk/ ) || ( $file_name !~ m/pt-k8s/ ) ) { $_ => "blib/man1/$name.1p"; } } }, MAN3PODS => {}, # man(3) pages are for C libs + depend => {manifypods => gotools}, PREREQ_PM => { DBI => 1.46, DBD::mysql => 3.0000_0, }, -); +); \ No newline at end of file diff --git a/go.mod b/go.mod index a47ee3da..aaca3e02 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( golang.org/x/crypto v0.15.0 golang.org/x/exp v0.0.0-20230321023759-10a507213a29 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 - k8s.io/api v0.28.3 + k8s.io/api v0.28.4 ) require ( @@ -57,7 +57,7 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/apimachinery v0.28.3 // indirect + k8s.io/apimachinery v0.28.4 // indirect k8s.io/klog/v2 v2.100.1 // indirect k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect diff --git a/go.sum b/go.sum index 341aeb43..6550443a 100644 --- a/go.sum +++ b/go.sum @@ -193,10 +193,10 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/api v0.28.3 h1:Gj1HtbSdB4P08C8rs9AR94MfSGpRhJgsS+GF9V26xMM= -k8s.io/api v0.28.3/go.mod h1:MRCV/jr1dW87/qJnZ57U5Pak65LGmQVkKTzf3AtKFHc= -k8s.io/apimachinery v0.28.3 h1:B1wYx8txOaCQG0HmYF6nbpU8dg6HvA06x5tEffvOe7A= -k8s.io/apimachinery v0.28.3/go.mod h1:uQTKmIqs+rAYaq+DFaoD2X7pcjLOqbQX2AOiO0nIpb8= +k8s.io/api v0.28.4 h1:8ZBrLjwosLl/NYgv1P7EQLqoO8MGQApnbgH8tu3BMzY= +k8s.io/api v0.28.4/go.mod h1:axWTGrY88s/5YE+JSt4uUi6NMM+gur1en2REMR7IRj0= +k8s.io/apimachinery v0.28.4 h1:zOSJe1mc+GxuMnFzD4Z/U1wst50X28ZNsn5bhgIIao8= +k8s.io/apimachinery v0.28.4/go.mod h1:wI37ncBvfAoswfq626yPTe6Bz1c22L7uaJ8dho83mgg= k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 h1:qY1Ad8PODbnymg2pRbkyMT/ylpTrCM8P2RJ0yroCyIk= diff --git a/src/go/Makefile b/src/go/Makefile index e0d8057f..f94a431f 100644 --- a/src/go/Makefile +++ b/src/go/Makefile @@ -22,7 +22,7 @@ pkgs = $(shell find . -type d -name "pt-*" -exec basename {} \;) # VERSION ?=$(shell git describe --abbrev=0) doesn't always work here, need to use git log VERSION ?=$(shell git log --no-walk --tags --pretty="%H %d" --decorate=short | head -n1 | awk -F'[, $(CP)]' '{ print $$4; }') BUILD=$(BUILD_DATE) -GOVERSION=$(shell go version | cut --delimiter=" " -f3) +GOVERSION=$(shell go version | cut -d " " -f3) GOUTILSDIR ?= $(GOPATH)/bin FILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*") PREFIX=$(shell pwd) @@ -127,24 +127,36 @@ env-down: env ## Clean-up MongoDB docker containers cluster docker-compose down -v rm .env -linux-amd64: ## Build Mongo tools for linux-amd64. +linux-amd64: ## Build Go tools for linux-amd64. @echo "Building linux/amd64 binaries in ${BIN_DIR} as version ${VERSION}" @cd ${TOP_DIR} && go get ./... @$(foreach pkg,$(pkgs),rm -f ${BIN_DIR}/$(pkg) 2> /dev/null;) @$(foreach pkg,$(pkgs),GOOS=linux GOARCH=amd64 go build -ldflags ${LDFLAGS} -o ${BIN_DIR}/$(pkg) ./$(pkg);) -linux-386: ## Build Mongo tools for linux-386 +linux-386: ## Build Go tools for linux-386 @echo "Building linux/386 binaries in ${BIN_DIR} as version ${VERSION}" @cd ${TOP_DIR} && go get ./... @$(foreach pkg,$(pkgs),rm -f ${BIN_DIR}/$(pkg) 2> /dev/null;) @$(foreach pkg,$(pkgs),GOOS=linux GOARCH=386 go build -ldflags ${LDFLAGS} -o ${BIN_DIR}/$(pkg) ./$(pkg);) -darwin-amd64: ## Build Mongo tools for darwin-amd64 (MacOS) +darwin-amd64: ## Build Go tools for darwin-amd64 (MacOS) @echo "Building darwin/amd64 binaries in ${BIN_DIR} as version ${VERSION}" @cd ${TOP_DIR} && go get ./... @$(foreach pkg,$(pkgs),rm -f ${BIN_DIR}/$(pkg) 2> /dev/null;) @$(foreach pkg,$(pkgs),GOOS=darwin GOARCH=amd64 go build -ldflags ${LDFLAGS} -o ${BIN_DIR}/$(pkg) ./$(pkg);) +darwin-arm64: ## Build Go tools for darwin-arm64 (MacOS) + @echo "Building darwin/arm64 binaries in ${BIN_DIR} as version ${VERSION}" + @cd ${TOP_DIR} && go get ./... + @$(foreach pkg,$(pkgs),rm -f ${BIN_DIR}/$(pkg) 2> /dev/null;) + @$(foreach pkg,$(pkgs),GOOS=darwin GOARCH=arm64 go build -ldflags ${LDFLAGS} -o ${BIN_DIR}/$(pkg) ./$(pkg);) + +build: + @echo "Building binaries in ${BIN_DIR} as version ${VERSION}" + @cd ${TOP_DIR} && go get ./... + @$(foreach pkg,$(pkgs),rm -f ${BIN_DIR}/$(pkg) 2> /dev/null;) + @$(foreach pkg,$(pkgs),go build -ldflags ${LDFLAGS} -o ${BIN_DIR}/$(pkg) ./$(pkg);) + style: ## Check code style @echo ">> checking code style" @! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' diff --git a/src/go/lib/config/config_test.go b/src/go/lib/config/config_test.go index a09c2db4..1eb5fd05 100644 --- a/src/go/lib/config/config_test.go +++ b/src/go/lib/config/config_test.go @@ -129,14 +129,14 @@ func TestOverrideConfig(t *testing.T) { } func TestDefaultFiles(t *testing.T) { - user, _ := user.Current() + current, _ := user.Current() toolname := "pt-testing" want := []string{ "/etc/percona-toolkit/percona-toolkit.conf", fmt.Sprintf("/etc/percona-toolkit/%s.conf", toolname), - fmt.Sprintf("%s/.percona-toolkit.conf", user.HomeDir), - fmt.Sprintf("%s/.%s.conf", user.HomeDir, toolname), + fmt.Sprintf("%s/.percona-toolkit.conf", current.HomeDir), + fmt.Sprintf("%s/.%s.conf", current.HomeDir, toolname), } got, err := DefaultConfigFiles(toolname) diff --git a/src/go/mongolib/proto/cmdlineopts.go b/src/go/mongolib/proto/cmdlineopts.go index 802a3042..0d2cf16c 100644 --- a/src/go/mongolib/proto/cmdlineopts.go +++ b/src/go/mongolib/proto/cmdlineopts.go @@ -37,7 +37,7 @@ type Security struct { KeyFile string `bson:"keyFile"` ClusterAuthMode string `bson:"clusterAuthMode"` Authorization string `bson:"authorization"` - JavascriptEnabled bool `bson:javascriptEnabled"` + JavascriptEnabled bool `bson:"javascriptEnabled"` Sasl struct { HostName string `bson:"hostName"` ServiceName string `bson:"serverName"` diff --git a/src/go/mongolib/proto/server_status.go b/src/go/mongolib/proto/server_status.go index a9608927..88710e84 100644 --- a/src/go/mongolib/proto/server_status.go +++ b/src/go/mongolib/proto/server_status.go @@ -30,10 +30,10 @@ type ServerStatus struct { } type StorageEngine struct { - Name string `bson:"name"` - SupportCommittedREads bool `bson:supportsCommittedReads"` - ReadOnly bool `bson:"readOnly"` - Persistent bool `bson:"persistent"` + Name string `bson:"name"` + SupportsCommittedReads bool `bson:"supportsCommittedReads"` + ReadOnly bool `bson:"readOnly"` + Persistent bool `bson:"persistent"` } // WiredTiger stores information related to the WiredTiger storage engine. diff --git a/src/go/pt-mongodb-query-digest/main.go b/src/go/pt-mongodb-query-digest/main.go index 51ccbe73..badc1a57 100644 --- a/src/go/pt-mongodb-query-digest/main.go +++ b/src/go/pt-mongodb-query-digest/main.go @@ -412,15 +412,15 @@ type multiSorter struct { less []lessFunc } -// Sort sorts the argument slice according to the less functions passed to OrderedBy. +// Sort sorts the argument slice according to the less functions passed to orderedBy. func (ms *multiSorter) Sort(queries []stats.QueryStats) { ms.queries = queries sort.Sort(ms) } -// OrderedBy returns a Sorter that sorts using the less functions, in order. +// orderedBy returns a Sorter that sorts using the less functions, in order. // Call its Sort method to sort the data. -func OrderedBy(less ...lessFunc) *multiSorter { +func orderedBy(less ...lessFunc) *multiSorter { return &multiSorter{ less: less, } @@ -520,7 +520,7 @@ func sortQueries(queries []stats.QueryStats, orderby []string) []stats.QueryStat sortFuncs = append(sortFuncs, f) } - OrderedBy(sortFuncs...).Sort(queries) + orderedBy(sortFuncs...).Sort(queries) return queries }