forked from grafana/tempo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquerier_test.go
More file actions
74 lines (64 loc) · 1.96 KB
/
querier_test.go
File metadata and controls
74 lines (64 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package querier
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/grafana/tempo/modules/ingester/client"
"github.com/grafana/tempo/pkg/tempopb"
"github.com/stretchr/testify/require"
"github.com/uber-go/atomic"
"github.com/weaveworks/common/user"
)
func TestQuerierUsesSearchExternalEndpoint(t *testing.T) {
numExternalRequests := atomic.NewInt32(0)
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(100 * time.Millisecond)
numExternalRequests.Inc()
}))
defer srv.Close()
tests := []struct {
cfg Config
queriesToExecute int
externalExpected int32
}{
// SearchExternalEndpoints is respected
{
cfg: Config{
SearchExternalEndpoints: []string{srv.URL},
},
queriesToExecute: 3,
externalExpected: 3,
},
// No SearchExternalEndpoints causes the querier to service everything internally
{
cfg: Config{},
queriesToExecute: 3,
externalExpected: 0,
},
// SearchPreferSelf is respected. this test won't pass b/c SearchBlock fails instantly and so
// all 3 queries are executed locally and nothing is proxied to the external endpoint.
// we'd have to mock the storage.Store interface to get this to pass. it's a big interface.
// {
// cfg: Config{
// SearchExternalEndpoints: []string{srv.URL},
// SearchPreferSelf: 2,
// },
// queriesToExecute: 3,
// externalExpected: 1,
// },
}
ctx := user.InjectOrgID(context.Background(), "blerg")
for _, tc := range tests {
numExternalRequests.Store(0)
q, err := New(tc.cfg, client.Config{}, nil, nil, nil)
require.NoError(t, err)
for i := 0; i < tc.queriesToExecute; i++ {
// ignore error purposefully here. all queries will error, but we don't care
// numExternalRequests will tell us what we need to know
_, _ = q.SearchBlock(ctx, &tempopb.SearchBlockRequest{})
}
require.Equal(t, tc.externalExpected, numExternalRequests.Load())
}
}