-
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
Conversation
src/query/api/v1/httpd/handler.go
Outdated
@@ -131,8 +132,12 @@ func (h *Handler) RegisterRoutes() error { | |||
).Methods(openapi.HTTPMethod) | |||
h.router.PathPrefix(openapi.StaticURLPrefix).Handler(logged(openapi.StaticHandler())) | |||
|
|||
timeoutOpts := &prometheus.TimeoutOpts{ | |||
FetchTimeout: h.embeddedDbCfg.Client.FetchTimeout, |
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.
@r and @richardartoul are we guaranteed that embeddedDbCfg.Client != nil
here?
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.
Rather than having this, have the handler take in a TimeoutOpts
in NewHandler
and set it on the Handler stuct
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.
I don't think its guaranteed to be set
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.
Okay maybe I'll just set it here then if it's nil
Codecov Report
@@ Coverage Diff @@
## master #1342 +/- ##
=========================================
- Coverage 70.7% 60.2% -10.6%
=========================================
Files 822 810 -12
Lines 70160 68630 -1530
=========================================
- Hits 49643 41321 -8322
- Misses 17293 24309 +7016
+ Partials 3224 3000 -224
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #1342 +/- ##
========================================
- Coverage 70.7% 70.7% -0.1%
========================================
Files 822 822
Lines 70192 70204 +12
========================================
- Hits 49656 49637 -19
- Misses 17309 17332 +23
- Partials 3227 3235 +8
Continue to review full report at Codecov.
|
require.NoError(t, err) | ||
h.embeddedDbCfg = &dbconfig.DBConfiguration{Client: client.Configuration{FetchTimeout: 15 * time.Second}} | ||
|
||
return h, nil |
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.
No need to return nil here, instead change the return to just be *Handler
@@ -46,6 +47,10 @@ import ( | |||
|
|||
var ( | |||
promReadTestMetrics = newPromReadMetrics(tally.NewTestScope("", nil)) | |||
|
|||
timeoutOpts = &prometheus.TimeoutOpts{ |
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.
Add a test to check that the timeout is being honoured?
Fix test Fix tests Address comments Fix test
3f5aa0e
to
b59f733
Compare
defaultTimeout = time.Second * 15 | ||
maxTimeout = 5 * time.Minute | ||
// DefaultTimeout is the default timeout for fetch requests | ||
DefaultTimeout = 15 * time.Second |
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.
It feels a bit weird to export this from here; I think it would read better if you had this hardcoded backup value in src/query/api/v1/httpd/handler.go
and keep it unexported.
Then in common_test
hardcode the 15 seconds as the test value (might be better to up to 30 in light of user comments on gitter?)
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.
Yeah I went back and forth on this. I'll put in handler.go
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 comment
The 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 comment
The 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.
@@ -64,17 +64,17 @@ func TestTimeoutParse(t *testing.T) { | |||
req, _ := http.NewRequest("POST", "dummy", nil) | |||
req.Header.Add("timeout", "1ms") | |||
|
|||
timeout, err := ParseRequestTimeout(req) | |||
timeout, err := ParseRequestTimeout(req, time.Second) | |||
assert.NoError(t, err) | |||
assert.Equal(t, timeout, time.Millisecond) |
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
if embeddedDbCfg == nil { | ||
timeoutOpts.FetchTimeout = defaultTimeout | ||
} else { | ||
if embeddedDbCfg.Client.FetchTimeout < 0 { |
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.
Quick test to check this?
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.
LG, just one more test around setting default?
No description provided.