fix(nacos): restrict registry fetch to privileged agent only#13236
fix(nacos): restrict registry fetch to privileged agent only#13236Baoyuantop wants to merge 1 commit intoapache:masterfrom
Conversation
All other discovery modules (tars, kubernetes, consul) only fetch service data in the privileged agent process. The nacos module was missing this restriction, causing every worker process to independently fetch from nacos servers, resulting in N-times redundant API requests and JSON parsing overhead. Add the same process.type() check used by other discovery modules so only the privileged agent fetches from nacos, while workers read from the shared dict populated by the agent. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Restricts Nacos service discovery fetching to the privileged agent process (matching behavior of other discovery modules) to prevent every worker from starting timers and issuing redundant Nacos API requests.
Changes:
- Add
ngx.processusage to detect process type in the Nacos discovery module. - Short-circuit
init_worker()unless running in the"privileged agent"process, so only that process performs periodic Nacos registry fetches.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if process.type() ~= "privileged agent" then | ||
| return | ||
| end |
There was a problem hiding this comment.
The new privileged-agent guard changes runtime behavior (workers no longer fetch/refresh Nacos data themselves). There are existing Nacos discovery tests under t/discovery/, but none assert that fetching happens only in the privileged agent (or that workers don’t start the fetch timer). Please add a regression test that fails if non-privileged workers perform Nacos fetches (e.g., by asserting request counts/log lines or by using worker_processes > 1 and verifying only one periodic fetch).
Description
All other discovery modules (tars, kubernetes, consul) restrict service data fetching to the privileged agent process only. The nacos module was missing this restriction, causing every worker process to independently start timers and fetch from nacos servers.
This results in:
This PR adds the same
process.type() ~= "privileged agent"check used by other discovery modules, so only the privileged agent fetches from nacos while workers read from the shared dict populated by the agent.Reference: This is a minimal fix extracted from the optimization discussed in #12867, adapted to the current codebase.
Which issue(s) this PR fixes:
Related to #12867
Checklist