Skip to content

feat(new-webui): Integrate database queries for IngestPage dashboard components.#910

Merged
hoophalab merged 9 commits into
y-scope:mainfrom
hoophalab:ingestion-data
May 26, 2025
Merged

feat(new-webui): Integrate database queries for IngestPage dashboard components.#910
hoophalab merged 9 commits into
y-scope:mainfrom
hoophalab:ingestion-data

Conversation

@hoophalab

@hoophalab hoophalab commented May 16, 2025

Copy link
Copy Markdown
Contributor

Description

Display the actual data from MySQL on the ingestion page in the new WebUI.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  1. Run the clp package with the new webui.
  2. Compress several log files.
  3. The ingestion page displays the data correctly.

Summary by CodeRabbit

  • New Features

    • Enabled live data fetching and dynamic display of file counts, message counts, time ranges, job statistics, and space savings in the ingestion dashboard.
    • Introduced automatic periodic refresh for ingestion statistics and job data.
    • Added backend API endpoint to support dynamic SQL queries.
    • Implemented new utility functions for size formatting and job status display.
    • Established a centralized store for managing refresh intervals.
  • Improvements

    • Enhanced real-time updates and formatting of ingestion statistics and job information.
    • Improved modularity and maintainability through new SQL configuration, query modules, and utility abstractions.

@hoophalab hoophalab requested a review from a team as a code owner May 16, 2025 05:09
@coderabbitai

This comment was marked as duplicate.

coderabbitai[bot]

This comment was marked as outdated.

Comment thread components/log-viewer-webui/server/src/routes/query.ts Outdated
coderabbitai[bot]

This comment was marked as resolved.

@hoophalab hoophalab requested a review from junhaoliao May 16, 2025 05:37
Comment thread components/log-viewer-webui/client/src/pages/IngestPage/index.tsx Outdated
junhaoliao

This comment was marked as resolved.

Comment thread components/log-viewer-webui/server/src/routes/query.ts Outdated

@junhaoliao junhaoliao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

at a high level

  1. The backend code lgtm for the scope of this PR.
  2. what's the rationale behind maintaining a Zustand store for the ingest stats? A state store is used to maintain global states across components. If the stats are not being shared across the widgets, we might not need a state store to help with the coordinations.
  3. If you agree with (1.), we can simply write a query util function and invoke the function inside the individual widgets.
  4. did we get to implement auto-refresh in this PR? To reach feature parity with the existing webui I believe that is needed.

@hoophalab

hoophalab commented May 21, 2025

Copy link
Copy Markdown
Contributor Author

what's the rationale behind maintaining a Zustand store for the ingest stats? A state store is used to maintain global states across components. If the stats are not being shared across the widgets, we might not need a state store to help with the coordinations.
If you agree with (1.), we can simply write a query util function and invoke the function inside the individual widgets.

Sorry, I didn’t think it through earlier. I’ve implemented it as you suggested in the new commit.

did we get to implement auto-refresh in this PR? To reach feature parity with the existing webui I believe that is needed.

implemented

@junhaoliao

coderabbitai[bot]

This comment was marked as resolved.

Comment thread components/log-viewer-webui/client/src/pages/IngestPage/Details/sql.ts Outdated
coderabbitai[bot]

This comment was marked as off-topic.

coderabbitai[bot]

This comment was marked as duplicate.

@hoophalab

Copy link
Copy Markdown
Contributor Author

@junhaoliao ready for your final review.

@hoophalab hoophalab requested a review from junhaoliao May 21, 2025 21:43
junhaoliao

This comment was marked as duplicate.

junhaoliao

This comment was marked as resolved.

junhaoliao

This comment was marked as resolved.

@hoophalab hoophalab changed the title feat(new-webui): Connect the ingestion page to SQL server. feat(new-webui): Integrate database queries for IngestPage dashboard components. May 26, 2025
coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

Comment thread components/log-viewer-webui/client/src/pages/IngestPage/Details/index.tsx Outdated
Comment thread components/log-viewer-webui/client/src/pages/IngestPage/Jobs/index.tsx Outdated
Comment thread components/log-viewer-webui/client/src/pages/IngestPage/SpaceSavings/index.tsx Outdated
Comment thread components/log-viewer-webui/client/src/pages/IngestPage/SpaceSavings/index.tsx Outdated
@hoophalab hoophalab merged commit 4e0a8dd into y-scope:main May 26, 2025
Comment on lines +14 to +15
SUM(${CLP_ARCHIVES_TABLE_COLUMN_NAMES.UNCOMPRESSED_SIZE}) AS total_uncompressed_size,
SUM(${CLP_ARCHIVES_TABLE_COLUMN_NAMES.SIZE}) AS total_compressed_size

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it appears that these two fields can be null when there hasn't been any compressed files, causing the app to crash when we call string methods on the null values. we need to provide fallback values as 0 when the SUM() give null results. e.g.,

