Skip to content

Conversation

@shahrokni
Copy link
Contributor

Description 🖊️

Working on perses/perses#3786 I found a bug which may also lead to other bugs related to transform. Let's see!

Logs table should include the result of all queries. It seems the buggy version only includes the query result at index 0.

image

Checklist

  • Pull request has a descriptive title and context useful to a reviewer.
  • Pull request title follows the [<catalog_entry>] <commit message> naming convention using one of the
    following catalog_entry values: FEATURE, ENHANCEMENT, BUGFIX, BREAKINGCHANGE, DOC,IGNORE.
  • All commits have DCO signoffs.

UI Changes

  • Changes that impact the UI include screenshots and/or screencasts of the relevant changes.
  • Code follows the UI guidelines.

@shahrokni shahrokni requested a review from jgbernalp January 21, 2026 10:55
@shahrokni shahrokni requested a review from a team as a code owner January 21, 2026 10:55
@shahrokni shahrokni changed the title [BUGFIX] Logstable: all quries results must be included [BUGFIX] Logstable: all quries results must be included in the logs table Jan 21, 2026
@jgbernalp
Copy link
Contributor

I think this makes sense. We are now merging unordered logs, but I think sorting is done when the table renders. Can we check that?

WDYT about this @rickardsjp @rafi-ruetcse17 @abelyakin?

@shahrokni
Copy link
Contributor Author

shahrokni commented Jan 21, 2026

I think this makes sense. We are now merging unordered logs, but I think sorting is done when the table renders. Can we check that?

WDYT about this @rickardsjp @rafi-ruetcse17 @abelyakin?

I see no specific mechanism for sorting or ordering mechanism. Technically, the input is rendered as it is.
The results of individual queries pile up.

const logs = [...q1_results, ...q2_results];
      <Virtuoso
        style={{ height: '100%', flexGrow: 1 }}
        initialItemCount={spec.showAll ? logs.length : undefined}
        totalCount={logs.length}
        itemContent={renderLogRow}
      />

/* --- */

  const renderLogRow = (index: number) => {
    const log = logs[index];
    if (!log) return null;

    return (
      <LogRow
        isExpandable={spec.enableDetails}
        log={log}
        index={index}
        isExpanded={expandedRows.has(index)}
        onToggle={onToggleExpand}
        allowWrap={spec.allowWrap}
        showTime={spec.showTime}
        isSelected={selectedRows.has(index)}
        onSelect={handleRowSelect}
      />
    );
  };

@shahrokni
Copy link
Contributor Author

@jgbernalp
Now the merged results are ordered according to the timestamp

image

@shahrokni shahrokni force-pushed the fix/include_all_queries branch from 0118a8c to b535a0d Compare January 21, 2026 12:40
Copy link
Contributor

@jgbernalp jgbernalp left a comment

Choose a reason for hiding this comment

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

LGTM, I'll let others chime in before merging.

Copy link
Contributor

@rickardsjp rickardsjp left a comment

Choose a reason for hiding this comment

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

Great find @shahrokni and thanks for tagging me @jgbernalp. I like it. I think we should eventually make the sorting order configurable (e.g. "flip results order" button) but that's out of scope for a bugfix PR.

Comment on lines 24 to 28
const logs = queryResults
.reduce<LogEntry[]>((acc, log) => {
acc = acc.concat(log?.data.logs?.entries ?? []);
return acc;
}, [])
Copy link
Contributor

@rickardsjp rickardsjp Jan 22, 2026

Choose a reason for hiding this comment

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

If a user has more than two queries, we add the log entries multiple times, which may be bad for performance (number of copy operations grows quadratically). There is flatMap(), which I understand would make this step at least a linear operation. I've tested it locally and it also works.

Suggested change
const logs = queryResults
.reduce<LogEntry[]>((acc, log) => {
acc = acc.concat(log?.data.logs?.entries ?? []);
return acc;
}, [])
const logs = queryResults
.flatMap(result => result?.data.logs?.entries ?? [])

I guess that's mostly a consideration for log views with multiple queries with large results which are unlikely, but worth noting.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is good (reversing the timestamps) but only tests sorting and does not test whether results from multiple queries are included.

@abelyakin
Copy link
Contributor

Lgtm.
Good catch! Logs indeed sorted per query.

@shahrokni shahrokni force-pushed the fix/include_all_queries branch 3 times, most recently from 199c62c to 79f4d45 Compare January 22, 2026 13:43
Signed-off-by: Mahmoud Shahrokni <seyedmahmoud.shahrokni@amadeus.com>

Signed-off-by: Mahmoud Shahrokni <seyedmahmoud.shahrokni@amadeus.com>

Signed-off-by: Mahmoud Shahrokni <seyedmahmoud.shahrokni@amadeus.com>

Signed-off-by: Mahmoud Shahrokni <seyedmahmoud.shahrokni@amadeus.com>

Signed-off-by: Mahmoud Shahrokni <seyedmahmoud.shahrokni@amadeus.com>

Signed-off-by: Mahmoud Shahrokni <seyedmahmoud.shahrokni@amadeus.com>

Signed-off-by: Mahmoud Shahrokni <seyedmahmoud.shahrokni@amadeus.com>

Signed-off-by: Mahmoud Shahrokni <seyedmahmoud.shahrokni@amadeus.com>

Signed-off-by: Mahmoud Shahrokni <seyedmahmoud.shahrokni@amadeus.com>
@shahrokni shahrokni force-pushed the fix/include_all_queries branch from 79f4d45 to b8eff8e Compare January 22, 2026 13:45
@shahrokni shahrokni added this pull request to the merge queue Jan 22, 2026
Merged via the queue into main with commit 6896694 Jan 22, 2026
13 checks passed
@shahrokni shahrokni deleted the fix/include_all_queries branch January 22, 2026 13:59
Copy link
Contributor

@rickardsjp rickardsjp left a comment

Choose a reason for hiding this comment

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

picking one last nit:

}
}}
data-log-index={index}
data-testid={`log-row-container-${index}`}
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think we needed a new attribute here. From the docs:

Using data-testid attributes do not resemble how your software is used and should be avoided if possible.

Couldn't we have done something like

const items = items.querySelectorAll('[data-log-index]');

in the test instead?

But I think we can refactor this once we add a button for inverting the result order.

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.

4 participants