Skip to content

Conversation

@johnmantios
Copy link
Contributor

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:

  1. Problem - The reason for opening the bug
  2. Root cause - Discovered root cause after investigation
  3. Solution - How the bug was fixed

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)

@johnmantios johnmantios marked this pull request as draft October 27, 2025 18:07
})
t.Run("dir name is just full absolute path", func(t *testing.T) {
frame := &runtime.Frame{
File: "Users/Apps/lakeFS-foo/to/main.go",
Copy link
Contributor Author

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

@arielshaqed arielshaqed requested a review from a team October 27, 2025 21:20
@Annaseli Annaseli self-requested a review October 30, 2025 11:11
@johnmantios johnmantios marked this pull request as ready for review October 30, 2025 19:33
Copy link
Contributor

@Annaseli Annaseli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnmantios

Thank you for the PR! Please address the comments.

"io"
"os"
"reflect"
"regexp"
Copy link
Contributor

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]
Copy link
Contributor

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?

Copy link
Contributor

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"
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logger strips filenames weirdly when repo is not named "lakefs"

3 participants