Skip to content

feat: support custom_lua_shared_dict in global lua {} block and stream {} block#13286

Open
houtengfei193-spec wants to merge 1 commit intoapache:masterfrom
houtengfei193-spec:feat/custom-lua-shared-dict-meta-stream
Open

feat: support custom_lua_shared_dict in global lua {} block and stream {} block#13286
houtengfei193-spec wants to merge 1 commit intoapache:masterfrom
houtengfei193-spec:feat/custom-lua-shared-dict-meta-stream

Conversation

@houtengfei193-spec
Copy link
Copy Markdown

What this PR does

Currently, custom_lua_shared_dict only works in the http {} block (added in #5030). This PR extends the same mechanism to:

  1. The global lua {} block (requires apisix-nginx-module) — for shared dicts accessible by both HTTP and Stream subsystems
  2. The stream {} block — for stream-only shared dicts

Why

Users who need cross-subsystem shared dicts (e.g., for lifecycle management, custom metrics, global state sharing) currently have to manually patch ngx_tpl.lua. This PR allows them to simply configure it in config.yaml:

nginx_config:
  meta:
    custom_lua_shared_dict:
      my-global-dict: 1m       # shared between http and stream
  stream:
    custom_lua_shared_dict:
      my-stream-dict: 5m       # stream only

Changes

File Change
apisix/cli/ngx_tpl.lua Add dynamic rendering loop in lua {} and stream {} blocks
apisix/cli/config.lua Add default empty custom_lua_shared_dict for meta and stream
apisix/cli/schema.lua Add schema validation for meta and stream custom_lua_shared_dict
t/cli/test_custom_shared_dict.sh Test cases covering meta, stream, combined, and empty configs

Backward Compatibility

100% backward compatible. Default custom_lua_shared_dict is an empty table — no behavior change without explicit configuration.

Note: The meta.custom_lua_shared_dict feature only takes effect when apisix-nginx-module is compiled in (i.e., use_apisix_base is true), since the global lua {} block itself is only rendered in that case.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Apr 23, 2026
@houtengfei193-spec
Copy link
Copy Markdown
Author

Hi @nic-6443 @shreemaan-abhishek, could you help approve the CI workflow for this PR? It's a small change (size:M) extending custom_lua_shared_dict to support stream {} and global lua {} blocks. Thanks!

@houtengfei193-spec
Copy link
Copy Markdown
Author

@membphis @tzssangglass @spacewander

Could you please review this PR? All CI checks have passed.

This PR adds support for custom_lua_shared_dict in:

  • Global lua {} block (for sharing between HTTP and Stream subsystems)
  • stream {} block (for Stream-only dictionaries)

This resolves the need to manually modify ngx_tpl.lua when users need cross-subsystem shared dictionaries (e.g., for lifecycle management, custom metrics, global state sharing).

All 18 CI checks have passed (1 skipped for DockerHub build which is expected for PRs).

Thank you for your time and review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant