Skip to content

LOG-9015: fix: add fallback to numeric comparator to respect natural sorting#357

Open
jgbernalp wants to merge 1 commit intoopenshift:mainfrom
jgbernalp:fix-numeric-comparator-toaccount-for-natural-sorting
Open

LOG-9015: fix: add fallback to numeric comparator to respect natural sorting#357
jgbernalp wants to merge 1 commit intoopenshift:mainfrom
jgbernalp:fix-numeric-comparator-toaccount-for-natural-sorting

Conversation

@jgbernalp
Copy link
Contributor

No description provided.

Signed-off-by: Gabriel Bernal <gbernal@redhat.com>
@openshift-ci-robot
Copy link

openshift-ci-robot commented Mar 25, 2026

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

Details

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

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Mar 25, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 25, 2026

Walkthrough

A new shared numericComparator utility function is introduced with a comprehensive test suite. The logs-table.tsx component is refactored to use this utility instead of a local implementation, with logIndex added as a tie-breaker for equal timestamp comparisons.

Changes

Cohort / File(s) Summary
Sort Utility Creation
web/src/sort-utils.ts
New utility module defining numericComparator function for generic numeric/string value comparison with direction multiplier and optional fallback parameter.
Test Suite
web/src/__tests__/numeric-comparator.spec.ts
Comprehensive test suite validating numericComparator behavior across ascending/descending directions, tie-breaking with fallback values, timestamp comparisons, and log index ordering.
Logs Table Refactor
web/src/components/logs-table.tsx
Replaced local numericComparator implementation with import from sort-utils; updated date column and default sort paths to use logIndex as tie-breaker for equal timestamps.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 25, 2026

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 25, 2026
@jgbernalp
Copy link
Contributor Author

/cherry-pick release-6.1

@openshift-cherrypick-robot

@jgbernalp: once the present PR merges, I will cherry-pick it on top of release-6.1 in a new PR and assign it to you.

Details

In response to this:

/cherry-pick release-6.1

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 390080c and 1ca8bc8.

📒 Files selected for processing (3)
  • web/src/__tests__/numeric-comparator.spec.ts
  • web/src/components/logs-table.tsx
  • web/src/sort-utils.ts

Comment on lines +11 to +12
if (result === 0 && fallbackComparison !== undefined) {
return fallbackComparison * directionMultiplier;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

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.

Suggested change
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.

@jgbernalp
Copy link
Contributor Author

/test test-unit

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 25, 2026

@jgbernalp: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/test-unit 1ca8bc8 link true /test test-unit

Full PR test history. Your PR dashboard.

Details

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. I understand the commands that are listed here.

@anpingli
Copy link
Contributor

anpingli commented Mar 27, 2026

@jgbernalp There are still some records out of order. template used in this test https://redhat.atlassian.net/browse/OU-1280?focusedCommentId=16554580

image

The correct order:

Message --- openshift_sequence

Unhandled exception:" - 1774597962575560125
Assertion failed" - 1774597962575717900
#0      main.<anonymous closure> (file:///path/to/code/dartFile.dart:9:20)" - 1774597962575751641
#1      printError (file:///path/to/code/dartFile.dart:36:13)" - 1774597962575804786
#2      main (file:///path/to/code/dartFile.dart:9:3)" - 1774597962575855275
#3      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:265)" - 1774597962575877265
#4      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:151)" - 1774597962575906546

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants