Skip to content

fix(fluentd): sort plugin @id numerically to preserve CR definition order#1927

Open
sugaf1204 wants to merge 1 commit intofluent:masterfrom
sugaf1204:worktree-order-index
Open

fix(fluentd): sort plugin @id numerically to preserve CR definition order#1927
sugaf1204 wants to merge 1 commit intofluent:masterfrom
sugaf1204:worktree-order-index

Conversation

@sugaf1204
Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Fix plugin rendering order when a CR has 10+ filter/output plugins.

PluginStoreByNameById.Less compared @id strings 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?

Fix plugin ordering when a single CR defines 10 or more filter or output plugins.

Additional documentation, usage docs, etc.:


Copilot AI review requested due to automatic review settings April 19, 2026 00:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.Less to compare @id trailing 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.

Comment thread apis/fluentd/v1alpha1/plugins/params/model.go Outdated
if p1 != p2 {
return p1 < p2
}
return n1 < n2
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

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).

Suggested change
return n1 < n2
if n1 != n2 {
return n1 < n2
}
return id1 < id2

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings April 19, 2026 00:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@sugaf1204 sugaf1204 marked this pull request as draft April 19, 2026 08:30
@sugaf1204 sugaf1204 force-pushed the worktree-order-index branch from 458e9af to f548ad3 Compare April 19, 2026 08:31
@sugaf1204 sugaf1204 marked this pull request as ready for review April 19, 2026 08:32
Copilot AI review requested due to automatic review settings April 19, 2026 08:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

…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>
@sugaf1204 sugaf1204 force-pushed the worktree-order-index branch from 3dae5ee to 416a9bf Compare April 19, 2026 08:37
@cw-Guo
Copy link
Copy Markdown
Collaborator

cw-Guo commented Apr 20, 2026

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?
for example, we can add a argument, so that user can control the sorting behavior, and the default value would be the lexicographically.
@joshuabaird what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants