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

@@ -28,31 +28,33 @@ type sslSecret struct {
// Dumper struct is for dumping cluster
type Dumper struct {
cmd string
kubeconfig string
resources []string
filePaths []string
fileContainer string
namespace string
location string
errors string
mode int64
crType string
forwardport string
sslSecrets []sslSecret
cmd string
kubeconfig string
resources []string
filePaths []string
fileContainer string
namespace string
location string
errors string
mode int64
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,
location: "cluster-dump",
mode: int64(0o777),
namespace: namespace,
forwardport: forwardport,
cmd: "kubectl",
kubeconfig: kubeconfig,
location: "cluster-dump",
mode: int64(0o777),
namespace: namespace,
forwardport: forwardport,
skipPodSummary: skipPodSummary,
}
resources := []string{
"pods",
@@ -352,18 +354,20 @@ func (d *Dumper) DumpCluster() error {
crName = pod.Labels["app.kubernetes.io/instance"]
}
// Get summary
output, err = d.getPodSummary(resourceType(d.crType), pod.Name, crName, ns.Name)
if err != nil {
d.logError(err.Error(), d.crType, pod.Name)
err = addToArchive(location, d.mode, []byte(err.Error()), tw)
if !d.skipPodSummary {
output, err = d.getPodSummary(resourceType(d.crType), pod.Name, crName, ns.Name)
if err != nil {
log.Printf("Error: create summary errors archive for pod %s in namespace %s: %v", pod.Name, ns.Name, err)
}
} else {
err = addToArchive(location, d.mode, output, tw)
if err != nil {
d.logError(err.Error(), "create summary archive for pod "+pod.Name)
log.Printf("Error: create summary archive for pod %s: %v", pod.Name, err)
d.logError(err.Error(), d.crType, pod.Name)
err = addToArchive(location, d.mode, []byte(err.Error()), tw)
if err != nil {
log.Printf("Error: create summary errors archive for pod %s in namespace %s: %v", pod.Name, ns.Name, err)
}
} else {
err = addToArchive(location, d.mode, output, tw)
if err != nil {
d.logError(err.Error(), "create summary archive for pod "+pod.Name)
log.Printf("Error: create summary archive for pod %s: %v", pod.Name, err)
}
}
}

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()