mirror of
https://github.com/grafana/loki.git
synced 2026-03-13 09:33:58 +08:00
test: fixup related to entry iterator (#21070)
This commit is contained in:
@@ -148,7 +148,7 @@ func Test_Unordered_InsertRetrieval(t *testing.T) {
|
||||
{0, "a", labels.EmptyLabels()}, {1, "b", labels.EmptyLabels()}, {0, "a", labels.FromStrings("a", "b")},
|
||||
},
|
||||
exp: []entry{
|
||||
{1, "b", labels.EmptyLabels()}, {0, "a", labels.EmptyLabels()}, {0, "a", labels.FromStrings("a", "b")},
|
||||
{1, "b", labels.EmptyLabels()}, {0, "a", labels.FromStrings("a", "b")}, {0, "a", labels.EmptyLabels()},
|
||||
},
|
||||
dir: logproto.BACKWARD,
|
||||
forFormat: UnorderedWithStructuredMetadataHeadBlockFmt,
|
||||
@@ -186,6 +186,8 @@ func Test_Unordered_InsertRetrieval(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
// For UnorderedHeadBlockFmt, structured metadata is stripped so both ts=0 entries share
|
||||
// the same stream and are returned in reverse insertion order.
|
||||
desc: "ts collision backward",
|
||||
input: []entry{
|
||||
{0, "a", labels.FromStrings("a", "b")}, {0, "b", labels.EmptyLabels()}, {1, "c", labels.EmptyLabels()},
|
||||
@@ -193,7 +195,22 @@ func Test_Unordered_InsertRetrieval(t *testing.T) {
|
||||
exp: []entry{
|
||||
{1, "c", labels.EmptyLabels()}, {0, "b", labels.EmptyLabels()}, {0, "a", labels.FromStrings("a", "b")},
|
||||
},
|
||||
dir: logproto.BACKWARD,
|
||||
dir: logproto.BACKWARD,
|
||||
forFormat: UnorderedHeadBlockFmt,
|
||||
},
|
||||
{
|
||||
// For UnorderedWithStructuredMetadataHeadBlockFmt, the two ts=0 entries have different
|
||||
// structured metadata so they end up in different streams. Tie-breaking by label string
|
||||
// puts {a="b"} before {} (since 'a' < '}' in ASCII).
|
||||
desc: "ts collision backward",
|
||||
input: []entry{
|
||||
{0, "a", labels.FromStrings("a", "b")}, {0, "b", labels.EmptyLabels()}, {1, "c", labels.EmptyLabels()},
|
||||
},
|
||||
exp: []entry{
|
||||
{1, "c", labels.EmptyLabels()}, {0, "a", labels.FromStrings("a", "b")}, {0, "b", labels.EmptyLabels()},
|
||||
},
|
||||
dir: logproto.BACKWARD,
|
||||
forFormat: UnorderedWithStructuredMetadataHeadBlockFmt,
|
||||
},
|
||||
{
|
||||
desc: "ts remove exact dupe forward",
|
||||
|
||||
@@ -271,7 +271,9 @@ func lessAscending(e1, e2 sortFields) bool {
|
||||
// The underlying stream hash may not be available, such as when merging LokiResponses in the
|
||||
// frontend which were sharded. Prefer to use the underlying stream hash when available,
|
||||
// which is needed in deduping code, but defer to label sorting when it's not present.
|
||||
if e1.streamHash == 0 {
|
||||
// Also defer to label sorting when both hashes are equal (e.g. entries from the same base
|
||||
// stream but with different structured metadata share the same base hash).
|
||||
if e1.streamHash == 0 || e1.streamHash == e2.streamHash {
|
||||
return e1.labels < e2.labels
|
||||
}
|
||||
return e1.streamHash < e2.streamHash
|
||||
@@ -281,7 +283,7 @@ func lessAscending(e1, e2 sortFields) bool {
|
||||
|
||||
func lessDescending(e1, e2 sortFields) bool {
|
||||
if e1.timeNanos == e2.timeNanos {
|
||||
if e1.streamHash == 0 {
|
||||
if e1.streamHash == 0 || e1.streamHash == e2.streamHash {
|
||||
return e1.labels < e2.labels
|
||||
}
|
||||
return e1.streamHash < e2.streamHash
|
||||
|
||||
Reference in New Issue
Block a user