fix(fluentd): sort plugin @id numerically to preserve CR definition order#1927
fix(fluentd): sort plugin @id numerically to preserve CR definition order#1927sugaf1204 wants to merge 1 commit intofluent:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes Fluentd plugin rendering order in generated configs when a single CR defines 10+ filter/output plugins by sorting plugin @id suffix indexes numerically (avoiding lexicographic mis-order like -10 before -2). It also adds regression fixtures and unit tests to lock in correct ordering for filters and outputs, plus a guard test around input ordering.
Changes:
- Update
PluginStoreByNameById.Lessto compare@idtrailing numeric segments numerically. - Add new Fluentd ClusterFilter/ClusterInput/ClusterOutput test fixtures that include 11 plugins (0..10).
- Add expected rendered config fixtures + unit tests covering the 10+ plugin ordering regression.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| apis/fluentd/v1alpha1/plugins/params/model.go | Adds numeric-aware @id comparison for plugin child sorting. |
| apis/fluentd/v1alpha1/tests/tools.go | Introduces CR fixtures with 11 filters/inputs/outputs to reproduce the ordering issue. |
| apis/fluentd/v1alpha1/tests/helper_test.go | Adds regression tests validating numeric ordering for filters/outputs and a guard for input order. |
| apis/fluentd/v1alpha1/tests/expected/fluentd-cluster-cfg-output-order-by-index.cfg | New expected config validating output ordering ...-0 through ...-10. |
| apis/fluentd/v1alpha1/tests/expected/fluentd-cluster-cfg-input-order-by-index.cfg | New expected config validating input rendering order in a single CR. |
| apis/fluentd/v1alpha1/tests/expected/fluentd-cluster-cfg-filter-order-by-index.cfg | New expected config validating filter ordering ...-0 through ...-10. |
| if p1 != p2 { | ||
| return p1 < p2 | ||
| } | ||
| return n1 < n2 |
There was a problem hiding this comment.
When ok1 && ok2 and p1 == p2, lessId returns n1 < n2 without a tie-breaker for n1 == n2. If two ids differ only in formatting (e.g., leading zeros like "...-2" vs "...-02"), Less will return false in both directions, letting sort.Sort reorder them non-deterministically. Add a deterministic tie-break (for example, fall back to full id1 < id2 when n1 == n2).
| return n1 < n2 | |
| if n1 != n2 { | |
| return n1 < n2 | |
| } | |
| return id1 < id2 |
458e9af to
f548ad3
Compare
…rder Lexicographic comparison placed index 10 before index 2 (-10 < -2 as strings). Use a numeric-aware comparator when both @ids share a "<prefix>-<int>" shape; fall back to lexicographic otherwise. Adds regression tests for inputs, filters, and outputs with 11 plugins per CR. Signed-off-by: sugaf1204 <sugaf1204@icloud.com>
3dae5ee to
416a9bf
Compare
|
Hi @sugaf1204 , thanks for the contributions!. This looks good but it is a breaking change. To make sure smoothly upgrading experience, can you add a gate for this feature? |
What this PR does / why we need it:
Fix plugin rendering order when a CR has 10+ filter/output plugins.
PluginStoreByNameById.Lesscompared@idstrings lexicographically, so index 10 sorted before index 2 ("…-10" < "…-2"). This PR adds numeric comparison for the trailing index segment.Also adds regression tests for 11 filters and 11 outputs to cover this case.
Which issue(s) this PR fixes:
Fixes #
Does this PR introduced a user-facing change?
Additional documentation, usage docs, etc.: