Skip to content
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

Modify log to add ngx.var.uri in request object #2445

Merged
merged 1 commit into from
Nov 1, 2017

Conversation

shiprabehera
Copy link
Contributor

@shiprabehera shiprabehera commented Apr 24, 2017

Summary

ngx.var.request_uri is the original uri and is not updated if the uri is changed using ngx.set_uri(newUri). Instead, ngx.var.uri reflects the new uri. Added a new field to reflect the modified uri.

Full changelog

  • Use the same name as the Nginx variables in request object of logs
  • Rename request_uri to request_url
  • New unit test

Issues resolved

Fix #2441

@p0pr0ck5
Copy link
Contributor

request_uri contains query arguments, uri does not. If the only difference here is a post-normalized representation, I think we need to append the query string. Thoughts?

Copy link
Member

@thibaultcha thibaultcha left a comment

Choose a reason for hiding this comment

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

Hi,

Thanks for the patch!

@@ -16,6 +16,7 @@ function _M.serialize(ngx)
return {
request = {
uri = ngx.var.request_uri,
new_uri = ngx.var.uri,
Copy link
Member

Choose a reason for hiding this comment

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

This definitely warrants a more careful approach or at least some discussion. We must make it obvious what the difference between those two values is. Two options:

  1. use the same name as the Nginx variables (breaking change), and document them as being such.
  2. keep uri, but rename new_uri to upstream_uri. Since we diverge from the Nginx variables, we would need to make them look similar, and would have to include the query string as @p0pr0ck5 suggested. However, there will still exist cases where uri will be normalized (path normalization, percent-decoded...), and upstream_uri will not. There will also be cases (most of the time probably), where both uri and upstream_uri will be identical, which could be confusing and/or wasteful.

I tend to lean towards 1., and open this against next, as a documented breaking change.

This will also need tests btw :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pablofmorales , correct. But the value of $uri can change - for example during redirects, which is not captured by $request_uri
@thibaultcha I agree that for most cases, both ngx.var.request_uri and ngx.var.uri would be same. Hence, renaming them could lead to confusion. In fact, this would only be useful if there is some redirect or uri modification happening and I want to log those as well. Let's use the same name as option 1 suggests. However, then we would have to modify the name of the field request_uri too. Maybe request_url ? :)

request_uri = ngx.var.request_uri,
uri = ngx.var.uri,
request_url = ngx.var.scheme.."://"..ngx.var.host..":"..ngx.var.server_port..ngx.var.request_uri 

I will add test cases, thanks.

@thibaultcha thibaultcha added the pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. label Apr 24, 2017
@p0pr0ck5 p0pr0ck5 self-assigned this May 30, 2017
@p0pr0ck5
Copy link
Contributor

@shiprabehera any update on the changes requested above?

@p0pr0ck5
Copy link
Contributor

Thanks for the update @shiprabehera! There is a merge conflict in the serializer though. Can we resolve this?

request_uri = ngx.var.scheme .. "://" .. ngx.var.host .. ":" .. ngx.var.server_port .. ngx.var.request_uri,
request_uri = ngx.var.request_uri,
uri = ngx.var.uri,
request_url = ngx.var.scheme.."://"..ngx.var.host..":"..ngx.var.server_port..ngx.var.request_uri,
Copy link
Contributor

Choose a reason for hiding this comment

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

so, this renames request_uri -> request_url, and makes request_uri a new value (the $request_uri) variable? this feels odd, and very much a breaking change. since we're introducing a new value request_url, why not just give it the new variable assignment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is a breaking change indeed. The whole point is to name the variables same as the Nginx variables to avoid confusion. Also, if we are mentioning parameters like scheme and host, it makes more sense to rename it to request_url, i.e url which is more specific as opposed to uri, no?

Copy link
Contributor

Choose a reason for hiding this comment

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

@shiprabehera thanks. Since this is a breaking change, we will need to point this change to the next branch (you can simply edit this PR), and will need to be rebased accordingly. We may also want to take some naming changes in 0010bce into account as well (not sure they're entirely relevant, but it's worth being aware of).

@shiprabehera shiprabehera changed the base branch from master to next July 6, 2017 12:29
@shiprabehera
Copy link
Contributor Author

shiprabehera commented Jul 6, 2017

@p0pr0ck5 , thanks for mentioning that.
0010bce has core router changes and does not refer to variables from the log file I have updated. This patch makes log variable names same as Nginx, does not change any core functionality.
Also, few integration test suites seem to fail. Could this be related?
Thanks.

@p0pr0ck5 p0pr0ck5 added pr/status/please review and removed pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. labels Jul 18, 2017
@p0pr0ck5
Copy link
Contributor

Hi @shiprabehera, sorry for the delay on this end. I will look over this again soon and let you know!

@p0pr0ck5
Copy link
Contributor

p0pr0ck5 commented Aug 1, 2017

@thibaultcha do you still have pending requested changes here? I still need to review this :) Just catching up on any blockers.

@thibaultcha
Copy link
Member

@p0pr0ck5 Nothing outstanding! This is looking good to me, at a glance. Although, if we are about to break to introduce more meaningful names to those properties, I'm thinking: "why not renaming uri to upstream_uri...

@p0pr0ck5
Copy link
Contributor

p0pr0ck5 commented Aug 7, 2017

Thanks thibaultcha!

why not renaming uri to upstream_uri

@shiprabehera any thoughts on this comment?

@shiprabehera
Copy link
Contributor Author

shiprabehera commented Aug 8, 2017

@p0pr0ck5 @thibaultcha
Sounds good! As long as we have clear distinction between them, no problem.

Copy link
Member

@thibaultcha thibaultcha left a comment

Choose a reason for hiding this comment

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

Everything looks good now except for this value to update since 0.11.0 :)

