forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloki_simple_scalable_test.go
75 lines (61 loc) · 1.92 KB
/
loki_simple_scalable_test.go
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
75
package integration
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/grafana/loki/integration/client"
"github.com/grafana/loki/integration/cluster"
)
func TestSimpleScalableIngestQuery(t *testing.T) {
clu := cluster.New()
defer func() {
assert.NoError(t, clu.Cleanup())
}()
var (
tRead = clu.AddComponent(
"read",
"-target=read",
)
tWrite = clu.AddComponent(
"write",
"-target=write",
)
)
require.NoError(t, clu.Run())
tenantID := randStringRunes()
now := time.Now()
cliWrite := client.New(tenantID, "", tWrite.HTTPURL().String())
cliWrite.Now = now
cliRead := client.New(tenantID, "", tRead.HTTPURL().String())
cliRead.Now = now
t.Run("ingest logs", func(t *testing.T) {
// ingest some log lines
require.NoError(t, cliWrite.PushLogLineWithTimestamp("lineA", now.Add(-45*time.Minute), map[string]string{"job": "fake"}))
require.NoError(t, cliWrite.PushLogLineWithTimestamp("lineB", now.Add(-45*time.Minute), map[string]string{"job": "fake"}))
require.NoError(t, cliWrite.PushLogLine("lineC", map[string]string{"job": "fake"}))
require.NoError(t, cliWrite.PushLogLine("lineD", map[string]string{"job": "fake"}))
})
t.Run("query", func(t *testing.T) {
resp, err := cliRead.RunRangeQuery(`{job="fake"}`)
require.NoError(t, err)
assert.Equal(t, "streams", resp.Data.ResultType)
var lines []string
for _, stream := range resp.Data.Stream {
for _, val := range stream.Values {
lines = append(lines, val[1])
}
}
assert.ElementsMatch(t, []string{"lineA", "lineB", "lineC", "lineD"}, lines)
})
t.Run("label-names", func(t *testing.T) {
resp, err := cliRead.LabelNames()
require.NoError(t, err)
assert.ElementsMatch(t, []string{"job"}, resp)
})
t.Run("label-values", func(t *testing.T) {
resp, err := cliRead.LabelValues("job")
require.NoError(t, err)
assert.ElementsMatch(t, []string{"fake"}, resp)
})
}