Skip to content
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

Metadata to labels result and filtering support #9702

Merged
merged 22 commits into from
Jul 24, 2023
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e7d0535
Add metadata labels to LabelResults and allow filtering
salvacorts Jun 13, 2023
c370b5c
support metric queries
salvacorts Jun 26, 2023
3821cbd
Fix test - now that mettadata is added to the labelResults, the itera…
salvacorts Jun 27, 2023
790aa6b
Fix lint issues
salvacorts Jun 27, 2023
60f04a7
Minor fixes after rebase
salvacorts Jul 18, 2023
321cf84
Comment-out integration testn and fix another test
salvacorts Jul 18, 2023
fb6bbd3
Add more tests
salvacorts Jul 18, 2023
1032a62
Rename argument
salvacorts Jul 18, 2023
c781c75
Add test for memchunk iter and pipeline
salvacorts Jul 18, 2023
3bb02da
Imprtove test to check for resulting labels
salvacorts Jul 19, 2023
6d457a5
Fix bug in moveNext wrt EOF not being correctly handled
salvacorts Jul 19, 2023
5716549
Remove integration test since it's now implemented as unit-test
salvacorts Jul 19, 2023
f3cc48e
Fix lint issues
salvacorts Jul 19, 2023
7370d07
Test metric queries with sample iterator
salvacorts Jul 19, 2023
920ec9a
More lint fixes
salvacorts Jul 19, 2023
b410b86
Fix lint issues (finally?)
salvacorts Jul 19, 2023
1e6f49b
Remove uneeded code after rebase
salvacorts Jul 19, 2023
cc6ce91
Merge branch 'main' into salvacorts/metadata-to-labelsResult-and-filt…
salvacorts Jul 20, 2023
ec685d4
Add more tests for metrics extractor
salvacorts Jul 20, 2023
b1f4b36
Merge branch 'main' into salvacorts/metadata-to-labelsResult-and-filt…
salvacorts Jul 21, 2023
37e7d8c
Improvements after merge
salvacorts Jul 21, 2023
ce51e4c
Update pkg/logql/log/pipeline.go
salvacorts Jul 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for memchunk iter and pipeline
salvacorts committed Jul 19, 2023
commit c781c7521887dba38743393583de3ff092c9a128
82 changes: 59 additions & 23 deletions pkg/chunkenc/memchunk_test.go
Original file line number Diff line number Diff line change
@@ -191,7 +191,6 @@ func TestBlock(t *testing.T) {
require.NoError(t, it.Close())
require.Equal(t, len(cases), idx)

// TODO: Test labels and metadata labels here.
sampleIt := chk.SampleIterator(context.Background(), time.Unix(0, 0), time.Unix(0, math.MaxInt64), countExtractor)
idx = 0
for sampleIt.Next() {
@@ -1551,6 +1550,9 @@ func TestMemChunk_IteratorWithNonIndexedLabels(t *testing.T) {
for _, enc := range testEncoding {
enc := enc
t.Run(enc.String(), func(t *testing.T) {
streamLabels := labels.Labels{
{Name: "job", Value: "fake"},
}
chk := newMemChunkWithFormat(chunkFormatV4, enc, UnorderedWithMetadataHeadBlockFmt, testBlockSize, testTargetSize)
require.NoError(t, chk.Append(logprotoEntryWithMetadata(1, "lineA", []logproto.LabelAdapter{
{Name: "traceID", Value: "123"},
@@ -1570,30 +1572,64 @@ func TestMemChunk_IteratorWithNonIndexedLabels(t *testing.T) {
{Name: "user", Value: "d"},
})))

expectedLines := []string{"lineA", "lineB", "lineC", "lineD"}
expectedStreams := []string{
labels.FromStrings("traceID", "123", "user", "a").String(),
labels.FromStrings("traceID", "456", "user", "b").String(),
labels.FromStrings("traceID", "789", "user", "c").String(),
labels.FromStrings("traceID", "123", "user", "d").String(),
}
for _, tc := range []struct {
name string
query string
expectedLines []string
expectedStreams []string
}{
{
name: "no-filter",
query: `{job="fake"}`,
expectedLines: []string{"lineA", "lineB", "lineC", "lineD"},
},
{
name: "filter",
query: `{job="fake"} | traceID="789"`,
expectedLines: []string{"lineC"},
},
{
name: "filter-regex-or",
query: `{job="fake"} | traceID=~"456|789"`,
expectedLines: []string{"lineB", "lineC"},
},
{
name: "filter-regex-contains",
query: `{job="fake"} | traceID=~".*5.*"`,
expectedLines: []string{"lineB"},
},
{
name: "filter-regex-complex",
query: `{job="fake"} | traceID=~"^[0-9]2.*"`,
expectedLines: []string{"lineA", "lineD"},
},
{
name: "multiple-filters",
query: `{job="fake"} | traceID="123" | user="d"`,
expectedLines: []string{"lineD"},
},
} {
t.Run(tc.name, func(t *testing.T) {
expr, err := syntax.ParseLogSelector(tc.query, true)
require.NoError(t, err)

// We will run the test twice so the iterator will be created twice.
// This is to ensure that the iterator is correctly closed.
for i := 0; i < 2; i++ {
it, err := chk.Iterator(context.Background(), time.Unix(0, 0), time.Unix(0, math.MaxInt64), logproto.FORWARD, noopStreamPipeline)
require.NoError(t, err)
pipeline, err := expr.Pipeline()
require.NoError(t, err)

var lines []string
var streams []string
for it.Next() {
require.NoError(t, it.Error())
e := it.Entry()
lines = append(lines, e.Line)
streams = append(streams, logproto.FromLabelAdaptersToLabels(e.NonIndexedLabels).String())
}
assert.ElementsMatch(t, expectedLines, lines)
assert.ElementsMatch(t, expectedStreams, streams)
// We will run the test twice so the iterator will be created twice.
// This is to ensure that the iterator is correctly closed.
for i := 0; i < 2; i++ {
it, err := chk.Iterator(context.Background(), time.Unix(0, 0), time.Unix(0, math.MaxInt64), logproto.FORWARD, pipeline.ForStream(streamLabels))
require.NoError(t, err)

var lines []string
for it.Next() {
e := it.Entry()
lines = append(lines, e.Line)
}
assert.ElementsMatch(t, tc.expectedLines, lines)
}
})
}
})
}