mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-02 02:34:19 +00:00
Merge pull request #966 from impimp/PT-2453
PT-2453: Add -skip-pod-summary for pt-k8s-debug-collector
This commit is contained in:
@@ -39,6 +39,9 @@ extend-ignore-re = [
|
|||||||
"END_ND_TOOLTIPS" = "END_ND_TOOLTIPS"
|
"END_ND_TOOLTIPS" = "END_ND_TOOLTIPS"
|
||||||
"EXPLAINed" = "EXPLAINed"
|
"EXPLAINed" = "EXPLAINed"
|
||||||
"FH_ND_FILE" = "FH_ND_FILE"
|
"FH_ND_FILE" = "FH_ND_FILE"
|
||||||
|
"GTI" = "GTI"
|
||||||
|
"GTID" = "GTID"
|
||||||
|
"GTIDs" = "GTIDs"
|
||||||
"INSERTs" = "INSERTs"
|
"INSERTs" = "INSERTs"
|
||||||
"IST" = "IST"
|
"IST" = "IST"
|
||||||
"istError" = "istError"
|
"istError" = "istError"
|
||||||
|
@@ -40,12 +40,13 @@ type Dumper struct {
|
|||||||
crType string
|
crType string
|
||||||
forwardport string
|
forwardport string
|
||||||
sslSecrets []sslSecret
|
sslSecrets []sslSecret
|
||||||
|
skipPodSummary bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var resourcesRe = regexp.MustCompile(`(\w+\.(\w+).percona\.com)`)
|
var resourcesRe = regexp.MustCompile(`(\w+\.(\w+).percona\.com)`)
|
||||||
|
|
||||||
// New return new Dumper object
|
// New return new Dumper object
|
||||||
func New(location, namespace, resource string, kubeconfig string, forwardport string) Dumper {
|
func New(location, namespace, resource string, kubeconfig string, forwardport string, skipPodSummary bool) Dumper {
|
||||||
d := Dumper{
|
d := Dumper{
|
||||||
cmd: "kubectl",
|
cmd: "kubectl",
|
||||||
kubeconfig: kubeconfig,
|
kubeconfig: kubeconfig,
|
||||||
@@ -53,6 +54,7 @@ func New(location, namespace, resource string, kubeconfig string, forwardport st
|
|||||||
mode: int64(0o777),
|
mode: int64(0o777),
|
||||||
namespace: namespace,
|
namespace: namespace,
|
||||||
forwardport: forwardport,
|
forwardport: forwardport,
|
||||||
|
skipPodSummary: skipPodSummary,
|
||||||
}
|
}
|
||||||
resources := []string{
|
resources := []string{
|
||||||
"pods",
|
"pods",
|
||||||
@@ -352,6 +354,7 @@ func (d *Dumper) DumpCluster() error {
|
|||||||
crName = pod.Labels["app.kubernetes.io/instance"]
|
crName = pod.Labels["app.kubernetes.io/instance"]
|
||||||
}
|
}
|
||||||
// Get summary
|
// Get summary
|
||||||
|
if !d.skipPodSummary {
|
||||||
output, err = d.getPodSummary(resourceType(d.crType), pod.Name, crName, ns.Name)
|
output, err = d.getPodSummary(resourceType(d.crType), pod.Name, crName, ns.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.logError(err.Error(), d.crType, pod.Name)
|
d.logError(err.Error(), d.crType, pod.Name)
|
||||||
@@ -366,6 +369,7 @@ func (d *Dumper) DumpCluster() error {
|
|||||||
log.Printf("Error: create summary archive for pod %s: %v", pod.Name, err)
|
log.Printf("Error: create summary archive for pod %s: %v", pod.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get individual Logs
|
// get individual Logs
|
||||||
location = filepath.Join(d.location, ns.Name, pod.Name)
|
location = filepath.Join(d.location, ns.Name, pod.Name)
|
||||||
|
@@ -28,6 +28,7 @@ func main() {
|
|||||||
kubeconfig := ""
|
kubeconfig := ""
|
||||||
forwardport := ""
|
forwardport := ""
|
||||||
version := false
|
version := false
|
||||||
|
skipPodSummary := false
|
||||||
|
|
||||||
flag.StringVar(&namespace, "namespace", "", "Namespace for collecting data. If empty data will be collected from all namespaces")
|
flag.StringVar(&namespace, "namespace", "", "Namespace for collecting data. If empty data will be collected from all namespaces")
|
||||||
flag.StringVar(&resource, "resource", "auto", "Collect data, specific to the resource. Supported values: pxc, psmdb, pg, pgv2, ps, none, auto")
|
flag.StringVar(&resource, "resource", "auto", "Collect data, specific to the resource. Supported values: pxc, psmdb, pg, pgv2, ps, none, auto")
|
||||||
@@ -35,6 +36,7 @@ func main() {
|
|||||||
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to kubeconfig")
|
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to kubeconfig")
|
||||||
flag.StringVar(&forwardport, "forwardport", "", "Port to use for port forwarding")
|
flag.StringVar(&forwardport, "forwardport", "", "Port to use for port forwarding")
|
||||||
flag.BoolVar(&version, "version", false, "Print version")
|
flag.BoolVar(&version, "version", false, "Print version")
|
||||||
|
flag.BoolVar(&skipPodSummary, "skip-pod-summary", false, "Skip pod summary collection")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if version {
|
if version {
|
||||||
@@ -50,7 +52,7 @@ func main() {
|
|||||||
resource += "/" + clusterName
|
resource += "/" + clusterName
|
||||||
}
|
}
|
||||||
|
|
||||||
d := dumper.New("", namespace, resource, kubeconfig, forwardport)
|
d := dumper.New("", namespace, resource, kubeconfig, forwardport, skipPodSummary)
|
||||||
log.Println("Start collecting cluster data")
|
log.Println("Start collecting cluster data")
|
||||||
|
|
||||||
err := d.DumpCluster()
|
err := d.DumpCluster()
|
||||||
|
@@ -365,6 +365,106 @@ func TestSSLResourceOption(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Tests for option --skip-pod-summary
|
||||||
|
*/
|
||||||
|
func TestPT_2453(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
|
||||||
|
resource string
|
||||||
|
want string
|
||||||
|
kubeconfig string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "none",
|
||||||
|
resource: "none",
|
||||||
|
want: "0",
|
||||||
|
kubeconfig: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pxc",
|
||||||
|
resource: "pxc",
|
||||||
|
want: "0",
|
||||||
|
kubeconfig: os.Getenv("KUBECONFIG_PXC"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ps",
|
||||||
|
resource: "ps",
|
||||||
|
want: "0",
|
||||||
|
kubeconfig: os.Getenv("KUBECONFIG_PS"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "psmdb",
|
||||||
|
resource: "psmdb",
|
||||||
|
want: "0",
|
||||||
|
kubeconfig: os.Getenv("KUBECONFIG_PSMDB"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pg",
|
||||||
|
resource: "pg",
|
||||||
|
want: "0",
|
||||||
|
kubeconfig: os.Getenv("KUBECONFIG_PG"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pgv2",
|
||||||
|
resource: "pgv2",
|
||||||
|
want: "0",
|
||||||
|
kubeconfig: os.Getenv("KUBECONFIG_PG2"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "auto pxc",
|
||||||
|
resource: "auto",
|
||||||
|
want: "0",
|
||||||
|
kubeconfig: os.Getenv("KUBECONFIG_PXC"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "auto ps",
|
||||||
|
resource: "auto",
|
||||||
|
want: "0",
|
||||||
|
kubeconfig: os.Getenv("KUBECONFIG_PS"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "auto psmdb",
|
||||||
|
resource: "auto",
|
||||||
|
want: "0",
|
||||||
|
kubeconfig: os.Getenv("KUBECONFIG_PSMDB"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "auto pg",
|
||||||
|
resource: "auto",
|
||||||
|
want: "0",
|
||||||
|
kubeconfig: os.Getenv("KUBECONFIG_PG"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "auto pgv2",
|
||||||
|
resource: "auto",
|
||||||
|
want: "0",
|
||||||
|
kubeconfig: os.Getenv("KUBECONFIG_PG2"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
cmd := exec.Command("../../../bin/pt-k8s-debug-collector", "--kubeconfig", test.kubeconfig, "--forwardport", os.Getenv("FORWARDPORT"), "--resource", test.resource, "--skip-pod-summary")
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
t.Errorf("error executing pt-k8s-debug-collector: %s\nCommand: %s", err.Error(), cmd.String())
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Option --version
|
Option --version
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user