Skip to content

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

Open
jgbernalp wants to merge 1 commit into
openshift: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 into
openshift:mainfrom
jgbernalp:fix-numeric-comparator-toaccount-for-natural-sorting

Conversation

@jgbernalp
Copy link
Copy Markdown
Contributor

@jgbernalp jgbernalp commented Mar 25, 2026

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved logs table sorting with enhanced timestamp precision and sequence-based tie-breaking for logs with identical timestamps.
  • Tests

    • Added end-to-end test coverage for logs sorting behavior.

@openshift-ci-robot
Copy link
Copy Markdown

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
Copy Markdown

coderabbitai Bot commented Mar 25, 2026

Warning

Rate limit exceeded

@jgbernalp has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 41 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 26021cfe-cdcc-4ddb-92b2-aafa3173cf54

📥 Commits

Reviewing files that changed from the base of the PR and between eb281c1 and 7d9d7fb.

📒 Files selected for processing (7)
  • web/cypress/e2e/integration/logs-dev-page.cy.ts
  • web/cypress/e2e/integration/logs-sorting.cy.ts
  • web/package.json
  • web/src/__tests__/numeric-comparator.spec.ts
  • web/src/components/logs-table.tsx
  • web/src/logs.types.ts
  • web/src/sort-utils.ts

Walkthrough

The PR adds shared numeric sorting utilities (numericComparator, bigIntDifference) to handle direction-aware comparisons and safe bigint arithmetic, extends LogTableData with observedTimestamp and openshiftSequence bigint fields, refactors logs-table to compute and use these fields for improved tie-breaking during sorting, and validates the implementation with unit and end-to-end tests.

Changes

Log Sorting Implementation

