-
Notifications
You must be signed in to change notification settings - Fork 454
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
[query] Add config for timeseries limit returned by single DB node #1644
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2d91b35
Add config and defaults for max timeseries limit returned from a sing…
30c9b1d
Fix disabled tests
robskillington 5ce21d1
Merge branch 'master' into r/add-config-limit
robskillington a6a64fd
Add tests for fetchoptionsbuilder
robskillington 7722f8a
Merge branch 'r/add-config-limit' of github.com:m3db/m3 into r/add-co…
robskillington 52f22fc
Fix build errors
robskillington 2028926
Fix tests in native package
robskillington bae3053
Add tests to default query limits to the prometheus docker integratio…
robskillington 03773a7
Fix comments
robskillington 3aeeaf3
Fix simple docker integration test
robskillington 4888588
Optionally use max timeout for the docker integration tests
robskillington 5887d97
Bump docker timeouts to avoid early failures
robskillington File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) 2019 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package handler | ||
|
||
import ( | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/m3db/m3/src/query/storage" | ||
xhttp "github.com/m3db/m3/src/x/net/http" | ||
) | ||
|
||
// FetchOptionsBuilder builds fetch options based on a request and default | ||
// config. | ||
type FetchOptionsBuilder interface { | ||
NewFetchOptions(req *http.Request) (*storage.FetchOptions, *xhttp.ParseError) | ||
} | ||
|
||
// FetchOptionsBuilderOptions provides options to use when creating a | ||
// fetch options builder. | ||
type FetchOptionsBuilderOptions struct { | ||
Limit int | ||
} | ||
|
||
type fetchOptionsBuilder struct { | ||
opts FetchOptionsBuilderOptions | ||
} | ||
|
||
// NewFetchOptionsBuilder returns a new fetch options builder. | ||
func NewFetchOptionsBuilder( | ||
opts FetchOptionsBuilderOptions, | ||
) FetchOptionsBuilder { | ||
return fetchOptionsBuilder{opts: opts} | ||
} | ||
|
||
func (b fetchOptionsBuilder) NewFetchOptions( | ||
req *http.Request, | ||
) (*storage.FetchOptions, *xhttp.ParseError) { | ||
fetchOpts := storage.NewFetchOptions() | ||
fetchOpts.Limit = b.opts.Limit | ||
if str := req.Header.Get(LimitMaxSeriesHeader); str != "" { | ||
n, err := strconv.Atoi(str) | ||
if err != nil { | ||
return nil, xhttp.NewParseError(err, http.StatusBadRequest) | ||
} | ||
fetchOpts.Limit = n | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: newline |
||
|
||
return fetchOpts, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright (c) 2019 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package handler | ||
|
||
import ( | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFetchOptionsBuilder(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
defaultLimit int | ||
headers map[string]string | ||
expectedLimit int | ||
expectedErr bool | ||
}{ | ||
{ | ||
name: "default limit with no headers", | ||
defaultLimit: 42, | ||
headers: map[string]string{}, | ||
expectedLimit: 42, | ||
}, | ||
{ | ||
name: "limit with header", | ||
defaultLimit: 42, | ||
headers: map[string]string{ | ||
LimitMaxSeriesHeader: "4242", | ||
}, | ||
expectedLimit: 4242, | ||
}, | ||
{ | ||
name: "bad header", | ||
defaultLimit: 42, | ||
headers: map[string]string{ | ||
LimitMaxSeriesHeader: "not_a_number", | ||
}, | ||
expectedErr: true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
builder := NewFetchOptionsBuilder(FetchOptionsBuilderOptions{ | ||
Limit: test.defaultLimit, | ||
}) | ||
|
||
req := httptest.NewRequest("GET", "/foo", nil) | ||
for k, v := range test.headers { | ||
req.Header.Add(k, v) | ||
} | ||
|
||
opts, err := builder.NewFetchOptions(req) | ||
|
||
if !test.expectedErr { | ||
require.NoError(t, err) | ||
require.Equal(t, test.expectedLimit, opts.Limit) | ||
} else { | ||
require.Error(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: newline