Skip to content

Commit

Permalink
Query range should not support date where start == end.
Browse files Browse the repository at this point in the history
Since we are always checking against start inclusively and not end, this means this type of query
will always returns no result.

Fixes grafana#1702, the frontend was not handling this type of query correctly.

Signed-off-by: Cyril Tovena <[email protected]>
  • Loading branch information
cyriltovena authored and Ed Welch committed Mar 2, 2020
1 parent 75ef5c8 commit 4da4d74
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/loghttp/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

var (
errEndBeforeStart = errors.New("end timestamp must not be before start time")
errEndBeforeStart = errors.New("end timestamp must not be before or equal to start time")
errNegativeStep = errors.New("zero or negative query resolution step widths are not accepted. Try a positive integer")
errStepTooSmall = errors.New("exceeded maximum resolution of 11,000 points per timeseries. Try decreasing the query resolution (?step=XX)")
)
Expand Down Expand Up @@ -255,7 +255,7 @@ func ParseRangeQuery(r *http.Request) (*RangeQuery, error) {
return nil, err
}

if result.End.Before(result.Start) {
if result.End.Before(result.Start) || result.Start.Equal(result.End) {
return nil, errEndBeforeStart
}

Expand Down
1 change: 1 addition & 0 deletions pkg/loghttp/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestParseRangeQuery(t *testing.T) {
{"bad start", &http.Request{URL: mustParseURL(`?query={foo="bar"}&start=t`)}, nil, true},
{"bad end", &http.Request{URL: mustParseURL(`?query={foo="bar"}&end=t`)}, nil, true},
{"end before start", &http.Request{URL: mustParseURL(`?query={foo="bar"}&start=2016-06-10T21:42:24.760738998Z&end=2015-06-10T21:42:24.760738998Z`)}, nil, true},
{"end equal start", &http.Request{URL: mustParseURL(`?query={foo="bar"}&start=2016-06-10T21:42:24.760738998Z&end=2016-06-10T21:42:24.760738998Z`)}, nil, true},
{"bad limit", &http.Request{URL: mustParseURL(`?query={foo="bar"}&start=2016-06-10T21:42:24.760738998Z&end=2017-06-10T21:42:24.760738998Z&limit=h`)}, nil, true},
{"bad direction",
&http.Request{
Expand Down
5 changes: 5 additions & 0 deletions pkg/querier/queryrange/split_by_interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ func (h *splitByInterval) Do(ctx context.Context, r queryrange.Request) (queryra

intervals := splitByTime(lokiRequest, interval)

// no interval should not be processed by the frontend.
if len(intervals) == 0 {
return h.next.Do(ctx, r)
}

if sp := opentracing.SpanFromContext(ctx); sp != nil {
sp.LogFields(otlog.Int("n_intervals", len(intervals)))

Expand Down

0 comments on commit 4da4d74

Please sign in to comment.