-
Notifications
You must be signed in to change notification settings - Fork 2.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
logging: fix the HTTP logger #4041
Conversation
Fix the HTTP logger so that it would take a look at the `url.URL` as well if `r.Host` is empty. Without this, the logging functionality doesn't quite work as Cortex uses `url.URL`: https://github.com/cortexproject/cortex/blob/faf92e8f3dbedfa769fbd6a3ff6e0fbd127694f5/pkg/frontend/downstream_roundtripper.go#L16-L23 Add a test to ensure that this works as expected in both ways. Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com> Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
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.
There are few questions, feel free to skip if it doesn't make sense
LGTM 💪
@@ -39,7 +39,11 @@ func (m *HTTPServerMiddleware) HTTPMiddleware(name string, next http.Handler) ht | |||
return func(w http.ResponseWriter, r *http.Request) { | |||
wrapped := httputil.WrapResponseWriterWithStatus(w) | |||
start := time.Now() | |||
_, port, err := net.SplitHostPort(r.Host) | |||
hostPort := r.Host |
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.
What should we do, if both r.Host
and r.URL.Host
is set, which one should we display?
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.
If r.Host
is there, it will get priority. We are only using r.URL.Host
if r.Host
is an empty 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.
I think we can print anyone of them, as long one of them is non-empty.
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.
From the docs:
// For client requests, the URL's Host specifies the server to
// connect to, while the Request's Host field optionally
// specifies the Host header value to send in the HTTP
// request.
So, we should give priority to r.Host
over r.URL.Host
because r.Host
might be more specific i.e. it's the Host
header 😛
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.
Looks like the current implementation is comprehensive 😄 !
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.
👍🏽
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. Thanks for the fix, we are seeing these error logs in our deployments as well.
Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com> Co-authored-by: Yash Sharma <yashrsharma44@gmail.com>
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.
Thanks! LGTM, just let's fix CHANGELOG but we can fix it anytime during release
@@ -30,6 +30,7 @@ We use _breaking :warning:_ to mark changes that are not backward compatible (re | |||
- [#3960](https://github.com/thanos-io/thanos/pull/3960) fix deduplication of equal alerts with different labels | |||
- [#3937](https://github.com/thanos-io/thanos/pull/3937) Store: Fix race condition in chunk pool. | |||
- [#4017](https://github.com/thanos-io/thanos/pull/4017) Query Frontend: fix downsampling iterator returning duplicate samples. | |||
- [#4017](https://github.com/thanos-io/thanos/pull/4041) Logging: fix the HTTP logger |
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.
Let's mention what is the fix exactly 🤗
@@ -39,7 +39,11 @@ func (m *HTTPServerMiddleware) HTTPMiddleware(name string, next http.Handler) ht | |||
return func(w http.ResponseWriter, r *http.Request) { | |||
wrapped := httputil.WrapResponseWriterWithStatus(w) | |||
start := time.Now() | |||
_, port, err := net.SplitHostPort(r.Host) | |||
hostPort := r.Host |
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.
👍🏽
Fix the HTTP logger so that it would take a look at the
url.URL
aswell if
r.Host
is empty. Without this, the logging functionality doesn't quite workas Cortex uses
url.URL
:https://github.com/cortexproject/cortex/blob/faf92e8f3dbedfa769fbd6a3ff6e0fbd127694f5/pkg/frontend/downstream_roundtripper.go#L16-L23
Add a test to ensure that this works as expected in both ways.
Without this, the user only sees in the logs:
Signed-off-by: Giedrius Statkevičius giedrius.statkevicius@vinted.com