Skip to content

logging: fix the HTTP logger#4041

Merged
bwplotka merged 3 commits intothanos-io:mainfrom
GiedriusS:fix/logger
Apr 10, 2021
Merged

logging: fix the HTTP logger#4041
bwplotka merged 3 commits intothanos-io:mainfrom
GiedriusS:fix/logger

Conversation

@GiedriusS
Copy link
Copy Markdown
Member

@GiedriusS GiedriusS commented Apr 9, 2021

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.

Without this, the user only sees in the logs:

level=error ts=2021-04-09T10:22:05.3319924Z caller=http.go:44 protocol=http http.component=server msg="failed to parse host port for http log decision" err="address foo.bar: missing port in address"

Signed-off-by: Giedrius Statkevičius giedrius.statkevicius@vinted.com

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

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>
Copy link
Copy Markdown
Contributor

@yashrsharma44 yashrsharma44 left a 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 💪

wrapped := httputil.WrapResponseWriterWithStatus(w)
start := time.Now()
_, port, err := net.SplitHostPort(r.Host)
hostPort := r.Host
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Member Author

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 😛

Copy link
Copy Markdown
Contributor

@yashrsharma44 yashrsharma44 Apr 9, 2021

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 😄 !

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽

onprem
onprem previously approved these changes Apr 9, 2021
Copy link
Copy Markdown
Member

@onprem onprem left a 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>
Copy link
Copy Markdown
Member

@bwplotka bwplotka left a 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

- [#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
Copy link
Copy Markdown
Member

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 🤗

wrapped := httputil.WrapResponseWriterWithStatus(w)
start := time.Now()
_, port, err := net.SplitHostPort(r.Host)
hostPort := r.Host
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽

@bwplotka bwplotka merged commit dd97468 into thanos-io:main Apr 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants