feat(new-webui): Integrate database queries for IngestPage dashboard components.#910
Conversation
This comment was marked as duplicate.
This comment was marked as duplicate.
There was a problem hiding this comment.
at a high level
- The backend code lgtm for the scope of this PR.
- 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.
- did we get to implement auto-refresh in this PR? To reach feature parity with the existing webui I believe that is needed.
Sorry, I didn’t think it through earlier. I’ve implemented it as you suggested in the new commit.
implemented |
|
@junhaoliao ready for your final review. |
| SUM(${CLP_ARCHIVES_TABLE_COLUMN_NAMES.UNCOMPRESSED_SIZE}) AS total_uncompressed_size, | ||
| SUM(${CLP_ARCHIVES_TABLE_COLUMN_NAMES.SIZE}) AS total_compressed_size |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
🧩 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_NAMESThis 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_CONFIGThis 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.
Description
Display the actual data from MySQL on the ingestion page in the new WebUI.
Checklist
breaking change.
Validation performed
Summary by CodeRabbit
New Features
Improvements