uri = ngx.var.request_uri,
request_uri = ngx.var.scheme .. "://" .. ngx.var.host .. ":" .. ngx.var.server_port .. ngx.var.request_uri,
request_uri = ngx.var.request_uri,
upstream_uri = ngx.var.uri,
Copy link
Member

Choose a reason for hiding this comment

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

Since 0.11.0, the upstream URI is determined via ngx.var.upstream_uri, and not set via ngx.req.set_uri() anymore, which means that this value need to be updated from ngx.var.uri to ngx.var.upstream_uri. Could you take care of that?

@thibaultcha thibaultcha added pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. and removed pr/status/please review labels Aug 19, 2017
@shiprabehera
Copy link
Contributor Author

@thibaultcha
Fixed it.

@p0pr0ck5 p0pr0ck5 added pr/status/please review and removed pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. labels Aug 23, 2017
@p0pr0ck5
Copy link
Contributor

This LGTM. Will wait for @thibaultcha to dismiss the review, then I think we're good to go here.

@thibaultcha
Copy link
Member

Looking good to me! Good to highlight this will be our first breaking change introduced after the 0.11.0 release - which means once this gets merged to next, it will be the first non-backwards compatible change compared to master!

@thibaultcha
Copy link
Member

(It looks like this patch could use some rebasing though - @shiprabehera will you take care of it to release a bit of the burden from @p0pr0ck5's shoulders? 😄)

@thibaultcha
Copy link
Member

@shiprabehera Thanks for giving it a try, but could we have only 1 commit here, like:

feat(log) improve uri fields in basic log serializer

* add `request.upstream_uri`
* rename `request.uri` to `request.request_uri`
* rename `request.request_uri` to `request.request_url`

From #2445

And no merge commit at all?

Thanks!

@thibaultcha thibaultcha added the pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. label Aug 28, 2017
* add `request.upstream_uri`
* rename `request.uri` to `request.request_uri`
* rename `request.request_uri` to `request.request_url`

From Kong#2445
@shiprabehera
Copy link
Contributor Author

@thibaultcha
Done. Thanks!

@thibaultcha
Copy link
Member

@shiprabehera Great, thank you!

@thibaultcha thibaultcha added pr/ready This PR is considered ready and can be merged at anytime (given it received no subsequent changes) and removed pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. labels Aug 29, 2017
@thibaultcha thibaultcha merged commit c9d6187 into Kong:next Nov 1, 2017
@thibaultcha
Copy link
Member

Merged! Thank you @shiprabehera - and sorry for the delay on our side. As per our breaking change policy, this should be scheduled for release in our next major version.

@shiprabehera
Copy link
Contributor Author

Thank you @thibaultcha

thibaultcha added a commit that referenced this pull request Dec 15, 2017
Reflecting back on #2445, the chosen names feel very redundant when
accessed from a queryable interface. The same way, `upstream_uri` seems
to have been wrongly added under the `request` scope, where it doesn't
belong.

This solution has the benefit of being less breaking as well. (Only one
field gets renamed).
thibaultcha added a commit that referenced this pull request Dec 15, 2017
Reflecting back on #2445, the chosen names feel very redundant when
accessed from a queryable interface. The same way, `upstream_uri` seems
to have been wrongly added under the `request` scope, where it doesn't
belong.

This solution has the benefit of being less breaking as well. (Only one
field gets renamed).

From #3098
thibaultcha pushed a commit that referenced this pull request Jan 16, 2018
* add `request.upstream_uri`
* rename `request.uri` to `request.request_uri`
* rename `request.request_uri` to `request.request_url`

From #2445
thibaultcha added a commit that referenced this pull request Jan 16, 2018
Reflecting back on #2445, the chosen names feel very redundant when
accessed from a queryable interface. The same way, `upstream_uri` seems
to have been wrongly added under the `request` scope, where it doesn't
belong.

This solution has the benefit of being less breaking as well. (Only one
field gets renamed).

From #3098
thibaultcha pushed a commit that referenced this pull request Jan 19, 2018
* add `request.upstream_uri`
* rename `request.uri` to `request.request_uri`
* rename `request.request_uri` to `request.request_url`

From #2445
thibaultcha added a commit that referenced this pull request Jan 19, 2018
Reflecting back on #2445, the chosen names feel very redundant when
accessed from a queryable interface. The same way, `upstream_uri` seems
to have been wrongly added under the `request` scope, where it doesn't
belong.

This solution has the benefit of being less breaking as well. (Only one
field gets renamed).

From #3098
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/ready This PR is considered ready and can be merged at anytime (given it received no subsequent changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants