spacewander commented on code in PR #6960:
URL: https://github.com/apache/apisix/pull/6960#discussion_r869814674


##########
apisix/stream/xrpc/runner.lua:
##########
@@ -71,9 +79,58 @@ local function put_req_ctx(session, ctx)
 end
 
 
+local function filter_logger(ctx, logger)
+    if not logger then
+       return false
+    end
+
+    if not logger.filter or #logger.filter == 0 then
+        -- no valid filter, default execution plugin
+        return true
+    end
+
+    -- key and version are divided by per-logger level
+    local key = "xrpc-logger" .. ctx.conf_id

Review Comment:
   We can use ctx.conf_id directly?



##########
apisix/stream/xrpc/runner.lua:
##########
@@ -14,14 +14,22 @@
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 --
+local require = require
 local core = require("apisix.core")
+local expr = require("resty.expr.v1")
 local pairs = pairs
 local ngx = ngx
 local ngx_now = ngx.now
 local OK = ngx.OK
 local DECLINED = ngx.DECLINED
 local DONE = ngx.DONE
+local pcall = pcall
+local ipairs = ipairs
+local tostring = tostring
 
+local logger_expr_cache = core.lrucache.new({
+    ttl = 300, count = 32

Review Comment:
   Personally speaking, what about using a larger count like 1024?



##########
apisix/stream/xrpc/runner.lua:
##########
@@ -71,9 +79,58 @@ local function put_req_ctx(session, ctx)
 end
 
 
+local function filter_logger(ctx, logger)
+    if not logger then
+       return false
+    end
+
+    if not logger.filter or #logger.filter == 0 then
+        -- no valid filter, default execution plugin
+        return true
+    end
+
+    -- key and version are divided by per-logger level
+    local key = "xrpc-logger" .. ctx.conf_id
+    local version = tostring(logger.filter)
+    local filter_expr, err = logger_expr_cache(key, version, expr.new, 
logger.filter)
+    if not filter_expr or err then

Review Comment:
   ```suggestion
       if not filter_expr then
   ```
   is enough?



##########
apisix/stream/xrpc/runner.lua:
##########
@@ -71,9 +79,58 @@ local function put_req_ctx(session, ctx)
 end
 
 
+local function filter_logger(ctx, logger)
+    if not logger then
+       return false
+    end
+
+    if not logger.filter or #logger.filter == 0 then
+        -- no valid filter, default execution plugin
+        return true
+    end
+
+    -- key and version are divided by per-logger level
+    local key = "xrpc-logger" .. ctx.conf_id
+    local version = tostring(logger.filter)

Review Comment:
   Actually, we can use the key directly as the version so we can save a 
`tostring`.
   As each logger's conf's memory address is independent.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to