mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
Alerting: Use default page size of 5000 when querying Loki for state history (#66315)
Always specify limit of 5000
This commit is contained in:
parent
cf7157f683
commit
a384194e15
@ -17,6 +17,8 @@ import (
|
||||
"github.com/weaveworks/common/http/client"
|
||||
)
|
||||
|
||||
const defaultPageSize = 5000
|
||||
|
||||
func NewRequester() client.Requester {
|
||||
return &http.Client{}
|
||||
}
|
||||
@ -222,6 +224,7 @@ func (c *httpLokiClient) setAuthAndTenantHeaders(req *http.Request) {
|
||||
req.Header.Add("X-Scope-OrgID", c.cfg.TenantID)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *httpLokiClient) rangeQuery(ctx context.Context, logQL string, start, end int64) (queryRes, error) {
|
||||
// Run the pre-flight checks for the query.
|
||||
if start > end {
|
||||
@ -234,6 +237,7 @@ func (c *httpLokiClient) rangeQuery(ctx context.Context, logQL string, start, en
|
||||
values.Set("query", logQL)
|
||||
values.Set("start", fmt.Sprintf("%d", start))
|
||||
values.Set("end", fmt.Sprintf("%d", end))
|
||||
values.Set("limit", fmt.Sprintf("%d", defaultPageSize))
|
||||
|
||||
queryURL.RawQuery = values.Encode()
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package historian
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@ -116,6 +117,28 @@ func TestLokiHTTPClient(t *testing.T) {
|
||||
exp := fmt.Sprintf(`{"streams": [{"stream": {}, "values": [["%d", "some line"]]}]}`, now.UnixNano())
|
||||
require.JSONEq(t, exp, sent)
|
||||
})
|
||||
|
||||
t.Run("range query", func(t *testing.T) {
|
||||
t.Run("passes along page size", func(t *testing.T) {
|
||||
req := NewFakeRequester().WithResponse(&http.Response{
|
||||
Status: "200 OK",
|
||||
StatusCode: 200,
|
||||
Body: io.NopCloser(bytes.NewBufferString(`{}`)),
|
||||
ContentLength: int64(0),
|
||||
Header: make(http.Header, 0),
|
||||
})
|
||||
client := createTestLokiClient(req)
|
||||
now := time.Now().UTC().UnixNano()
|
||||
q := `{from="state-history"}`
|
||||
|
||||
_, err := client.rangeQuery(context.Background(), q, now-100, now)
|
||||
|
||||
require.NoError(t, err)
|
||||
params := req.lastRequest.URL.Query()
|
||||
require.True(t, params.Has("limit"), "query params did not contain 'limit': %#v", params)
|
||||
require.Equal(t, fmt.Sprint(defaultPageSize), params.Get("limit"))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// This function can be used for local testing, just remove the skip call.
|
||||
|
Loading…
Reference in New Issue
Block a user