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

Fix order of the returned results from badger backend. #1939

Merged
merged 5 commits into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
47 changes: 31 additions & 16 deletions plugin/storage/badger/spanstore/read_write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"io"
"io/ioutil"
"log"
"math/rand"
"os"
"runtime/pprof"
"testing"
Expand Down Expand Up @@ -128,11 +129,6 @@ func TestValidation(t *testing.T) {
params.Tags = map[string]string{"A": "B"}
_, err = sr.FindTraces(context.Background(), params)
assert.EqualError(t, err, "service name must be set")

// Only StartTimeMin and Max (not supported yet)
// _, err := sr.FindTraces(context.Background(), params)
// assert.EqualError(t, err, "This query parameter is not supported yet")
burmanm marked this conversation as resolved.
Show resolved Hide resolved

})
}

Expand All @@ -143,15 +139,16 @@ func TestIndexSeeks(t *testing.T) {
spans := 3
tid := startT
for i := 0; i < traces; i++ {
lowId := rand.Uint64()
tid = tid.Add(time.Duration(time.Millisecond * time.Duration(i)))

for j := 0; j < spans; j++ {
s := model.Span{
TraceID: model.TraceID{
Low: uint64(i),
Low: lowId,
High: 1,
},
SpanID: model.SpanID(j),
SpanID: model.SpanID(rand.Uint64()),
OperationName: fmt.Sprintf("operation-%d", j),
Process: &model.Process{
ServiceName: fmt.Sprintf("service-%d", i%4),
Expand All @@ -171,11 +168,19 @@ func TestIndexSeeks(t *testing.T) {
},
},
}

err := sw.WriteSpan(&s)
assert.NoError(t, err)
}
}

testOrder := func(trs []*model.Trace) {
// Assert that we returned correctly in DESC time order
for l := 1; l < len(trs); l++ {
assert.True(t, trs[l].Spans[spans-1].StartTime.Before(trs[l-1].Spans[spans-1].StartTime))
}
}

params := &spanstore.TraceQueryParameters{
StartTimeMin: startT,
StartTimeMax: startT.Add(time.Duration(time.Millisecond * 10)),
Expand All @@ -185,6 +190,7 @@ func TestIndexSeeks(t *testing.T) {
trs, err := sr.FindTraces(context.Background(), params)
assert.NoError(t, err)
assert.Equal(t, 1, len(trs))
assert.Equal(t, spans, len(trs[0].Spans))

params.OperationName = "operation-1"
trs, err = sr.FindTraces(context.Background(), params)
Expand Down Expand Up @@ -215,6 +221,7 @@ func TestIndexSeeks(t *testing.T) {
trs, err = sr.FindTraces(context.Background(), params)
assert.NoError(t, err)
assert.Equal(t, 1, len(trs))
assert.Equal(t, spans, len(trs[0].Spans))

// Query limited amount of hits

Expand All @@ -224,17 +231,24 @@ func TestIndexSeeks(t *testing.T) {
trs, err = sr.FindTraces(context.Background(), params)
assert.NoError(t, err)
assert.Equal(t, 2, len(trs))
testOrder(trs)
burmanm marked this conversation as resolved.
Show resolved Hide resolved

// Check for DESC return order
// Check for DESC return order with duration index
params.NumTraces = 9
params.DurationMin = time.Duration(30 * time.Millisecond) // Filters one
params.DurationMax = time.Duration(50 * time.Millisecond) // Filters three
trs, err = sr.FindTraces(context.Background(), params)
assert.NoError(t, err)
assert.Equal(t, 9, len(trs))
assert.Equal(t, 5, len(trs))
testOrder(trs)

// Assert that we fetched correctly in DESC time order
for l := 1; l < len(trs); l++ {
assert.True(t, trs[l].Spans[spans-1].StartTime.Before(trs[l-1].Spans[spans-1].StartTime))
}
// Check for DESC return order without
burmanm marked this conversation as resolved.
Show resolved Hide resolved
params.DurationMin = 0
params.DurationMax = 0
trs, err = sr.FindTraces(context.Background(), params)
assert.NoError(t, err)
assert.Equal(t, 9, len(trs))
testOrder(trs)

// StartTime, endTime scan - full table scan (so technically no index seek)
params = &spanstore.TraceQueryParameters{
Expand All @@ -244,7 +258,9 @@ func TestIndexSeeks(t *testing.T) {

trs, err = sr.FindTraces(context.Background(), params)
assert.NoError(t, err)
assert.Equal(t, 6, len(trs))
assert.Equal(t, 5, len(trs))
burmanm marked this conversation as resolved.
Show resolved Hide resolved
assert.Equal(t, spans, len(trs[0].Spans))
testOrder(trs)

// StartTime and Duration queries
params.StartTimeMax = startT.Add(time.Duration(time.Hour * 10))
Expand All @@ -254,8 +270,7 @@ func TestIndexSeeks(t *testing.T) {
trs, err = sr.FindTraces(context.Background(), params)
assert.NoError(t, err)
assert.Equal(t, 6, len(trs))
assert.Equal(t, uint64(56), trs[0].Spans[0].TraceID.Low)
assert.Equal(t, uint64(51), trs[5].Spans[0].TraceID.Low)
testOrder(trs)
})
}

Expand Down
Loading