-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: better reporting of airbyte chart errors #112
Changes from 5 commits
fd86ae5
682a395
98d0a5e
cc5d277
29ccd00
f2705ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package local | ||
|
||
import ( | ||
"bufio" | ||
"io" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
// 2024-09-10 20:16:24 WARN i.m.s.r.u.Loggers$Slf4JLogger(warn):299 - [273.... | ||
var javaLogRx = regexp.MustCompile(`^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \x1b\[(?:1;)?\d+m(?P<level>[A-Z]+)\x1b\[m (?P<msg>\S+ - .*)`) | ||
|
||
type javaLogLine struct { | ||
msg string | ||
level string | ||
} | ||
|
||
type javaLogScanner struct { | ||
scanner *bufio.Scanner | ||
line javaLogLine | ||
} | ||
|
||
func newJavaLogScanner(r io.Reader) *javaLogScanner { | ||
return &javaLogScanner{ | ||
scanner: bufio.NewScanner(r), | ||
line: javaLogLine{ | ||
msg: "", | ||
level: "DEBUG", | ||
}, | ||
} | ||
} | ||
|
||
func (j *javaLogScanner) Scan() bool { | ||
for { | ||
if ok := j.scanner.Scan(); !ok { | ||
return false | ||
} | ||
|
||
// skip java stacktrace noise | ||
if strings.HasPrefix(j.scanner.Text(), "\tat ") || strings.HasPrefix(j.scanner.Text(), "\t... ") { | ||
continue | ||
} | ||
|
||
m := javaLogRx.FindSubmatch(j.scanner.Bytes()) | ||
|
||
if m != nil { | ||
j.line.msg = string(m[2]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
according to https://pkg.go.dev/regexp#Regexp.FindSubmatch |
||
j.line.level = string(m[1]) | ||
} else { | ||
j.line.msg = j.scanner.Text() | ||
} | ||
return true | ||
} | ||
} | ||
|
||
func (j *javaLogScanner) Err() error { | ||
return j.scanner.Err() | ||
} | ||
|
||
func getAllJavaLogLines(r io.Reader) ([]javaLogLine, error) { | ||
lines := []javaLogLine{} | ||
s := newJavaLogScanner(r) | ||
for s.Scan() { | ||
lines = append(lines, s.line) | ||
} | ||
return lines, s.Err() | ||
} | ||
|
||
func getLastJavaLogError(r io.Reader) (string, error) { | ||
lines, err := getAllJavaLogLines(r) | ||
if err != nil { | ||
return "", err | ||
} | ||
for i := len(lines) - 1; i >= 0; i-- { | ||
if lines[i].level == "ERROR" { | ||
return lines[i].msg, nil | ||
} | ||
} | ||
return "", nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is true that most of the pods are running Java services, but not all. Just wanna make note of that in case we ever try to use this to pull errors from temporal or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, the log parsing stuff is fragile right now. And maybe I should remove the
java
part of the name. It's really just a log scanner for a certain format.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests and cleaned up the naming to not mention java