Skip to content

Conversation

@qihaiyan
Copy link
Contributor

@qihaiyan qihaiyan commented Oct 28, 2025

Description

{% if enabled_plugins["prometheus"] and not enabled_stream_plugins["prometheus"] then %}
    lua_shared_dict prometheus-metrics {* http.lua_shared_dict["prometheus-metrics"] *};
    -- add prometheus-cache here
    lua_shared_dict prometheus-cache {* http.lua_shared_dict["prometheus-cache"] *};
{% end  #%}

Maybe it's better to set prometheus-cache together with prometheus-metrics in ngx_tpl.lua

Only when use_apisix_base is set to true, will the prometheus-cache take effect.
But in order to integrate with QAT, i used a custom built openresty instead of apisix-runtime, so use_apisix_base is not true, and prometheus-cache is not setted in nginx.conf even if prometheus plugin is enabled.

Which issue(s) this PR fixes:

Fixes #12703

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. enhancement New feature or request labels Oct 28, 2025
out="$(curl http://127.0.0.1:9091/apisix/prometheus/metrics)"
if ! echo "$out" | grep "apisix_stream_connection_total{route=\"1\"} 1" > /dev/null; then
echo "failed: prometheus can't work in stream subsystem"
echo "failed: prometheus can't work in both http & stream subsystem"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional testing is needed; the existing tests cannot verify whether prometheus-cache is correctly generated when use_apisix_base=false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find out how to set use_apisix_base=false in ut environment, it's setted in env.lua:

    local use_apisix_base = true
    if not or_info:find("apisix-nginx-module", 1, true) then
        use_apisix_base = false
    end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the existing tests and didn't find anything related to use_apisix_base=false, so I think this is acceptable. Let's see what other maintainers think.

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:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add additional handling of prometheus-cache in ngx_tpl.lua

2 participants