Skip to content

fix(apisix-standalone): potential duplication of global rules#497

Merged
bzp2010 merged 1 commit into
mainfrom
bzp/fix-apisix-standalone-global-rules-dups
Jun 23, 2026
Merged

fix(apisix-standalone): potential duplication of global rules#497
bzp2010 merged 1 commit into
mainfrom
bzp/fix-apisix-standalone-global-rules-dups

Conversation

@bzp2010

@bzp2010 bzp2010 commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Description

Fixes #489

Global rules are now parsed correctly during the dump, preventing potential plugin ID duplicates and redundant synchronization attempts.

The error mechanism has been described in some detail in #489.

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

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Fixes a bug in the APISIX standalone backend's toADC transformer where global_rules plugins were incorrectly accessed by array index (plugins![0]) instead of being iterated as a record. The fix flattens each rule's plugins map via Object.entries. A new E2E test suite validates the full global rule lifecycle including idempotency.

Changes

Global rules transformer fix and E2E validation

Layer / File(s) Summary
toADC global_rules and plugin_metadata transformer fix
libs/backend-apisix-standalone/src/transformer.ts
global_rules construction changes from gr.plugins![0] (array index, always undefined) to flatMap-ing Object.entries(gr.plugins ?? {}) and applying recursiveOmitUndefined per plugin value. plugin_metadata moves recursiveOmitUndefined to apply directly on the rest object instead of a separate .map pass over all entries.
Global Rule E2E lifecycle test suite
libs/backend-apisix-standalone/e2e/resources/global-rule.e2e-spec.ts
Adds a complete Jest E2E suite covering: create two global rules and dump-verify, idempotent second sync (zero events, global_rules_conf_version unchanged), update one rule with a single UPDATE event, delete all rules with only DELETE events, and final dump confirming an empty rules list.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR fully addresses issue #489 by fixing the plugins read path transformation, adding comprehensive e2e tests, and preventing duplicate global rule creation on resync.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the global_rules read path bug and validating it through e2e tests; no out-of-scope modifications detected.
E2e Test Quality Review ✅ Passed E2E test comprehensively covers the fix: CRUD lifecycle (create 2 rules, update, delete), critical idempotency regression test verifying zero diff events and stable conf_version on resync, proper r...
Security Check ✅ Passed No security vulnerabilities found across all 7 categories: (1) No sensitive data exposure in logs—test has no logging, transformer has no new logging; (2) No database secrets—no persistence code ch...
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main bug fix: a duplication issue with global rules in the apisix-standalone backend.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bzp/fix-apisix-standalone-global-rules-dups

Comment @coderabbitai help to get the list of available commands.

@bzp2010 bzp2010 closed this Jun 23, 2026
@bzp2010 bzp2010 reopened this Jun 23, 2026
@bzp2010 bzp2010 closed this Jun 23, 2026
@bzp2010 bzp2010 reopened this Jun 23, 2026
@bzp2010 bzp2010 added the test/apisix-standalone Trigger the APISIX standalone test on the PR label Jun 23, 2026
@bzp2010 bzp2010 changed the title fix(apisix-standalone): fix global_rules read path dropping plugins fix(apisix-standalone): potential duplication of global rules Jun 23, 2026
@bzp2010 bzp2010 self-assigned this Jun 23, 2026
@bzp2010 bzp2010 merged commit 263119c into main Jun 23, 2026
107 checks passed
@bzp2010 bzp2010 deleted the bzp/fix-apisix-standalone-global-rules-dups branch June 23, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test/apisix-standalone Trigger the APISIX standalone test on the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(backend-apisix-standalone): global_rules read path drops plugins → duplicate global_rule on resync → APISIX 400

2 participants