-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Fix stats hijack #1598
Fix stats hijack #1598
Conversation
2d82c69
to
d7003fd
Compare
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.
Hi @emilevauge,
I was so free to have a look at the code and left few comments. Please let me know when this is not appreciated!
middlewares/recover.go
Outdated
// RecoverHandler recovers from a panic in http handlers | ||
func RecoverHandler(next http.Handler) http.Handler { | ||
fn := func(w http.ResponseWriter, r *http.Request) { | ||
defer func() { |
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.
You could extract this anonymous fn and reuse it in the NegroniRecoverHandler.
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.
fixed
middlewares/stateful.go
Outdated
|
||
import "net/http" | ||
|
||
// Stateful interface groups all http interface that must be |
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.
Typo HTTP interfaces ..
.
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.
fixed
server/server.go
Outdated
@@ -525,6 +525,12 @@ func (server *Server) prepareServer(entryPointName string, router *middlewares.H | |||
return nil, err | |||
} | |||
|
|||
middlewaresStr := "" | |||
for _, handler := range negroni.Handlers() { | |||
middlewaresStr += reflect.TypeOf(handler).String() + " " |
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.
Is this here by intend or a left over?
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 added this intentionally ;)
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.
Ok :) To be honest I am not sure how useful I find this. With a simple configuration I currently get the following output:
Middlewares: negroni.HandlerFunc *middlewares.Logger *stats.Stats negroni.HandlerFunc
Additionally I have for example retries configured. It is not mentioned here, as this middleware is setup in the loadConfig()
method and specific to a backend. Therefore we should maybe make this message more explicit or extend the logging also on other positions. WDYT?
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.
Yep, you are right, as we don't have middlewares created in loadConfig
, it is a bit useless. I will remove it.
d7003fd
to
f3f0066
Compare
Any chance of this helping with #1591? |
@regner Indeed, it will fix the error |
f3f0066
to
e0902de
Compare
middlewares/recover.go
Outdated
import ( | ||
"github.com/codegangsta/negroni" | ||
"github.com/containous/traefik/log" | ||
"net/http" |
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.
Please group the non-stdlib imports below the stdlib ones 😉
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.
Ouch, I finally configured Gogland correctly on imports ^^
middlewares/recover_test.go
Outdated
"github.com/codegangsta/negroni" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" |
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.
Please group the non-stdlib imports below the stdlib ones.
e0902de
to
864bff3
Compare
Thanks @emilevauge. I wasn't entirely sure but if thats the case I eagerly look forward to this being merged. |
middlewares/recover_test.go
Outdated
t.Fatal(err) | ||
} | ||
if resp.StatusCode != 500 { | ||
t.Fatalf("Received non-%d response: %d\n", 500, resp.StatusCode) |
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 don't really need to replace the 500 error code with a variable, do we?
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 do ^^
middlewares/recover_test.go
Outdated
} | ||
} | ||
|
||
func TestNegroniRecoverHandler(t *testing.T) { |
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 think the two tests could be fairly easily merged into a single table-driven test by letting the handler be created through a func() http.Handler
or so?
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.
@timoreimann to be honest, as we are in the process of removing negroni
dep, I don't think that's what we want. TestNegroniRecoverHandler
will be removed soon ;)
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 good point. 👍
864bff3
to
bc225ec
Compare
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.
LGTM. 🎉
bc225ec
to
15fc2ae
Compare
Signed-off-by: Emile Vauge <[email protected]>
Signed-off-by: Emile Vauge <[email protected]>
15fc2ae
to
48a91d0
Compare
Description
This PR fixes #1315 and adds a generic http recover.
Fixes #1315, #1591