nic-6443 commented on code in PR #12629:
URL: https://github.com/apache/apisix/pull/12629#discussion_r2373937889


##########
apisix/balancer.lua:
##########
@@ -194,7 +195,20 @@ end
 -- 2. each time we need to retry upstream
 local function pick_server(route, ctx)
     core.log.info("route: ", core.json.delay_encode(route, true))
-    core.log.info("ctx: ", core.json.delay_encode(ctx, true))
+    local redacted_ctx = core.table.deepcopy(ctx)
+    for name, conf in pairs(ctx.var._ctx.consumer.plugins) do
+        local plugin = require("apisix.plugins."..name)
+        local schema
+        if plugin.type == "auth" then
+            schema = plugin.consumer_schema
+        else
+            schema = plugin.schema
+        end
+        redacted_ctx.var._ctx.consumer.plugins[name] = redact_encrypted(conf, 
schema)
+        local redacted_auth = 
redact_encrypted(redacted_ctx.var._ctx.consumer.auth_conf, schema)
+        redacted_ctx.var._ctx.consumer.auth_conf = redacted_auth
+    end
+    core.log.info("ctx: ", core.json.delay_encode(redacted_ctx, true))

Review Comment:
   we should avoid to redact the log that will not be printed like 
`json.delay_encode`, my suggestion:
   ```
   local max_delay_encode_items = 16
   local delay_tab_idx = 0
   local delay_tab_arr = {}
   for i = 1, max_delay_encode_items do
       delay_tab_arr[i] = setmetatable({data = "", force = false}, {
           __tostring = function(self)
               if self.redact_func then
                   self.data = deepcopy(self.data)
                   self.redact_func(self.data)
               end
               local res, err = encode(self.data, self.force)
               if not res then
                   ngx.log(ngx.WARN, "failed to encode: ", err,
                           " force: ", self.force)
               end
   
               return res
           end
       })
   end
   
   
   function _M.delay_encode(data, force, redact_func)
       delay_tab_idx = delay_tab_idx+1
       if delay_tab_idx > max_delay_encode_items then
           delay_tab_idx = 1
       end
       delay_tab_arr[delay_tab_idx].data = data
       delay_tab_arr[delay_tab_idx].force = force
       delay_tab_arr[delay_tab_idx].redact_func = redact_func
       return delay_tab_arr[delay_tab_idx]
   end
   ```
   only execute `redact_func` when this line of log be printed actually.



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