-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
less opaque chunk keys on fs with v12 #5291
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package objectclient | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/prometheus/common/model" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/grafana/loki/pkg/storage/chunk" | ||
) | ||
|
||
func MustParseDayTime(s string) chunk.DayTime { | ||
t, err := time.Parse("2006-01-02", s) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return chunk.DayTime{ | ||
Time: model.TimeFromUnix(t.Unix()), | ||
} | ||
} | ||
|
||
func TestFSEncoder(t *testing.T) { | ||
schema := chunk.SchemaConfig{ | ||
Configs: []chunk.PeriodConfig{ | ||
{ | ||
From: MustParseDayTime("2020-01-01"), | ||
Schema: "v11", | ||
}, | ||
{ | ||
From: MustParseDayTime("2022-01-01"), | ||
Schema: "v12", | ||
}, | ||
}, | ||
} | ||
|
||
// chunk that resolves to v11 | ||
oldChunk := chunk.Chunk{ | ||
UserID: "fake", | ||
From: MustParseDayTime("2020-01-02").Time, | ||
Through: MustParseDayTime("2020-01-03").Time, | ||
Checksum: 123, | ||
Fingerprint: 456, | ||
ChecksumSet: true, | ||
} | ||
|
||
// chunk that resolves to v12 | ||
newChunk := chunk.Chunk{ | ||
UserID: "fake", | ||
From: MustParseDayTime("2022-01-02").Time, | ||
Through: MustParseDayTime("2022-01-03").Time, | ||
Checksum: 123, | ||
Fingerprint: 456, | ||
ChecksumSet: true, | ||
} | ||
|
||
for _, tc := range []struct { | ||
desc string | ||
from string | ||
exp string | ||
}{ | ||
{ | ||
desc: "before v12 encodes entire chunk", | ||
from: schema.ExternalKey(oldChunk), | ||
exp: "ZmFrZS8xYzg6MTZmNjM4ZDQ0MDA6MTZmNjhiM2EwMDA6N2I=", | ||
}, | ||
{ | ||
desc: "v12+ encodes encodes the non-directory trail", | ||
from: schema.ExternalKey(newChunk), | ||
exp: "fake/1c8/MTdlMTgxNWY4MDA6MTdlMWQzYzU0MDA6N2I=", | ||
}, | ||
} { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
chk, err := chunk.ParseExternalKey("fake", tc.from) | ||
require.Nil(t, err) | ||
require.Equal(t, tc.exp, FSEncoder(schema, chk)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: should we use
filepath.Join()
here?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.
We can't use
filepath
to build the keys when usingfsObjectClient
because it converts/
to os specific separator usingfilepath.FromSlash
andfilepath.ToSlash
. Basically, you would always use a/
when usingfsObjectClient
, irrespective of os type .If at all, we could use
path.Join
with always uses/
, but it does not seem necessary since we are anyways working with a/
above.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.
That's why I thought we should use it, to have files in individual directories, also on windows.
With
strings.Join()
it would result in files all in the same root directory? But on unix system it would be organized in subfolders.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.
Maybe I get something wrong here.
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.
What @chaudum said seems sound to me. The only time I can think where this would be problematic is mounting the same file system on different OS's (i.e. migrating on an NFS mounted Loki deployment), but I'm not sure that's something we can reasonably protect against. I'll merge this one as is in the meantime.
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.
I just think it's weird to have different file/directory structure on Unix and Windows.