mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-12-09 02:01:37 +08:00
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:
@@ -28,31 +28,33 @@ type sslSecret struct {
|
|||||||
|
|
||||||
// Dumper struct is for dumping cluster
|
// Dumper struct is for dumping cluster
|
||||||
type Dumper struct {
|
type Dumper struct {
|
||||||
cmd string
|
cmd string
|
||||||
kubeconfig string
|
kubeconfig string
|
||||||
resources []string
|
resources []string
|
||||||
filePaths []string
|
filePaths []string
|
||||||
fileContainer string
|
fileContainer string
|
||||||
namespace string
|
namespace string
|
||||||
location string
|
location string
|
||||||
errors string
|
errors string
|
||||||
mode int64
|
mode int64
|
||||||
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,
|
||||||
location: "cluster-dump",
|
location: "cluster-dump",
|
||||||
mode: int64(0o777),
|
mode: int64(0o777),
|
||||||
namespace: namespace,
|
namespace: namespace,
|
||||||
forwardport: forwardport,
|
forwardport: forwardport,
|
||||||
|
skipPodSummary: skipPodSummary,
|
||||||
}
|
}
|
||||||
resources := []string{
|
resources := []string{
|
||||||
"pods",
|
"pods",
|
||||||
@@ -352,18 +354,20 @@ func (d *Dumper) DumpCluster() error {
|
|||||||
crName = pod.Labels["app.kubernetes.io/instance"]
|
crName = pod.Labels["app.kubernetes.io/instance"]
|
||||||
}
|
}
|
||||||
// Get summary
|
// Get summary
|
||||||
output, err = d.getPodSummary(resourceType(d.crType), pod.Name, crName, ns.Name)
|
if !d.skipPodSummary {
|
||||||
if err != nil {
|
output, err = d.getPodSummary(resourceType(d.crType), pod.Name, crName, ns.Name)
|
||||||
d.logError(err.Error(), d.crType, pod.Name)
|
|
||||||
err = addToArchive(location, d.mode, []byte(err.Error()), tw)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error: create summary errors archive for pod %s in namespace %s: %v", pod.Name, ns.Name, err)
|
d.logError(err.Error(), d.crType, pod.Name)
|
||||||
}
|
err = addToArchive(location, d.mode, []byte(err.Error()), tw)
|
||||||
} else {
|
if err != nil {
|
||||||
err = addToArchive(location, d.mode, output, tw)
|
log.Printf("Error: create summary errors archive for pod %s in namespace %s: %v", pod.Name, ns.Name, err)
|
||||||
if err != nil {
|
}
|
||||||
d.logError(err.Error(), "create summary archive for pod "+pod.Name)
|
} else {
|
||||||
log.Printf("Error: create summary archive for pod %s: %v", pod.Name, err)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user