forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathper_request_limits_test.go
62 lines (49 loc) · 1.76 KB
/
per_request_limits_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
//go:build integration
package integration
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/grafana/loki/v3/integration/client"
"github.com/grafana/loki/v3/integration/cluster"
"github.com/grafana/loki/v3/pkg/util/querylimits"
)
func TestPerRequestLimits(t *testing.T) {
clu := cluster.New(nil, cluster.SchemaWithTSDB, func(c *cluster.Cluster) {
c.SetSchemaVer("v13")
})
defer func() {
assert.NoError(t, clu.Cleanup())
}()
var (
tAll = clu.AddComponent(
"all",
"-target=all",
"-log.level=debug",
"-querier.per-request-limits-enabled=true",
)
)
require.NoError(t, clu.Run())
queryLimitsPolicy := client.InjectHeadersOption(map[string][]string{querylimits.HTTPHeaderQueryLimitsKey: {`{"maxQueryLength": "1m"}`}})
cliTenant := client.New("org1", "", tAll.HTTPURL(), queryLimitsPolicy)
// ingest log lines for tenant 1 and tenant 2.
require.NoError(t, cliTenant.PushLogLine("lineA", cliTenant.Now.Add(-45*time.Minute), nil, map[string]string{"job": "fake"}))
// check that per-rquest-limits are enforced
_, err := cliTenant.RunRangeQuery(context.Background(), `{job="fake"}`)
require.ErrorContains(t, err, "the query time range exceeds the limit (query length")
_, err = cliTenant.LabelNames(context.Background())
require.ErrorContains(t, err, "the query time range exceeds the limit (query length")
// check without policy header
cliTenant = client.New("org1", "", tAll.HTTPURL())
resp, err := cliTenant.RunRangeQuery(context.Background(), `{job="fake"}`)
require.NoError(t, err)
var lines []string
for _, stream := range resp.Data.Stream {
for _, val := range stream.Values {
lines = append(lines, val[1])
}
}
require.ElementsMatch(t, []string{"lineA"}, lines)
}