Repository navigation
fix(cli): preserve YAML data references when ignoring comments - #14085
ruanweihong-aaa wants to merge 6 commits into
Conversation
Address block scalar, cross-line reference and runtime reload feedback on apache#13686. Co-authored-by: asdf2014 <asdf2014@apache.org>
shreemaan-abhishek
left a comment
There was a problem hiding this comment.
Once a configuration contains any #, file.lua rescans the entire growing prefix for every reference... we need to find a better (performant) way to solve this problem.
There was a problem hiding this comment.
This PR introduces a significant performance regression in environment-variable substitution.
Once the expanded prefix contains #, is_in_yaml_data() rescans the entire growing prefix with libyaml for every subsequent reference. A single leading comment is enough to trigger this, even when the references are all in YAML data.
The local measurements recorded for 9bb1504, with one reference per route, show approximately quadratic growth:
| Routes | Before this PR | With this PR |
|---|---|---|
| 500 | < 0.01 s | 1.56 s |
| 1,000 | < 0.01 s | 6.1 s |
| 2,000 | < 0.01 s | 23.6 s |
This affects both startup and runtime configuration updates. config_yaml.parse runs synchronously in workers, so the additional parsing work can block request handling during reload. Concurrent request latency has not been measured.
Please address the repeated-prefix scanning before merging and add a scaling regression check alongside the functional tests. Ignoring environment references in comments should not make configuration loading quadratic.
Check YAML syntax boundaries for ordinary and Unicode values. Classify multiline references and block content in the batch scan while preserving the sequential fallback when context changes. Add scanner-count and compatibility regressions.
|
Pushed
The committed |
Description
Environment-variable references in commented-out Standalone YAML can cause startup or configuration updates to fail when a variable is unset. This PR uses the existing YAML scanner to distinguish comments from configuration data. References identified as comments remain verbatim and are not added to exported variables; data references retain the existing environment lookup, default-value and error-handling behavior.
This builds on #13686 by @asdf2014 and retains its standalone regression coverage.
Implementation
scan_reference_contextsreplaces each complete reference with a single-line marker in a separate buffer and records its source position. The existing YAML scanner classifies the markers using token spans. This also supports multiline placeholders: replacing a data reference consumes the placeholder's internal line breaks.|/>header from the body. A hash in the block body remains data. Line tracking handles LF, CRLF, CR, NEL, LS and PS.host:port, URLs, text containing spaces and Unicode text can reuse the classification. Quoted scalars retain their quote/escape checks. Block content uses conservative checks as well, including protection against empty or leading-space values changing inferred indentation.The scan result is local to one substitution call. No new dependency, persistent cache, escaping rule or restriction on accepted substitutions is introduced.
Regression tests included in this PR
t/cli/test_standalone.shcovers:Validation
On a Rocky Linux host, using the official
apache/apisix:3.19.0-ubunturuntime and dependencies with the021de40dsource tarball plus these changes:t/cli/test_standalone.sh: passed.t/config-center-yaml/route.t: 26/26 assertions passed. Test::Nginx emitted the previously observed process-cleanup timeout warnings.The tested production and test files match the submitted files. This is validation against the image's dependencies, not a fresh full dependency build. The new commit still needs GitHub CI.
Remaining limitation
The sequential fallback can still rescan growing prefixes and have quadratic overhead for syntax-changing values or contexts that cannot be classified in a batch. Scanner errors also retain the existing conservative data classification. This PR does not establish linear behavior for every supported YAML template. Concurrent request latency during configuration updates has not been measured.
Which issue(s) this PR fixes:
Fixes #13685.
Follow-up to #13686; this does not modify or close the original PR.
Checklist
Documentation is unchanged. Functional compatibility cases pass; the compatibility checkbox remains open because the fallback performance concern still needs review.