(ctx context.Context, zw *zip.Writer, prometheusCfg csconfig.PrometheusCfg, endpoint string)
| 363 | } |
| 364 | |
| 365 | func (cli *cliSupport) dumpPprof(ctx context.Context, zw *zip.Writer, prometheusCfg csconfig.PrometheusCfg, endpoint string) error { |
| 366 | fmt.Fprintf(os.Stdout, "Collecting pprof/%s data\n", endpoint) |
| 367 | |
| 368 | ctx, cancel := context.WithTimeout(ctx, 120*time.Second) |
| 369 | defer cancel() |
| 370 | |
| 371 | req, err := http.NewRequestWithContext( |
| 372 | ctx, |
| 373 | http.MethodGet, |
| 374 | fmt.Sprintf( |
| 375 | "http://%s/debug/pprof/%s", |
| 376 | net.JoinHostPort( |
| 377 | prometheusCfg.ListenAddr, |
| 378 | strconv.Itoa(prometheusCfg.ListenPort), |
| 379 | ), |
| 380 | endpoint, |
| 381 | ), |
| 382 | http.NoBody, |
| 383 | ) |
| 384 | if err != nil { |
| 385 | return fmt.Errorf("could not create request to pprof endpoint: %w", err) |
| 386 | } |
| 387 | |
| 388 | client := &http.Client{} |
| 389 | |
| 390 | resp, err := client.Do(req) |
| 391 | if err != nil { |
| 392 | return fmt.Errorf("could not get pprof data from endpoint: %w", err) |
| 393 | } |
| 394 | |
| 395 | defer resp.Body.Close() |
| 396 | |
| 397 | cli.writeToZip(zw, SUPPORT_PPROF_DIR+endpoint+".pprof", time.Now(), resp.Body) |
| 398 | |
| 399 | return nil |
| 400 | } |
| 401 | |
| 402 | func (cli *cliSupport) dumpProfiles(zw *zip.Writer) { |
| 403 | fmt.Fprintln(os.Stdout, "Collecting crowdsec profile") |
no test coverage detected