-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Conversation
|
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,
Thanks for the patch!
@@ -16,6 +16,7 @@ function _M.serialize(ngx) | |||
return { | |||
request = { | |||
uri = ngx.var.request_uri, | |||
new_uri = ngx.var.uri, |
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.
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:
- use the same name as the Nginx variables (breaking change), and document them as being such.
- keep
uri
, but renamenew_uri
toupstream_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 whereuri
will be normalized (path normalization, percent-decoded...), andupstream_uri
will not. There will also be cases (most of the time probably), where bothuri
andupstream_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 :)
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.
@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.
@shiprabehera any update on the changes requested above? |
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, |
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.
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?
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.
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?
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.
@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).
@p0pr0ck5 , thanks for mentioning that. |
Hi @shiprabehera, sorry for the delay on this end. I will look over this again soon and let you know! |
@thibaultcha do you still have pending requested changes here? I still need to review this :) Just catching up on any blockers. |
@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 |
Thanks thibaultcha!
@shiprabehera any thoughts on this comment? |
@p0pr0ck5 @thibaultcha |
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.
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, |
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.
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 |
This LGTM. Will wait for @thibaultcha to dismiss the review, then I think we're good to go here. |
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 |
(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? 😄) |
@shiprabehera Thanks for giving it a try, but could we have only 1 commit here, like:
And no merge commit at all? Thanks! |
* add `request.upstream_uri` * rename `request.uri` to `request.request_uri` * rename `request.request_uri` to `request.request_url` From Kong#2445
@thibaultcha |
@shiprabehera Great, thank you! |
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. |
Thank you @thibaultcha |
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).
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
* add `request.upstream_uri` * rename `request.uri` to `request.request_uri` * rename `request.request_uri` to `request.request_url` From #2445
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
* add `request.upstream_uri` * rename `request.uri` to `request.request_uri` * rename `request.request_uri` to `request.request_url` From #2445
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
Summary
ngx.var.request_uri
is the original uri and is not updated if the uri is changed usingngx.set_uri(newUri)
. Instead,ngx.var.uri
reflects the new uri. Added a new field to reflect the modified uri.Full changelog
request_uri
torequest_url
Issues resolved
Fix #2441