-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat(xrpc): register variable rpc_time #7040
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 tasks
spacewander
reviewed
May 13, 2022
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 can apply the patch:
index df6e430c..5bf3daa5 100644
--- apisix/core/ctx.lua
+++ apisix/core/ctx.lua
@@ -278,11 +278,12 @@ do
else
local getter = apisix_var_names[key]
if getter then
+ local ctx = t._ctx
if getter == true then
- val = ngx.ctx.api_ctx and ngx.ctx.api_ctx[key]
+ val = ctx and ctx[key]
else
-- the getter is registered by ctx.register_var
- val = getter(ngx.ctx.api_ctx)
+ val = getter(ctx)
end
else
@@ -341,6 +342,7 @@ function _M.set_vars_meta(ctx)
end
var._request = get_request()
+ var._ctx = ctx
setmetatable(var, mt)
ctx.var = var
end
diff --git t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua
index 28fa4abc..3ea0c7ea 100644
--- t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua
+++ t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua
@@ -30,12 +30,7 @@ local str_byte = string.byte
core.ctx.register_var("rpc_len", function(ctx)
- local curr_ctx = ctx.xrpc_session and ctx.xrpc_session._curr_ctx
- if not curr_ctx then
- core.log.warn("can't find current context")
- return nil
- end
- return curr_ctx.len
+ return ctx.len
end)
local _M = {}
spacewander
reviewed
May 13, 2022
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 can apply the patch:
index df6e430c..5bf3daa5 100644
--- apisix/core/ctx.lua
+++ apisix/core/ctx.lua
@@ -278,11 +278,12 @@ do
else
local getter = apisix_var_names[key]
if getter then
+ local ctx = t._ctx
if getter == true then
- val = ngx.ctx.api_ctx and ngx.ctx.api_ctx[key]
+ val = ctx and ctx[key]
else
-- the getter is registered by ctx.register_var
- val = getter(ngx.ctx.api_ctx)
+ val = getter(ctx)
end
else
@@ -341,6 +342,7 @@ function _M.set_vars_meta(ctx)
end
var._request = get_request()
+ var._ctx = ctx
setmetatable(var, mt)
ctx.var = var
end
diff --git t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua
index 28fa4abc..3ea0c7ea 100644
--- t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua
+++ t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua
@@ -30,12 +30,7 @@ local str_byte = string.byte
core.ctx.register_var("rpc_len", function(ctx)
- local curr_ctx = ctx.xrpc_session and ctx.xrpc_session._curr_ctx
- if not curr_ctx then
- core.log.warn("can't find current context")
- return nil
- end
- return curr_ctx.len
+ return ctx.len
end)
local _M = {}
update, thanks for pointing out a better way. |
spacewander
reviewed
May 15, 2022
spacewander
approved these changes
May 16, 2022
bzp2010
approved these changes
May 16, 2022
Liu-Junlin
pushed a commit
to Liu-Junlin/apisix
that referenced
this pull request
May 20, 2022
spacewander
pushed a commit
that referenced
this pull request
Jun 30, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes # (issue)
Checklist