Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.18] Fix bug report missing all logs for json logs #45026

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Extract to parseLog
  • Loading branch information
syw14 authored and istio-testing committed May 22, 2023
commit bcfa337b55a6a54fb4c31db0a5156d5ab28b7f87
18 changes: 9 additions & 9 deletions tools/bug-report/pkg/bugreport/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func addFlags(cmd *cobra.Command, args *config2.BugReportConfig) {
// input config
cmd.PersistentFlags().StringVarP(&configFile, "filename", "f", "",
"Path to a file containing configuration in YAML format. The file contents are applied over the default "+
"values and flag settings, with lists being replaced per JSON merge semantics.")
"values and flag settings, with lists being replaced per JSON merge semantics.")

// dry run
cmd.PersistentFlags().BoolVarP(&args.DryRun, "dry-run", "", false,
Expand All @@ -62,31 +62,31 @@ func addFlags(cmd *cobra.Command, args *config2.BugReportConfig) {
// timeouts and max sizes
cmd.PersistentFlags().DurationVar(&commandTimeout, "timeout", bugReportDefaultTimeout,
"Maximum amount of time to spend fetching logs. When timeout is reached "+
"only the logs captured so far are saved to the archive.")
"only the logs captured so far are saved to the archive.")
// include / exclude specs
cmd.PersistentFlags().StringSliceVar(&included, "include", bugReportDefaultInclude,
"Spec for which pod's proxy logs to include in the archive. See above for format and examples.")
cmd.PersistentFlags().StringSliceVar(&excluded, "exclude", bugReportDefaultExclude,
"Spec for which pod's proxy logs to exclude from the archive, after the include spec "+
"is processed. See above for format and examples.")
"is processed. See above for format and examples.")

// log time ranges
cmd.PersistentFlags().StringVar(&startTime, "start-time", "",
"Start time for the range of log entries to include in the archive. "+
"Default is the infinite past. If set, --duration must be unset.")
"Default is the infinite past. If set, --duration must be unset.")
cmd.PersistentFlags().StringVar(&endTime, "end-time", "",
"End time for the range of log entries to include in the archive. Default is now.")
cmd.PersistentFlags().DurationVar(&since, "duration", 0,
"How far to go back in time from end-time for log entries to include in the archive. "+
"Default is infinity. If set, --start-time must be unset.")
"Default is infinity. If set, --start-time must be unset.")

// log error control
cmd.PersistentFlags().StringSliceVar(&args.CriticalErrors, "critical-errs", nil,
"List of comma separated glob patterns to match against log error strings. "+
"If any pattern matches an error in the log, the logs is given the highest priority for archive inclusion.")
"If any pattern matches an error in the log, the logs is given the highest priority for archive inclusion.")
cmd.PersistentFlags().StringSliceVar(&args.IgnoredErrors, "ignore-errs", nil,
"List of comma separated glob patterns to match against log error strings. "+
"Any error matching these patterns is ignored when calculating the log importance heuristic.")
"Any error matching these patterns is ignored when calculating the log importance heuristic.")

// working dir to store temporary artifacts
cmd.PersistentFlags().StringVar(&tempDir, "dir", "",
Expand All @@ -98,7 +98,7 @@ func addFlags(cmd *cobra.Command, args *config2.BugReportConfig) {
// requests per second limit
cmd.PersistentFlags().IntVar(&args.RequestsPerSecondLimit, "rps-limit", 0,
"Requests per second limit to the Kubernetes API server, defaults to 10."+
"A higher limit can make bug report collection much faster.")
"A higher limit can make bug report collection much faster.")
}

func parseConfig() (*config2.BugReportConfig, error) {
Expand Down Expand Up @@ -145,7 +145,7 @@ func parseConfig() (*config2.BugReportConfig, error) {
}

func parseTimes(config *config2.BugReportConfig, startTime, endTime string, duration time.Duration) error {
if (startTime == "" && endTime == "" && config.Since == 0) {
if startTime == "" && endTime == "" {
config.TimeFilterApplied = false
} else {
config.TimeFilterApplied = true
Expand Down
27 changes: 10 additions & 17 deletions tools/bug-report/pkg/processlog/processlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,7 @@ func getTimeRange(logStr string, start, end time.Time) string {
var sb strings.Builder
write := false
for _, l := range strings.Split(logStr, "\n") {
var t *time.Time
var valid bool

if isJSONLog(logStr) {
t, _, _, valid = parseJSONLog(l)
} else {
t, _, _, valid = processPlainLog(l)
}

t, _, _, valid := parseLog(l)
if valid {
write = false
if (t.Equal(start) || t.After(start)) && (t.Equal(end) || t.Before(end)) {
Expand All @@ -93,14 +85,7 @@ func getTimeRange(logStr string, start, end time.Time) string {
func getStats(config *config.BugReportConfig, logStr string) *Stats {
out := &Stats{}
for _, l := range strings.Split(logStr, "\n") {
var level, text string
var valid bool
if isJSONLog(logStr) {
_, level, text, valid = parseJSONLog(l)
} else {
_, level, text, valid = processPlainLog(l)
}

_, level, text, valid := parseLog(l)
if !valid {
continue
}
Expand All @@ -123,6 +108,14 @@ func getStats(config *config.BugReportConfig, logStr string) *Stats {
return out
}

func parseLog(line string) (timeStamp *time.Time, level string, text string, valid bool) {
if isJSONLog(line) {
return parseJSONLog(line)
} else {
return processPlainLog(line)
}
}

func processPlainLog(line string) (timeStamp *time.Time, level string, text string, valid bool) {
lv := strings.Split(line, "\t")
if len(lv) < 3 {
Expand Down