Layer / File(s) Summary
Numeric sorting utilities
web/src/sort-utils.ts
numericComparator orders values by </> with direction multiplier and optional tie-breaking fallback; bigIntDifference safely computes bigint differences clamped to JavaScript safe integer bounds.
Log table data shape extension
web/src/logs.types.ts
LogTableData interface gains optional observedTimestamp?: bigint and openshiftSequence?: bigint fields.
Observed timestamp extraction
web/src/components/logs-table.tsx (data flow)
streamToTableData extracts stream.stream.observedTimestamp as BigInt and enriches each LogTableData row with computed timestamp and sequence fields for sorting.
Logs table sorting refactoring
web/src/components/logs-table.tsx (sort logic)
Removes local numericComparator and TableCellValue type; Date column and default sort now use imported numericComparator with bigIntDifference tie-breaking on openshiftSequence or observedTimestamp.
Test coverage and CI
web/src/__tests__/numeric-comparator.spec.ts, web/cypress/e2e/integration/logs-sorting.cy.ts, web/package.json
Jest tests validate comparison semantics, direction multipliers, safe integer clamping, and boundary cases; Cypress e2e test confirms descending observedTimestamp sort; CI script invokes cypress directly.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 12
✅ Passed checks (12 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding a fallback to the numeric comparator to respect natural sorting.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed Check is not applicable: This PR only contains Jest and Cypress tests (TypeScript), not Ginkgo tests (Go framework). The custom check targets Ginkgo test names specifically.
Test Structure And Quality ✅ Passed Custom check for Ginkgo test quality is not applicable; PR contains only Jest and Cypress tests, no Ginkgo tests.
Microshift Test Compatibility ✅ Passed No Ginkgo e2e tests are added in this PR. The new tests are Jest unit tests and Cypress UI e2e tests for a web plugin, not Kubernetes/OpenShift cluster e2e tests.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No Ginkgo e2e tests are added in this PR. Test additions are Cypress UI tests, Jest unit tests, and Go unit tests—not OpenShift e2e tests. Check is not applicable.
Topology-Aware Scheduling Compatibility ✅ Passed PR contains only frontend UI code (React, utilities, tests) with no Kubernetes manifests, operators, or scheduling constraints. Check is not applicable.
Ote Binary Stdout Contract ✅ Passed PR only modifies web/TypeScript files, not Go binaries or test infrastructure. No stdout violations detected or applicable to this web-focused change.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed Custom check is not applicable: PR adds no Ginkgo e2e tests. It contains only Jest unit tests and Cypress integration tests for a web UI plugin.

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

✨ 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 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
Copy Markdown
Contributor Author

/cherry-pick release-6.1

@openshift-cherrypick-robot
Copy link
Copy Markdown

@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
Copy Markdown

@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 thread web/src/sort-utils.ts
@jgbernalp
Copy link
Copy Markdown
Contributor Author

/test test-unit

@anpingli
Copy link
Copy Markdown
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

@jgbernalp jgbernalp force-pushed the fix-numeric-comparator-toaccount-for-natural-sorting branch from 1ca8bc8 to ed4ea5e Compare May 21, 2026 11:43
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented May 21, 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 "5.0.0" version, but no target version was set.

Details

In response to this:

Summary by CodeRabbit

Release Notes

  • Improvements
  • Enhanced logs table sorting: logs with identical timestamps are now ordered by observation time, ensuring deterministic and consistent ordering in both ascending and descending sort modes. This provides more intuitive and predictable log display when multiple entries share the same timestamp.

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.

Copy link
Copy Markdown

@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: 2

♻️ Duplicate comments (1)
web/src/sort-utils.ts (1)

11-12: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

directionMultiplier must not be applied to the stability fallback.

This is the same defect flagged previously and matches anpingli's review report. With the current code, a descending primary sort (directionMultiplier = -1) inverts the tie-break: observedTimestampDifference(a, b) = a - b becomes b - a, so within a group of equal timestamp rows the table renders by descending observedTimestamp instead of ascending. anpingli's expected ordering for the tied OU‑1280 stack‑trace rows is ascending by openshift_sequence/observedTimestamp (...560125 first → ...906546 last), which only works if the fallback is returned as‑is.

🐛 Proposed fix
   const result = a < b ? -1 : a > b ? 1 : 0;
   if (result === 0 && fallbackComparison !== undefined) {
-    return fallbackComparison * directionMultiplier;
+    return fallbackComparison;
   }
   return result * directionMultiplier;

Also update the descending tie‑break expectations in web/src/__tests__/numeric-comparator.spec.ts (the should apply direction multiplier to fallback comparison and should use logIndex as tiebreaker ... in descending sort cases) to reflect preserved tie‑break direction.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/sort-utils.ts` around lines 11 - 12, The stability fallback
comparison is being multiplied by directionMultiplier, which incorrectly inverts
tie-break ordering for descending sorts; in the comparator function in
web/src/sort-utils.ts (the block computing result, fallbackComparison and using
directionMultiplier) return the fallbackComparison without applying
directionMultiplier when result === 0 and fallbackComparison !== undefined so
tied items preserve their natural ordering, and update the unit tests named
"should apply direction multiplier to fallback comparison" and "should use
logIndex as tiebreaker ... in descending sort" in
web/src/__tests__/numeric-comparator.spec.ts to expect the preserved
(non-inverted) tie-break order.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@web/src/__tests__/numeric-comparator.spec.ts`:
- Around line 26-29: The tests currently assert that the fallback comparison is
multiplied by directionMultiplier (buggy behavior); update the expectations so
the fallback preserves natural ordering even when directionMultiplier is
negative: in the spec cases referencing numericComparator (the "should apply
direction multiplier to fallback comparison" test) and the descending logIndex
tie-break tests, reverse the expected signs for the assertions that compare
equal primary keys (i.e., where numericComparator(5,5,-1,3) and
numericComparator(5,5,-1,-2) are asserted) so they expect the fallback result
without an extra direction flip; locate these assertions by the test titles and
any references to numericComparator or the logIndex tie-break and change the
expected values accordingly.

In `@web/src/components/logs-table.tsx`:
- Around line 66-67: The observedTimestamp fallback currently uses
BigInt(timestamp) where timestamp was computed with parseFloat(String(value[0]))
causing precision loss for nanosecond epochs; instead feed the raw string into
BigInt so both paths use the exact integer string: construct observedTimestamp
from BigInt(stream.stream.observedTimestamp ?? String(value[0])) (keep the
existing parseFloat(String(value[0])) only if the float `timestamp` is still
needed elsewhere, but do not use that parsed `timestamp` when building
`observedTimestamp`).

---

Duplicate comments:
In `@web/src/sort-utils.ts`:
- Around line 11-12: The stability fallback comparison is being multiplied by
directionMultiplier, which incorrectly inverts tie-break ordering for descending
sorts; in the comparator function in web/src/sort-utils.ts (the block computing
result, fallbackComparison and using directionMultiplier) return the
fallbackComparison without applying directionMultiplier when result === 0 and
fallbackComparison !== undefined so tied items preserve their natural ordering,
and update the unit tests named "should apply direction multiplier to fallback
comparison" and "should use logIndex as tiebreaker ... in descending sort" in
web/src/__tests__/numeric-comparator.spec.ts to expect the preserved
(non-inverted) tie-break order.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: c932bf0a-c965-4ca9-9510-df2f1fb554e9

📥 Commits

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

📒 Files selected for processing (6)
  • web/cypress/e2e/integration/logs-sorting.cy.ts
  • web/src/__tests__/numeric-comparator.spec.ts
  • web/src/__tests__/observed-timestamp-difference.spec.ts
  • web/src/components/logs-table.tsx
  • web/src/logs.types.ts
  • web/src/sort-utils.ts
✅ Files skipped from review due to trivial changes (1)
  • web/cypress/e2e/integration/logs-sorting.cy.ts

Comment thread web/src/__tests__/numeric-comparator.spec.ts
Comment thread web/src/components/logs-table.tsx Outdated
@jgbernalp jgbernalp force-pushed the fix-numeric-comparator-toaccount-for-natural-sorting branch 2 times, most recently from 13706d2 to f31f52c Compare May 21, 2026 11:59
@jgbernalp
Copy link
Copy Markdown
Contributor Author

/cherry-pick release-coo-ocp-4.22

@openshift-cherrypick-robot
Copy link
Copy Markdown

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

Details

In response to this:

/cherry-pick release-coo-ocp-4.22

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.

@jgbernalp
Copy link
Copy Markdown
Contributor Author

/cherry-pick release-coo-ocp-4.15

@openshift-cherrypick-robot
Copy link
Copy Markdown

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

Details

In response to this:

/cherry-pick release-coo-ocp-4.15

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.

@jgbernalp
Copy link
Copy Markdown
Contributor Author

/cherry-pick release-coo-ocp-4.12

@openshift-cherrypick-robot
Copy link
Copy Markdown

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

Details

In response to this:

/cherry-pick release-coo-ocp-4.12

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.

@jgbernalp
Copy link
Copy Markdown
Contributor Author

/test test-unit

@jgbernalp
Copy link
Copy Markdown
Contributor Author

/test test-e2e

@jgbernalp
Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@jgbernalp
Copy link
Copy Markdown
Contributor Author

/retest

@PeterYurkovich
Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label May 21, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 21, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jgbernalp, PeterYurkovich

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:
  • OWNERS [PeterYurkovich,jgbernalp]

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

@jgbernalp
Copy link
Copy Markdown
Contributor Author

/retest

@etmurasaki
Copy link
Copy Markdown
Contributor

@jgbernalp I made some comments in jira ticket.

@etmurasaki
Copy link
Copy Markdown
Contributor

/hold

@openshift-ci openshift-ci Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 21, 2026
@etmurasaki
Copy link
Copy Markdown
Contributor

holding in case qe label is added by mistake.

@jgbernalp jgbernalp force-pushed the fix-numeric-comparator-toaccount-for-natural-sorting branch from f31f52c to eb281c1 Compare May 22, 2026 06:33
@openshift-ci openshift-ci Bot removed the lgtm Indicates that a PR is ready to be merged. label May 22, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 22, 2026

New changes are detected. LGTM label has been removed.

Copy link
Copy Markdown

@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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@web/src/components/logs-table.tsx`:
- Around line 139-141: The comparator uses a truthy check for openshiftSequence
which treats 0n as falsy; update the conditional in the sort comparator (where
bigIntDifference is called) to explicitly check for undefined (e.g.,
a.openshiftSequence !== undefined && b.openshiftSequence !== undefined) so that
0n is honored as a valid tie-break value and only falls back to
observedTimestamp when openshiftSequence is actually undefined.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 25450afb-b4bb-44ab-b326-b39b23a0917c

📥 Commits

Reviewing files that changed from the base of the PR and between ed4ea5e and eb281c1.

📒 Files selected for processing (6)
  • web/cypress/e2e/integration/logs-sorting.cy.ts
  • web/package.json
  • web/src/__tests__/numeric-comparator.spec.ts
  • web/src/components/logs-table.tsx
  • web/src/logs.types.ts
  • web/src/sort-utils.ts

Comment thread web/src/components/logs-table.tsx Outdated
@jgbernalp jgbernalp force-pushed the fix-numeric-comparator-toaccount-for-natural-sorting branch from eb281c1 to 06f6c4d Compare May 22, 2026 07:03
Signed-off-by: Gabriel Bernal <gbernal@redhat.com>
@jgbernalp jgbernalp force-pushed the fix-numeric-comparator-toaccount-for-natural-sorting branch from 06f6c4d to 7d9d7fb Compare May 22, 2026 07:07
@jgbernalp
Copy link
Copy Markdown
Contributor Author

/test test-unit

1 similar comment
@jgbernalp
Copy link
Copy Markdown
Contributor Author

/test test-unit

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 22, 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 7d9d7fb 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.

@jgbernalp
Copy link
Copy Markdown
Contributor Author

Needs openshift/release#79643

@jgbernalp
Copy link
Copy Markdown
Contributor Author

/unhold

@openshift-ci openshift-ci Bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 24, 2026
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.

6 participants