-
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
Get fetch timeout from db config #1342
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ import ( | |
"time" | ||
|
||
xmetrics "github.com/m3db/m3/src/dbnode/x/metrics" | ||
"github.com/m3db/m3/src/query/api/v1/handler/prometheus" | ||
"github.com/m3db/m3/src/query/executor" | ||
"github.com/m3db/m3/src/query/models" | ||
"github.com/m3db/m3/src/query/storage" | ||
|
@@ -47,6 +48,10 @@ import ( | |
var ( | ||
promReadTestMetrics = newPromReadMetrics(tally.NewTestScope("", nil)) | ||
defaultLookbackDuration = time.Minute | ||
|
||
timeoutOpts = &prometheus.TimeoutOpts{ | ||
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. Add a test to check that the timeout is being honoured? |
||
FetchTimeout: 15 * time.Second, | ||
} | ||
) | ||
|
||
func setupServer(t *testing.T) *httptest.Server { | ||
|
@@ -58,13 +63,16 @@ func setupServer(t *testing.T) *httptest.Server { | |
FetchTagged(gomock.Any(), gomock.Any(), gomock.Any()). | ||
Return(nil, false, fmt.Errorf("not initialized")) | ||
storage := test.NewSlowStorage(lstore, 10*time.Millisecond) | ||
promRead := readHandler(storage) | ||
promRead := readHandler(storage, timeoutOpts) | ||
server := httptest.NewServer(test.NewSlowHandler(promRead, 10*time.Millisecond)) | ||
return server | ||
} | ||
|
||
func readHandler(store storage.Storage) *PromReadHandler { | ||
return &PromReadHandler{engine: executor.NewEngine(store, tally.NewTestScope("test", nil), defaultLookbackDuration), promReadMetrics: promReadTestMetrics} | ||
func readHandler(store storage.Storage, timeoutOpts *prometheus.TimeoutOpts) *PromReadHandler { | ||
return &PromReadHandler{engine: executor.NewEngine(store, tally.NewTestScope("test", nil), defaultLookbackDuration), | ||
promReadMetrics: promReadTestMetrics, | ||
timeoutOpts: timeoutOpts, | ||
} | ||
} | ||
|
||
func TestPromReadParsing(t *testing.T) { | ||
|
@@ -79,11 +87,29 @@ func TestPromReadParsing(t *testing.T) { | |
require.Equal(t, len(r.Queries), 1) | ||
} | ||
|
||
func TestPromFetchTimeoutParsing(t *testing.T) { | ||
logging.InitWithCores(nil) | ||
ctrl := gomock.NewController(t) | ||
storage, _ := m3.NewStorageAndSession(t, ctrl) | ||
promRead := &PromReadHandler{ | ||
engine: executor.NewEngine(storage, tally.NewTestScope("test", nil), defaultLookbackDuration), | ||
promReadMetrics: promReadTestMetrics, | ||
timeoutOpts: &prometheus.TimeoutOpts{ | ||
FetchTimeout: 2 * time.Minute, | ||
}, | ||
} | ||
|
||
req, _ := http.NewRequest("POST", PromReadURL, test.GeneratePromReadBody(t)) | ||
dur, err := prometheus.ParseRequestTimeout(req, promRead.timeoutOpts.FetchTimeout) | ||
require.NoError(t, err) | ||
assert.Equal(t, 2*time.Minute, dur) | ||
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. Nice! Can you add a test with a default, and an invalid timeout value? 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. We have these tests in the native package. Not sure we need to duplicate. |
||
} | ||
|
||
func TestPromReadParsingBad(t *testing.T) { | ||
logging.InitWithCores(nil) | ||
ctrl := gomock.NewController(t) | ||
storage, _ := m3.NewStorageAndSession(t, ctrl) | ||
promRead := readHandler(storage) | ||
promRead := readHandler(storage, timeoutOpts) | ||
req, _ := http.NewRequest("POST", PromReadURL, strings.NewReader("bad body")) | ||
_, err := promRead.parseRequest(req) | ||
require.NotNil(t, err, "unable to parse request") | ||
|
@@ -97,7 +123,7 @@ func TestPromReadStorageWithFetchError(t *testing.T) { | |
Return(nil, true, fmt.Errorf("unable to get data")) | ||
session.EXPECT().IteratorPools(). | ||
Return(nil, nil) | ||
promRead := readHandler(storage) | ||
promRead := readHandler(storage, timeoutOpts) | ||
req := test.GeneratePromReadRequest() | ||
_, err := promRead.read(context.TODO(), httptest.NewRecorder(), req, time.Hour) | ||
require.NotNil(t, err, "unable to read from storage") | ||
|
@@ -154,7 +180,7 @@ func TestReadErrorMetricsCount(t *testing.T) { | |
defer closer.Close() | ||
readMetrics := newPromReadMetrics(scope) | ||
|
||
promRead := &PromReadHandler{engine: executor.NewEngine(storage, scope, defaultLookbackDuration), promReadMetrics: readMetrics} | ||
promRead := &PromReadHandler{engine: executor.NewEngine(storage, scope, defaultLookbackDuration), promReadMetrics: readMetrics, timeoutOpts: timeoutOpts} | ||
req, _ := http.NewRequest("POST", PromReadURL, test.GeneratePromReadBody(t)) | ||
promRead.ServeHTTP(httptest.NewRecorder(), req) | ||
|
||
|
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.
Shouldn't this fail?
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.
Oops never mind github hid the top bit