Skip to content

Commit

Permalink
Fix tests and naming after rebase upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
salvacorts committed Jul 13, 2023
1 parent 4c78a5d commit 21df77b
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 95 deletions.
5 changes: 0 additions & 5 deletions integration/loki_micro_services_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"
"time"

"github.com/prometheus/prometheus/model/labels"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -100,22 +99,18 @@ func TestMicroServicesDeleteRequest(t *testing.T) {
{
strconv.FormatInt(now.Add(-48*time.Hour).UnixNano(), 10),
"lineA",
labels.Labels{}.String(),
},
{
strconv.FormatInt(now.Add(-48*time.Hour).UnixNano(), 10),
"lineB",
labels.Labels{}.String(),
},
{
strconv.FormatInt(now.Add(-time.Minute).UnixNano(), 10),
"lineC",
labels.Labels{}.String(),
},
{
strconv.FormatInt(now.Add(-time.Minute).UnixNano(), 10),
"lineD",
labels.Labels{}.String(),
},
},
})
Expand Down
35 changes: 16 additions & 19 deletions pkg/chunkenc/memchunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/grafana/loki/pkg/iter"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/logql/log"
"github.com/grafana/loki/pkg/logql/syntax"
"github.com/grafana/loki/pkg/logqlmodel/stats"
"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/util/filter"
Expand Down Expand Up @@ -324,17 +323,17 @@ func (hb *headBlock) Convert(version HeadBlockFmt) (HeadBlock, error) {
out := version.NewBlock()

for _, e := range hb.entries {
if err := out.Append(e.t, e.s, e.metaLabels); err != nil {
if err := out.Append(e.t, e.s, e.nonIndexedLabels); err != nil {
return nil, err
}
}
return out, nil
}

type entry struct {
t int64
s string
metaLabels labels.Labels
t int64
s string
nonIndexedLabels labels.Labels
}

// NewMemChunk returns a new in-mem chunk.
Expand Down Expand Up @@ -686,12 +685,7 @@ func (c *MemChunk) Append(entry *logproto.Entry) error {
return ErrOutOfOrder
}

entryLabels, err := syntax.ParseLabels(entry.MetadataLabels)
if err != nil {
return err
}

if err := c.head.Append(entryTimestamp, entry.Line, entryLabels); err != nil {
if err := c.head.Append(entryTimestamp, entry.Line, entry.NonIndexedLabels); err != nil {
return err
}

Expand Down Expand Up @@ -1042,9 +1036,9 @@ func (hb *headBlock) Iterator(ctx context.Context, direction logproto.Direction,
streams[labels] = stream
}
stream.Entries = append(stream.Entries, logproto.Entry{
Timestamp: time.Unix(0, e.t),
Line: newLine,
MetadataLabels: e.metaLabels.String(),
Timestamp: time.Unix(0, e.t),
Line: newLine,
NonIndexedLabels: e.nonIndexedLabels,
})
}

Expand Down Expand Up @@ -1434,10 +1428,13 @@ func (e *entryBufferedIterator) Next() bool {
return false
}

metaLabels := make(labels.Labels, len(e.currMetadataLabels)/2)
for i := 0; i < len(e.currMetadataLabels); i += 2 {
metaLabels[i/2].Name = string(e.currMetadataLabels[i])
metaLabels[i/2].Value = string(e.currMetadataLabels[i+1])
var nonIndexedLabels labels.Labels
if len(e.currMetadataLabels) > 0 {
nonIndexedLabels = make(labels.Labels, len(e.currMetadataLabels)/2)
for i := 0; i < len(e.currMetadataLabels); i += 2 {
nonIndexedLabels[i/2].Name = string(e.currMetadataLabels[i])
nonIndexedLabels[i/2].Value = string(e.currMetadataLabels[i+1])
}
}

newLine, lbs, matches := e.pipeline.Process(e.currTs, e.currLine)
Expand All @@ -1446,7 +1443,7 @@ func (e *entryBufferedIterator) Next() bool {
}

e.currLabels = lbs
e.cur.MetadataLabels = metaLabels.String()
e.cur.NonIndexedLabels = nonIndexedLabels
e.cur.Timestamp = time.Unix(0, e.currTs)
e.cur.Line = string(newLine)
return true
Expand Down
29 changes: 14 additions & 15 deletions pkg/chunkenc/memchunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,64 +100,64 @@ func TestBlock(t *testing.T) {
cases := []struct {
ts int64
str string
lbs string
lbs labels.Labels
cut bool
}{
{
ts: 1,
str: "hello, world!",
lbs: labels.Labels{}.String(),
},
{
ts: 2,
str: "hello, world2!",
lbs: `{app="myapp"}`,
lbs: labels.Labels{
{Name: "app", Value: "myapp"},
},
},
{
ts: 3,
str: "hello, world3!",
lbs: `{a="a", b="b"}`,
lbs: labels.Labels{
{Name: "a", Value: "a"},
{Name: "b", Value: "b"},
},
},
{
ts: 4,
str: "hello, world4!",
lbs: labels.Labels{}.String(),
},
{
ts: 5,
str: "hello, world5!",
lbs: labels.Labels{}.String(),
},
{
ts: 6,
str: "hello, world6!",
lbs: labels.Labels{}.String(),
cut: true,
},
{
ts: 7,
str: "hello, world7!",
lbs: labels.Labels{}.String(),
},
{
ts: 8,
str: "hello, worl\nd8!",
lbs: `{a="a2", b="b"}`,
lbs: labels.Labels{
{Name: "a", Value: "a2"},
{Name: "b", Value: "b"},
},
},
{
ts: 8,
str: "hello, world 8, 2!",
lbs: labels.Labels{}.String(),
},
{
ts: 8,
str: "hello, world 8, 3!",
lbs: labels.Labels{}.String(),
},
{
ts: 9,
str: "",
lbs: labels.Labels{}.String(),
},
}

Expand All @@ -177,10 +177,9 @@ func TestBlock(t *testing.T) {
require.Equal(t, cases[idx].ts, e.Timestamp.UnixNano())
require.Equal(t, cases[idx].str, e.Line)
if chunkFormat < chunkFormatV4 {
//require.Empty(t, e.MetadataLabels)
require.Equal(t, labels.Labels{}.String(), e.MetadataLabels)
require.Empty(t, e.NonIndexedLabels)
} else {
require.Equal(t, cases[idx].lbs, e.MetadataLabels)
require.Equal(t, cases[idx].lbs, e.NonIndexedLabels)
}
idx++
}
Expand Down
26 changes: 14 additions & 12 deletions pkg/chunkenc/unordered.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (e *nsEntries) ValueAtDimension(_ uint64) int64 {
func (hb *unorderedHeadBlock) Append(ts int64, line string, metaLabels labels.Labels) error {
if hb.format < UnorderedWithMetadataHeadBlockFmt {
// metaLabels must be ignored for the previous head block formats
metaLabels = labels.Labels{}
metaLabels = nil
}
// This is an allocation hack. The rangetree lib does not
// support the ability to pass a "mutate" function during an insert
Expand Down Expand Up @@ -255,7 +255,7 @@ func (hb *unorderedHeadBlock) Iterator(
direction,
mint,
maxt,
func(ts int64, line string, metaLabels labels.Labels) error {
func(ts int64, line string, nonIndexedLabels labels.Labels) error {
// TODO: This should go to a separate PR
newLine, parsedLbs, matches := pipeline.ProcessString(ts, line)
if !matches {
Expand All @@ -274,9 +274,9 @@ func (hb *unorderedHeadBlock) Iterator(
}

stream.Entries = append(stream.Entries, logproto.Entry{
Timestamp: time.Unix(0, ts),
Line: newLine,
MetadataLabels: metaLabels.String(),
Timestamp: time.Unix(0, ts),
Line: newLine,
NonIndexedLabels: nonIndexedLabels,
})
return nil
},
Expand Down Expand Up @@ -567,13 +567,15 @@ func (hb *unorderedHeadBlock) LoadBytes(b []byte) error {
var metaLabels labels.Labels
if version >= UnorderedWithMetadataHeadBlockFmt.Byte() {
metaLn := db.uvarint()
metaLabels = make(labels.Labels, metaLn)
for j := 0; j < metaLn && db.err() == nil; j++ {
nameLn := db.uvarint()
valueLn := db.uvarint()
metaLabels[j] = labels.Label{
Name: string(db.bytes(nameLn)),
Value: string(db.bytes(valueLn)),
if metaLn > 0 {
metaLabels = make(labels.Labels, metaLn)
for j := 0; j < metaLn && db.err() == nil; j++ {
nameLn := db.uvarint()
valueLn := db.uvarint()
metaLabels[j] = labels.Label{
Name: string(db.bytes(nameLn)),
Value: string(db.bytes(valueLn)),
}
}
}
}
Expand Down
23 changes: 11 additions & 12 deletions pkg/chunkenc/unordered_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ func iterEq(t *testing.T, exp []entry, got iter.EntryIterator) {
var i int
for got.Next() {
require.Equal(t, logproto.Entry{
Timestamp: time.Unix(0, exp[i].t),
Line: exp[i].s,
MetadataLabels: labels.Labels{}.String(),
Timestamp: time.Unix(0, exp[i].t),
Line: exp[i].s,
}, got.Entry())
i++
}
Expand Down Expand Up @@ -167,7 +166,7 @@ func Test_Unordered_InsertRetrieval(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
hb := newUnorderedHeadBlock(UnorderedHeadBlockFmt)
for _, e := range tc.input {
require.Nil(t, hb.Append(e.t, e.s, e.metaLabels))
require.Nil(t, hb.Append(e.t, e.s, e.nonIndexedLabels))
}

itr := hb.Iterator(
Expand Down Expand Up @@ -230,7 +229,7 @@ func Test_UnorderedBoundedIter(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
hb := newUnorderedHeadBlock(UnorderedHeadBlockFmt)
for _, e := range tc.input {
require.Nil(t, hb.Append(e.t, e.s, e.metaLabels))
require.Nil(t, hb.Append(e.t, e.s, e.nonIndexedLabels))
}

itr := hb.Iterator(
Expand Down Expand Up @@ -376,15 +375,15 @@ func BenchmarkHeadBlockWrites(b *testing.B) {
if tc.unorderedWrites {
ts := rnd.Int63()
writes = append(writes, entry{
t: ts,
s: fmt.Sprint("line:", ts),
metaLabels: labels.Labels{{Name: "foo", Value: fmt.Sprint(ts)}},
t: ts,
s: fmt.Sprint("line:", ts),
nonIndexedLabels: labels.Labels{{Name: "foo", Value: fmt.Sprint(ts)}},
})
} else {
writes = append(writes, entry{
t: int64(i),
s: fmt.Sprint("line:", i),
metaLabels: labels.Labels{{Name: "foo", Value: fmt.Sprint(i)}},
t: int64(i),
s: fmt.Sprint("line:", i),
nonIndexedLabels: labels.Labels{{Name: "foo", Value: fmt.Sprint(i)}},
})
}
}
Expand All @@ -393,7 +392,7 @@ func BenchmarkHeadBlockWrites(b *testing.B) {
for n := 0; n < b.N; n++ {
writeFn := tc.fn()
for _, w := range writes {
writeFn(w.t, w.s, w.metaLabels)
writeFn(w.t, w.s, w.nonIndexedLabels)
}
}
})
Expand Down
9 changes: 5 additions & 4 deletions pkg/chunkenc/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/grafana/loki/pkg/chunkenc/testdata"
"github.com/grafana/loki/pkg/logproto"
"github.com/prometheus/prometheus/model/labels"
)

func logprotoEntry(ts int64, line string) *logproto.Entry {
Expand All @@ -15,11 +16,11 @@ func logprotoEntry(ts int64, line string) *logproto.Entry {
}
}

func logprotoEntryWithMetadata(ts int64, line string, metadataLabels string) *logproto.Entry {
func logprotoEntryWithMetadata(ts int64, line string, nonIndexedLabels labels.Labels) *logproto.Entry {
return &logproto.Entry{
Timestamp: time.Unix(0, ts),
Line: line,
MetadataLabels: metadataLabels,
Timestamp: time.Unix(0, ts),
Line: line,
NonIndexedLabels: nonIndexedLabels,
}
}

Expand Down
20 changes: 8 additions & 12 deletions pkg/ingester/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,29 +412,25 @@ var (
Labels: labels.Labels{labels.Label{Name: "stream", Value: "1"}}.String(),
Entries: []logproto.Entry{
{
Timestamp: time.Unix(0, 1),
Line: "1",
MetadataLabels: labels.Labels{}.String(),
Timestamp: time.Unix(0, 1),
Line: "1",
},
{
Timestamp: time.Unix(0, 2),
Line: "2",
MetadataLabels: labels.Labels{}.String(),
Timestamp: time.Unix(0, 2),
Line: "2",
},
},
}
stream2 = logproto.Stream{
Labels: labels.Labels{labels.Label{Name: "stream", Value: "2"}}.String(),
Entries: []logproto.Entry{
{
Timestamp: time.Unix(0, 1),
Line: "3",
MetadataLabels: labels.Labels{}.String(),
Timestamp: time.Unix(0, 1),
Line: "3",
},
{
Timestamp: time.Unix(0, 2),
Line: "4",
MetadataLabels: labels.Labels{}.String(),
Timestamp: time.Unix(0, 2),
Line: "4",
},
},
}
Expand Down
Loading

0 comments on commit 21df77b

Please sign in to comment.