Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for the old query string regexp in the frontend. #1522

Merged
merged 1 commit into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/querier/queryrange/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cortexproject/cortex/pkg/querier/queryrange"
"github.com/go-kit/kit/log"
"github.com/grafana/loki/pkg/logql"
"github.com/prometheus/prometheus/pkg/labels"
)

// Config is the configuration for the queryrange tripperware
Expand Down Expand Up @@ -53,6 +54,13 @@ func NewTripperware(cfg Config, log log.Logger, limits queryrange.Limits) (front
return metricRT.RoundTrip(req)
}
if logSelector, ok := expr.(logql.LogSelectorExpr); ok {
// backport the old regexp params into the query params
regexp := params.Get("regexp")
if regexp != "" {
logSelector = logql.NewFilterExpr(logSelector, labels.MatchRegexp, regexp)
params.Set("query", logSelector.String())
req.URL.RawQuery = params.Encode()
}
filter, err := logSelector.Filter()
if err != nil {
return nil, err
Expand Down
43 changes: 43 additions & 0 deletions pkg/querier/queryrange/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,49 @@ func TestUnhandledPath(t *testing.T) {
require.NoError(t, err)
}

func TestRegexpParamsSupport(t *testing.T) {
tpw, stopper, err := NewTripperware(testConfig, util.Logger, fakeLimits{})
if stopper != nil {
defer func() { _ = stopper.Stop() }()
}
require.NoError(t, err)
rt, err := newfakeRoundTripper()
require.NoError(t, err)
defer rt.Close()

lreq := &LokiRequest{
Query: `{app="foo"}`, // no regex so it should go to the querier
Limit: 1000,
StartTs: testTime.Add(-6 * time.Hour),
EndTs: testTime,
Direction: logproto.FORWARD,
Path: "/loki/api/v1/query_range",
}

ctx := user.InjectOrgID(context.Background(), "1")
req, err := lokiCodec.EncodeRequest(ctx, lreq)
require.NoError(t, err)

// fudge a regexp params
params := req.URL.Query()
params.Set("regexp", "foo")
req.URL.RawQuery = params.Encode()

req = req.WithContext(ctx)
err = user.InjectOrgIDIntoHTTPRequest(ctx, req)
require.NoError(t, err)

count, h := promqlResult(streams)
rt.setHandler(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
// the query params should contain the filter.
require.Contains(t, r.URL.Query().Get("query"), `|~"foo"`)
h.ServeHTTP(rw, r)
}))
_, err = tpw(rt).RoundTrip(req)
require.Equal(t, 2, *count) // expecting the query to also be splitted since it has a filter.
require.NoError(t, err)
}

type fakeLimits struct {
maxQueryParallelism int
}
Expand Down