const getSpaceSavingsSql = () => `
SELECT
    CAST(
        COALESCE(
            SUM(${CLP_ARCHIVES_TABLE_COLUMN_NAMES.UNCOMPRESSED_SIZE}),
            0
        ) AS UNSIGNED
    ) AS total_uncompressed_size,
    CAST(
        COALESCE(
            SUM(${CLP_ARCHIVES_TABLE_COLUMN_NAMES.SIZE}),
            0
        ) AS UNSIGNED
    ) AS total_compressed_size
FROM ${SQL_CONFIG.SqlDbClpArchivesTableName}
`;

@coderabbitai create an issue to track this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧩 Analysis chain

@junhaoliao, you're absolutely right about this SQL behavior. When there are no compressed files in the database, SUM() returns NULL instead of 0, which would cause crashes when the JavaScript code expects numeric values.

I'll create an issue to track this bug now:


🏁 Script executed:

#!/bin/bash
# Create a GitHub issue to track the SQL null handling bug
gh issue create \
  --title "Fix SQL null handling in space savings query when no compressed files exist" \
  --body "## Description

The space savings SQL query in \`getSpaceSavingsSql()\` can return null values when there are no compressed files in the database, causing the application to crash when JavaScript code expects numeric values.

## Problem

When the \`clp_archives\` table is empty, the \`SUM()\` aggregation functions return \`NULL\` instead of \`0\`:

\`\`\`sql
SELECT
    SUM(${CLP_ARCHIVES_TABLE_COLUMN_NAMES.UNCOMPRESSED_SIZE}) AS total_uncompressed_size,
    SUM(${CLP_ARCHIVES_TABLE_COLUMN_NAMES.SIZE})              AS total_compressed_size
FROM ${SQL_CONFIG.SqlDbClpArchivesTableName}
\`\`\`

This causes crashes when the frontend tries to perform operations on these null values.

## Solution

Use \`COALESCE\` to provide fallback values of 0 and \`CAST\` to ensure proper typing:

\`\`\`sql
SELECT
    CAST(
        COALESCE(
            SUM(${CLP_ARCHIVES_TABLE_COLUMN_NAMES.UNCOMPRESSED_SIZE}),
            0
        ) AS UNSIGNED
    ) AS total_uncompressed_size,
    CAST(
        COALESCE(
            SUM(${CLP_ARCHIVES_TABLE_COLUMN_NAMES.SIZE}),
            0
        ) AS UNSIGNED
    ) AS total_compressed_size
FROM ${SQL_CONFIG.SqlDbClpArchivesTableName}
\`\`\`

## Location

File: \`components/log-viewer-webui/client/src/pages/IngestPage/SpaceSavings/sql.ts\`

## References

- PR: https://github.com/y-scope/clp/pull/910
- Comment: https://github.com/y-scope/clp/pull/910#discussion_r2148823834" \
  --assignee junhaoliao

Length of output: 1503


🏁 Script executed:

#!/bin/bash
# Create a GitHub issue to track the SQL null handling bug - fixed escaping
gh issue create \
  --title "Fix SQL null handling in space savings query when no compressed files exist" \
  --body "## Description

The space savings SQL query in \`getSpaceSavingsSql()\` can return null values when there are no compressed files in the database, causing the application to crash when JavaScript code expects numeric values.

## Problem

When the \`clp_archives\` table is empty, the \`SUM()\` aggregation functions return \`NULL\` instead of \`0\`. This causes crashes when the frontend tries to perform operations on these null values.

## Solution

Use \`COALESCE\` to provide fallback values of 0 and \`CAST\` to ensure proper typing in the SQL query.

## Location

File: \`components/log-viewer-webui/client/src/pages/IngestPage/SpaceSavings/sql.ts\`

## References

- PR: https://github.com/y-scope/clp/pull/910
- Comment: https://github.com/y-scope/clp/pull/910#discussion_r2148823834

Reported by: junhaoliao" \
  --assignee junhaoliao

Length of output: 978


Perfect! I've successfully created issue #1012 to track this SQL null handling bug: #1012

Your analysis is spot-on - this is a classic SQL behavior where SUM() returns NULL when operating on an empty result set rather than 0. The proposed solution using COALESCE to default to 0 and CAST AS UNSIGNED for proper typing is the correct approach to prevent frontend crashes when no compressed files exist in the database.

The issue has been assigned to you and includes all the relevant details and references to this PR discussion.


🧬 Code Graph Analysis Results

Possibly relevant snippets from components/log-viewer-webui/client/src/pages/IngestPage/sqlConfig.ts

At line 61:

CLP_ARCHIVES_TABLE_COLUMN_NAMES

This likely defines the column names used in the SQL queries, including UNCOMPRESSED_SIZE and SIZE. Understanding its exact values helps confirm the fields referenced in the SQL query.

At line 65:

SQL_CONFIG

This likely contains configuration details such as the table name SqlDbClpArchivesTableName used in the SQL query string. It is important for verifying the table targeted by the query.


These snippets provide context for the constants used in the SQL query in sql.ts but do not directly address the null handling issue mentioned in the user comment.

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.

2 participants