-
Notifications
You must be signed in to change notification settings - Fork 404
Fix logCallerTrimmer when repo name is not just lakefs #9609
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
base: master
Are you sure you want to change the base?
Conversation
| }) | ||
| t.Run("dir name is just full absolute path", func(t *testing.T) { | ||
| frame := &runtime.Frame{ | ||
| File: "Users/Apps/lakeFS-foo/to/main.go", |
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.
not sure if this is even a legit case
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.
Thank you for the PR! Please address the comments.
| "io" | ||
| "os" | ||
| "reflect" | ||
| "regexp" |
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.
Why was the "reflect" library deleted? We need this lib :)
| r := regexp.MustCompile(fmt.Sprintf(`.*/([^/]*%s[^/]*)/.*`, ProjectDirectoryName)) | ||
| matches := r.FindStringSubmatch(strings.ToLower(frame.File)) | ||
| if len(matches) > 1 { | ||
| file = matches[1] |
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.
Unfortunately, this solution doesn’t achieve the desired result.
Note that logCallerTrimmer is intended to trim caller paths to be relative to the project root.
From the Go docs:
FindStringSubmatch returns a slice of strings containing the text of the leftmost match of the regular expression in s and the matches, if any, of its subexpressions, as described in the “Submatch” section of the package comment.
A return value of nil indicates no match.
(See an example in the docs)
Applying this to our case:
For the path:
"/Users/annaseliverstov/work/lakefs-anna/pkg/block/factory/build.go"
The matches slice will contain:
matches[0] == "/Users/annaseliverstov/work/lakefs-anna/pkg/block/factory/build.go"
matches[1] == "lakefs-anna"
So the resulting file value would be:
file = "lakefs-anna"
When the expected result should be:
file = "pkg/block/factory/build.go"
Please make sure your solution also correctly handles paths like:
"/Users/annaseliverstov/work/lakefs-anna/cmd/lakefs/cmd/run.go"
"/Users/annaseliverstov/work/lakefs-anna/lakefs-anna/pkg/block/factory/build.go"
Maybe you can find a way to extract the project root?
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.
Looks like the tests are failing with the current solution, please run them locally before submitting next time :)
| Line: 42, | ||
| Function: "main.someFunction", | ||
| } | ||
| wantFile := "lakefs/to/main.go:42" |
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.
In this case actually it should be: wantFile := "to/main.go:42" if assuming the lakefs in the path is the project root
Closes #9296
Change Description
Background
When the repo name is not just "lakefs" then the prettifier in the logger logs the file path in a weird way. For example, so far, if the repo was named e.g. lakeFS-foo, then the logger logged it as "file":"-foo/pkg/api/controller.go:1835"
Bug Fix
If this PR is a bug fix, please let us know about:
New Feature
If this PR introduces a new feature, describe it here.
Testing Details
Unit test included
Breaking Change?
No
Additional info
Logs, outputs, screenshots of changes if applicable (CLI / GUI changes)
Contact Details
How can we get in touch with you if we need more info? (ex. email@example.com)