LOG-9015: fix: add fallback to numeric comparator to respect natural sorting#357
Conversation
Signed-off-by: Gabriel Bernal <gbernal@redhat.com>
|
@jgbernalp: This pull request references LOG-9015 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the bug to target the "4.22.0" version, but no target version was set. DetailsIn response to this: Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
WalkthroughA new shared Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jgbernalp The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/cherry-pick release-6.1 |
|
@jgbernalp: once the present PR merges, I will cherry-pick it on top of DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@web/src/sort-utils.ts`:
- Around line 11-12: The stability fallback currently multiplies
fallbackComparison by directionMultiplier which reverses natural order for tied
timestamps in descending mode; change the return so that when result === 0 and
fallbackComparison !== undefined you return fallbackComparison (without applying
directionMultiplier) to preserve input/backend order, updating any tests (e.g.,
in web/src/__tests__/numeric-comparator.spec.ts) that expected reversed order to
now expect the original input order; refer to the variables result,
fallbackComparison, and directionMultiplier in sort-utils.ts when making this
change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1ab7dc00-997d-4385-8ded-f27bbe265b5d
📒 Files selected for processing (3)
web/src/__tests__/numeric-comparator.spec.tsweb/src/components/logs-table.tsxweb/src/sort-utils.ts
| if (result === 0 && fallbackComparison !== undefined) { | ||
| return fallbackComparison * directionMultiplier; |
There was a problem hiding this comment.
Don't apply directionMultiplier to a stability fallback.
Line 12 re-scales fallbackComparison, but the current callers use a.logIndex - b.logIndex to preserve input/backend order when the primary timestamp comparison ties. In descending mode that reverses those tied rows instead of keeping their natural order.
Suggested fix
export const numericComparator = <T extends SortableValue>(
a: T,
b: T,
directionMultiplier: number,
fallbackComparison?: number,
): number => {
const result = a < b ? -1 : a > b ? 1 : 0;
if (result === 0 && fallbackComparison !== undefined) {
- return fallbackComparison * directionMultiplier;
+ return fallbackComparison;
}
return result * directionMultiplier;
};Downstream, the descending fallback expectations in web/src/__tests__/numeric-comparator.spec.ts should preserve input order rather than reverse it.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (result === 0 && fallbackComparison !== undefined) { | |
| return fallbackComparison * directionMultiplier; | |
| export const numericComparator = <T extends SortableValue>( | |
| a: T, | |
| b: T, | |
| directionMultiplier: number, | |
| fallbackComparison?: number, | |
| ): number => { | |
| const result = a < b ? -1 : a > b ? 1 : 0; | |
| if (result === 0 && fallbackComparison !== undefined) { | |
| return fallbackComparison; | |
| } | |
| return result * directionMultiplier; | |
| }; |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@web/src/sort-utils.ts` around lines 11 - 12, The stability fallback currently
multiplies fallbackComparison by directionMultiplier which reverses natural
order for tied timestamps in descending mode; change the return so that when
result === 0 and fallbackComparison !== undefined you return fallbackComparison
(without applying directionMultiplier) to preserve input/backend order, updating
any tests (e.g., in web/src/__tests__/numeric-comparator.spec.ts) that expected
reversed order to now expect the original input order; refer to the variables
result, fallbackComparison, and directionMultiplier in sort-utils.ts when making
this change.
|
/test test-unit |
|
@jgbernalp: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
@jgbernalp There are still some records out of order. template used in this test https://redhat.atlassian.net/browse/OU-1280?focusedCommentId=16554580
The correct order: Message --- openshift_sequence |

No description provided.