fix: metrics reporting when LLM plugin is not enabled#12841
Conversation
Fix incorrect metrics reporting when LLM plugin is not enabled. Change default values from '0' to '' for LLM-related nginx variables (llm_time_to_first_token, llm_prompt_tokens, llm_completion_tokens) to properly detect when LLM functionality is not active. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
We found in apisix/plugins/prometheus/exporter.lua#L376-L394 that metrics are reported when the value is not empty. When the LLM plugin is not enabled, the default value is 0, which results in invalid metrics. |
|
Another possible solution is to check if |
Adjust the if statement might help |
|
Hi @qiqizjl, the proposed changes in this PR are incomplete and will cause a regression. We recommend creating an issue first to discuss a solution for this problem. |
|
The current PR implementation is incorrect, so I'm closing it for now. You can resubmit the PR according to the discussion in the issue. |
Summary
Fix incorrect metrics reporting when LLM plugin is not enabled.
Problem
When the LLM plugin is not enabled, the nginx variables for LLM metrics were defaulting to '0', which caused the metrics to be incorrectly reported as active even when no LLM functionality was being used.
Solution
Changed the default values from '0' to '' (empty string) for the following nginx variables:
llm_time_to_first_tokenllm_prompt_tokensllm_completion_tokensAlso updated the condition check in
openai-base.luato properly detect when LLM functionality is not active.Changes
apisix/cli/ngx_tpl.lua: Changed default values from '0' to ''apisix/plugins/ai-drivers/openai-base.lua: Updated condition check🤖 Generated with Claude Code