getLog fetches the logs for the given namespace/pod/container and returns the log text and stats for it.
(runner *kubectlcmd.Runner, resources *cluster2.Resources, config *config.BugReportConfig, namespace, pod, container string, )
| 512 | |
| 513 | // getLog fetches the logs for the given namespace/pod/container and returns the log text and stats for it. |
| 514 | func getLog(runner *kubectlcmd.Runner, resources *cluster2.Resources, config *config.BugReportConfig, |
| 515 | namespace, pod, container string, |
| 516 | ) (string, *processlog.Stats, int, error) { |
| 517 | defer logRuntime(time.Now(), "Done getting logs only for %v/%v/%v", namespace, pod, container) |
| 518 | |
| 519 | log.Infof("Getting logs for %s/%s/%s...", namespace, pod, container) |
| 520 | |
| 521 | var tailLines *int64 |
| 522 | if config.TailLines > 0 { |
| 523 | tailLines = &config.TailLines |
| 524 | } |
| 525 | var sinceTime *time.Time |
| 526 | if config.TimeFilterApplied && !config.StartTime.IsZero() { |
| 527 | sinceTime = &config.StartTime |
| 528 | } |
| 529 | |
| 530 | clog, err := runner.LogsWithOptions(namespace, pod, container, false, config.DryRun, tailLines, sinceTime) |
| 531 | if err != nil { |
| 532 | return "", nil, 0, err |
| 533 | } |
| 534 | if resources.ContainerRestarts(namespace, pod, container, common.IsCniPod(pod)) > 0 { |
| 535 | pclog, err := runner.LogsWithOptions(namespace, pod, container, true, config.DryRun, tailLines, sinceTime) |
| 536 | if err != nil { |
| 537 | return "", nil, 0, err |
| 538 | } |
| 539 | clog = "========= Previous log present (appended at the end) =========\n\n" + clog + |
| 540 | "\n\n========= Previous log =========\n\n" + pclog |
| 541 | } |
| 542 | var cstat *processlog.Stats |
| 543 | clog, cstat = processlog.Process(config, clog) |
| 544 | return clog, cstat, cstat.Importance(), nil |
| 545 | } |
| 546 | |
| 547 | func runAnalyze(config *config.BugReportConfig, params *content.Params, analyzeTimeout time.Duration) { |
| 548 | newParam := params.SetNamespace(common.NamespaceAll) |
no test coverage detected
searching dependent graphs…