PT-2134 - support for PostgreSQL and MySQL operators (#567)

* PT-2134 - Support for PostgreSQL and PS MySQL operators

For PS MySQL operator: added support of pt-mysql-summary
For PostgreSQL operator: added support for pg_gather
Options added:
  - kubeconfig - path to kubeconfig
  - forwardport - port to use when calling pt-*-summary tools ad pt_gather
Options changed:
  - resource - now default value is  (was pxc). New values added:
    psql - for PostgreSQL operator
    ps - for PS MySQL operator
    if default value () is used: only K8 information is collected
    Otherwise resource-specific summary is collected

* PT-2134_support_for_PostgreSQL_and_MySQL_operators

Fixed summary collection when connecting to PostgreSQL opertor and no resource specified

* PT-2134 - support for PostgreSQL and MySQL operators

Added test case for full supported set of values for option --resource,
added --kubeconfig and --forwardport options for test cases,
added support for environment variables KUBECONFIG_PXC, KUBECONFIG_PS, KUBECONFIG_PSMDB, KUBECONFIG_PSQL, FORWARDPORT for test cases

* PT-2134 - support for PostgreSQL and MySQL operators

updated docs/pt-k8s-debug-collector.rst,
replaced README.md in src/go/pt-k8s-debug-collector wih symbolic link to docs/pt-k8s-debug-collector.rst
to avoid having inconsistent documentation

* PT-2134 - support for PostgreSQL and MySQL operators

Removed curl STDERR from the command output

* PT-2134 - support for PostgreSQL and MySQL operators

typo in pt-k8s-debug-collector.rst

* PT-2134 - support for PostgreSQL and MySQL operators

Renamed --resource=psql to --resource=pg after review suggestion by Ege
and collecting feedback from potential users

Co-authored-by: EvgeniyPatlan <evgeniy.patlan@percona.com>
Co-authored-by: Carlos Salguero <carlos.salguero@percona.com>
This commit is contained in:
Sveta Smirnova
2022-12-19 18:48:51 +03:00
committed by GitHub
parent 7e5c51d0fb
commit e8ebc855d0
6 changed files with 491 additions and 135 deletions

View File

@@ -2,6 +2,7 @@ package main
import (
"bytes"
"os"
"os/exec"
"path"
"strings"
@@ -10,11 +11,33 @@ import (
"golang.org/x/exp/slices"
)
/*
This test requires:
- Running K8 Operator installation
- kubectl configuration files, one for each supported operator
-- KUBECONFIG_PXC for K8SPXC
-- KUBECONFIG_PS for K8SPS
-- KUBECONFIG_PSMDB for K8SPSMDB
-- KUBECONFIG_PG for K8SPG
You can additionally set option FORWARDPORT if you want to use custom port when testing summaries.
pt-mysql-summary and pt-mongodb-summary must be in the PATH.
Since running pt-k8s-debug-collector may take long time run go test with increase timeout:
go test -timeout 6000s
We do not explicitly test --kubeconfig and --forwardport options, because they are used in other tests.
*/
/*
Tests collection of the individual files by pt-k8s-debug-collector.
Requires running K8SPXC instance and kubectl, configured to access that instance by default.
*/
func TestIndividualFiles(t *testing.T) {
if os.Getenv("KUBECONFIG_PXC") == "" {
t.Skip("TestIndividualFiles requires K8SPXC")
}
tests := []struct {
name string
cmd []string
@@ -56,7 +79,7 @@ func TestIndividualFiles(t *testing.T) {
},
}
cmd := exec.Command("../../../bin/pt-k8s-debug-collector")
cmd := exec.Command("../../../bin/pt-k8s-debug-collector", "--kubeconfig", os.Getenv("KUBECONFIG_PXC"), "--forwardport", os.Getenv("FORWARDPORT"), "--resource", "pxc")
if err := cmd.Run(); err != nil {
t.Errorf("error executing pt-k8s-debug-collector: %s", err.Error())
}
@@ -77,3 +100,61 @@ func TestIndividualFiles(t *testing.T) {
}
}
}
/*
Tests for supported values of the --resource option
*/
func TestResourceOption(t *testing.T) {
testcmd := []string{"sh", "-c", "tar -tf cluster-dump.tar.gz --wildcards '*/summary.txt' 2>/dev/null | wc -l"}
tests := []struct {
name string
want string
kubeconfig string
}{
{
name: "none",
want: "0",
kubeconfig: "",
},
{
name: "pxc",
want: "3",
kubeconfig: os.Getenv("KUBECONFIG_PXC"),
},
{
name: "ps",
want: "3",
kubeconfig: os.Getenv("KUBECONFIG_PS"),
},
{
name: "psmdb",
want: "3",
kubeconfig: os.Getenv("KUBECONFIG_PSMDB"),
},
{
name: "pg",
want: "3",
kubeconfig: os.Getenv("KUBECONFIG_PG"),
},
}
for _, test := range tests {
cmd := exec.Command("../../../bin/pt-k8s-debug-collector", "--kubeconfig", test.kubeconfig, "--forwardport", os.Getenv("FORWARDPORT"), "--resource", test.name)
if err := cmd.Run(); err != nil {
t.Errorf("error executing pt-k8s-debug-collector: %s", err.Error())
}
defer func() {
cmd = exec.Command("rm", "-f", "cluster-dump.tar.gz")
if err := cmd.Run(); err != nil {
t.Errorf("error cleaning up test data: %s", err.Error())
}
}()
out, err := exec.Command(testcmd[0], testcmd[1:]...).Output()
if err != nil {
t.Errorf("test %s, error running command %s:\n%s\n\nCommand output:\n%s", test.name, testcmd, err.Error(), out)
}
if strings.TrimRight(bytes.NewBuffer(out).String(), "\n") != test.want {
t.Errorf("test %s, output is not as expected\nOutput: %s\nWanted: %s", test.name, out, test.want)
}
}
}