PT-2453: Add -skip-pod-summary for pt-k8s-debug-collector

In some cases, collecting additional data from pods is not needed and, due to the current tool design, can cause significant delays.
This commit introduces a workaround to skip such collection when it's not required.
This commit is contained in:
IMP
2025-05-30 14:24:03 +02:00
committed by Iwo Panowicz
parent fd2f0f94b1
commit 6e7a867fed
2 changed files with 37 additions and 31 deletions

View File

@@ -40,12 +40,13 @@ type Dumper struct {
crType string
forwardport string
sslSecrets []sslSecret
skipPodSummary bool
}
var resourcesRe = regexp.MustCompile(`(\w+\.(\w+).percona\.com)`)
// 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{
cmd: "kubectl",
kubeconfig: kubeconfig,
@@ -53,6 +54,7 @@ func New(location, namespace, resource string, kubeconfig string, forwardport st
mode: int64(0o777),
namespace: namespace,
forwardport: forwardport,
skipPodSummary: skipPodSummary,
}
resources := []string{
"pods",
@@ -352,6 +354,7 @@ func (d *Dumper) DumpCluster() error {
crName = pod.Labels["app.kubernetes.io/instance"]
}
// Get summary
if !d.skipPodSummary {
output, err = d.getPodSummary(resourceType(d.crType), pod.Name, crName, ns.Name)
if err != nil {
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)
}
}
}
// get individual Logs
location = filepath.Join(d.location, ns.Name, pod.Name)

View File

@@ -28,6 +28,7 @@ func main() {
kubeconfig := ""
forwardport := ""
version := false
skipPodSummary := false
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")
@@ -35,6 +36,7 @@ func main() {
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to kubeconfig")
flag.StringVar(&forwardport, "forwardport", "", "Port to use for port forwarding")
flag.BoolVar(&version, "version", false, "Print version")
flag.BoolVar(&skipPodSummary, "skip-pod-summary", false, "Skip pod summary collection")
flag.Parse()
if version {
@@ -50,7 +52,7 @@ func main() {
resource += "/" + clusterName
}
d := dumper.New("", namespace, resource, kubeconfig, forwardport)
d := dumper.New("", namespace, resource, kubeconfig, forwardport, skipPodSummary)
log.Println("Start collecting cluster data")
err := d.DumpCluster()