Repository navigation
feat(webui): Show query speed in native search status. #1429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
be5e1f6
a15d14d
ab061fe
2473795
d4517cf
f21b4e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {useQuery} from "@tanstack/react-query"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {Typography} from "antd"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {formatSizeInBytes} from "../../../../IngestPage/Jobs/units"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import useSearchStore from "../../../SearchState/index"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {SEARCH_UI_STATE} from "../../../SearchState/typings"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {fetchQuerySpeed} from "./utils"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const {Text} = Typography; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const SPEED_DEFAULT = {latency: 0, speed: 0}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Displays the query latency and speed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const QuerySpeed = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const searchUiState = useSearchStore((state) => state.searchUiState); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const searchJobId = useSearchStore((state) => state.searchJobId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const cachedDataset = useSearchStore((state) => state.cachedDataset); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const {data = SPEED_DEFAULT} = useQuery({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queryKey: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "speed", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| searchJobId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cachedDataset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queryFn: async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const {bytes, duration} = await fetchQuerySpeed(cachedDataset ?? "", searchJobId ?? ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return {latency: duration, speed: bytes / duration}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| enabled: SEARCH_UI_STATE.DONE === searchUiState, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const {latency, speed} = data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Text type={"secondary"}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {`Query took ${latency.toFixed(3)} seconds (${formatSizeInBytes(speed)}/s).`} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
hoophalab marked this conversation as resolved.
Resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Text> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle edge case where duration is zero. Line 34 performs division by Apply this diff to handle the edge case: (async () => {
const {cachedDataset, searchJobId} = useSearchStore.getState();
const {bytes, duration} = await fetchQuerySpeed(cachedDataset ?? "", searchJobId ?? "");
setLatency(duration);
- setSpeed(bytes / MEGABYTES_IN_BYTES / duration);
+ setSpeed(duration > 0 ? bytes / MEGABYTES_IN_BYTES / duration : 0);
})().catch(console.error);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default QuerySpeed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import {querySql} from "../../../../../api/sql"; | ||
| import {settings} from "../../../../../settings"; | ||
|
|
||
|
|
||
| /** | ||
| * Builds a SQL query string to retrieve the total uncompressed bytes and duration | ||
| * for a specific query job within a given dataset. | ||
| * | ||
| * @param datasetName | ||
| * @param jobId | ||
| * @return | ||
| */ | ||
| const buildQuerySpeedSql = (datasetName: string, jobId: string) => { | ||
| const tableName = "" === datasetName ? | ||
| settings.SqlDbClpArchivesTableName : | ||
| `${settings.SqlDbClpTablePrefix}${datasetName}_archives`; | ||
|
|
||
| return `WITH qt AS ( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the query lgtm |
||
| SELECT job_id, archive_id | ||
| FROM query_tasks | ||
| WHERE archive_id IS NOT NULL | ||
| ), | ||
| totals AS ( | ||
| SELECT | ||
| qt.job_id, | ||
| SUM(ca.uncompressed_size) AS total_uncompressed_bytes | ||
| FROM qt | ||
| JOIN ${tableName} ca | ||
| ON qt.archive_id = ca.id | ||
| GROUP BY qt.job_id | ||
| ) | ||
| SELECT | ||
| CAST(totals.total_uncompressed_bytes AS double) AS bytes, | ||
| qj.duration AS duration | ||
| FROM query_jobs qj | ||
|
hoophalab marked this conversation as resolved.
Resolved
|
||
| JOIN totals | ||
| ON totals.job_id = qj.id | ||
| WHERE qj.id = ${jobId}`; | ||
| }; | ||
|
Comment on lines
+13
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify SQL injection protection. The function uses string interpolation to insert Run the following script to verify whether 🏁 Script executed: #!/bin/bash
# Check if querySql supports parameterized queries or if inputs are validated
# Find the implementation of querySql
ast-grep --pattern 'function querySql($$$) {
$$$
}'
# Check for any input validation of jobId and datasetName
rg -nP --type=ts -C5 '\b(searchJobId|cachedDataset)\s*=' -g '!**/node_modules/**'
# Look for SQL sanitization or parameterization patterns
rg -nP --type=ts 'prepare|sanitize|escape|param' -g '!**/node_modules/**' -g '**/api/sql/**'Length of output: 12548 🏁 Script executed: #!/bin/bash
# Find where buildQuerySpeedSql is called
rg -nP --type=ts 'buildQuerySpeedSql' -C5 -g '!**/node_modules/**'
# Find QueryJobDbManager and similar to see how SQL queries are executed
rg -nP --type=ts 'QueryJobDbManager|querySql|\.query\(|\.execute\(' -C3 -g '!**/server/**' -g '!**/node_modules/**' | head -60
# Look for the actual query execution mechanism in server-side code
rg -nP --type=ts 'Presto\.client|pool\.query|connection\.execute' -C3 -g '**/server/**' -g '!**/node_modules/**' | head -80Length of output: 9734 🏁 Script executed: #!/bin/bash
# Find where buildQuerySpeedSql is called
rg -nP --type=ts 'buildQuerySpeedSql' -C8
# Find how the function is exported/used
fd -e ts -e tsx | xargs grep -l 'buildQuerySpeedSql' 2>/dev/null
# Search for utils file and see what's exported
cat components/webui/client/src/pages/SearchPage/SearchControls/QueryStatus/QuerySpeed/utils.ts 2>/dev/null || echo "File not found"
# Find imports of this utils file
rg -P --type=ts 'from.*QuerySpeed.*utils|import.*buildQuerySpeedSql' -C3Length of output: 5894 Script executed: Output: Script executed: Output: Script executed: Output: Script executed: Output: Script executed: Output: Verify SQL injection vulnerability claim—confirmed but with important context about input sources. The SQL injection concern is technically valid: However, the practical risk is lower than initially suggested: Recommendation: While the current implementation may be secure through app state management, parameterized queries or prepared statements should be used in
The original review comment correctly identifies the string interpolation pattern but should acknowledge that the inputs appear to be app-managed rather than user-supplied. 🏁 Script executed: #!/bin/bash
# Find the server-side endpoint for /api/archive-metadata/sql
rg -nP --type=ts 'archive-metadata.*sql|/sql' -C10 -g '**/server/**' -g '!**/node_modules/**'
# Look for Presto query execution patterns
rg -nP --type=ts 'Presto\.client\.query|execute.*query|query.*sql' -C5 -g '**/server/**' -g '!**/node_modules/**' | head -100Length of output: 3218 🏁 Script executed: #!/bin/bash
# Find the server-side endpoint for /api/archive-metadata/sql
rg -nP --type=ts 'archive-metadata.*sql|/sql' -C10 -g '**/server/**' -g '!**/node_modules/**'
# Look for Presto query execution patterns
rg -nP --type=ts 'Presto\.client\.query|execute.*query|query.*sql' -C5 -g '**/server/**' -g '!**/node_modules/**' | head -100Length of output: 3218 🏁 Script executed: #!/bin/bash
# Read the full sql.ts file to see query execution
cat components/webui/server/src/routes/api/archive-metadata/sql.tsLength of output: 94 🏁 Script executed: #!/bin/bash
# Read the full sql.ts file to see query execution
cat components/webui/server/src/routes/api/archive-metadata/sql.tsLength of output: 94 🏁 Script executed: #!/bin/bash
# Find where fetchQuerySpeed is called
rg -nP --type=ts 'fetchQuerySpeed' -C5 -g '!**/node_modules/**'
# Find the source of cachedDataset in the store
rg -nP --type=ts 'cachedDataset.*:' -C3 -g '!**/node_modules/**'
# Check the initial state/store definitions
rg -nP --type=ts 'searchJobId|cachedDataset' -C2 -g '**/SearchState/**' -g '!**/node_modules/**'Length of output: 12518 🏁 Script executed: #!/bin/bash
# Find where fetchQuerySpeed is called
rg -nP --type=ts 'fetchQuerySpeed' -C5 -g '!**/node_modules/**'
# Find the source of cachedDataset in the store
rg -nP --type=ts 'cachedDataset.*:' -C3 -g '!**/node_modules/**'
# Check the initial state/store definitions
rg -nP --type=ts 'searchJobId|cachedDataset' -C2 -g '**/SearchState/**' -g '!**/node_modules/**'Length of output: 12518 🏁 Script executed: #!/bin/bash
# Find the SearchStore definition
find components/webui/client/src -name '*SearchState*' -o -name '*useSearchStore*' | head -20
# Find where cachedDataset is set (assignment/mutation)
rg -nP --type=ts 'cachedDataset\s*[:=]|set.*cachedDataset' -C3
# Find where searchJobId is assigned
rg -nP --type=ts 'searchJobId\s*[:=]|set.*searchJobId' -C3 -g '**/SearchState/**'Length of output: 6972 🏁 Script executed: #!/bin/bash
# Find the SearchStore definition
find components/webui/client/src -name '*SearchState*' -o -name '*useSearchStore*' | head -20
# Find where cachedDataset is set (assignment/mutation)
rg -nP --type=ts 'cachedDataset\s*[:=]|set.*cachedDataset' -C3
# Find where searchJobId is assigned
rg -nP --type=ts 'searchJobId\s*[:=]|set.*searchJobId' -C3 -g '**/SearchState/**'Length of output: 6972 🏁 Script executed: #!/bin/bash
# Read the store definition
cat components/webui/client/src/pages/SearchPage/SearchState/store.tsLength of output: 97 🏁 Script executed: #!/bin/bash
# Read the store definition
cat components/webui/client/src/pages/SearchPage/SearchState/store.tsLength of output: 97 Script executed: Output: Perfect! Now I have confirmed the full implementation. Let me now search for where Script executed: Output: Perfect! Now I can see that Script executed: Output: Script executed: Output: Good. Now let me check the presto-client documentation to see if it supports parameterized queries. Based on my comprehensive verification, I can now provide a final assessment: Review of SQL injection vulnerability in The function does interpolate Key findings:
Actual vulnerability: The string interpolation of Recommendation: Use proper SQL escaping or validation for 🏁 Script executed: #!/bin/bash
# Read the archive-metadata/index.ts to see the full /sql endpoint implementation
cat components/webui/server/src/routes/api/archive-metadata/index.ts | head -100Length of output: 918 🏁 Script executed: #!/bin/bash
# Read the archive-metadata/index.ts to see the full /sql endpoint implementation
cat components/webui/server/src/routes/api/archive-metadata/index.ts | head -100Length of output: 918 🏁 Script executed: #!/bin/bash
# Find where updateCachedDataset and updateSearchJobId are called
rg -nP --type=ts 'updateCachedDataset|updateSearchJobId' -C3 -g '!**/node_modules/**' | head -80
# Check if dataset selection is user-controlled or server-provided
rg -nP --type=ts 'selectDataset|updateSelectDataset|selectDataset\s*=' -C3 -g '!**/node_modules/**' | head -60Length of output: 15505 🏁 Script executed: #!/bin/bash
# Find where updateCachedDataset and updateSearchJobId are called
rg -nP --type=ts 'updateCachedDataset|updateSearchJobId' -C3 -g '!**/node_modules/**' | head -80
# Check if dataset selection is user-controlled or server-provided
rg -nP --type=ts 'selectDataset|updateSelectDataset|selectDataset\s*=' -C3 -g '!**/node_modules/**' | head -60Length of output: 15800 🏁 Script executed: #!/bin/bash
# Check if Presto.client.execute supports parameters
rg -nP --type=ts 'class Presto|Presto\.client\.execute' -A20 -B5 -g '**/services/presto/**'Length of output: 148 🏁 Script executed: #!/bin/bash
# Check if Presto.client.execute supports parameters
rg -nP --type=ts 'class Presto|Presto\.client\.execute' -A20 -B5 -g '**/services/presto/**'Length of output: 148 🏁 Script executed: #!/bin/bash
# Read the Presto service implementation
cat components/webui/server/src/services/presto/index.tsLength of output: 84 🏁 Script executed: #!/bin/bash
# Read the Presto service implementation
cat components/webui/server/src/services/presto/index.tsLength of output: 84 🌐 Web query: 💡 Result: Yes. The npm presto-client supports prepared/parameterized queries:
Sources: [1] socket.dev (presto-client API), [2] npm presto-client changelog, [3] Presto docs on PREPARE/EXECUTE. SQL injection vulnerability confirmed—implement parameterized query fixes at server level. The original review comment is correct: SQL injection is possible. The verification reveals a critical vulnerability in the implementation chain:
The vulnerability: Fix required: Use parameterized queries at the server level. MySQL connection pools support the second parameter for values: const [result] = await mysqlConnectionPool.query(queryString, [jobId, datasetName]);Alternatively, implement SQL escaping or validation for dataset names in |
||
|
|
||
| interface QuerySpeedResp { | ||
| bytes: number; | ||
| duration: number; | ||
| } | ||
|
|
||
| /** | ||
| * Fetches the query speed data (bytes and duration) for a specific job ID | ||
| * within a given dataset by executing a SQL query. | ||
| * | ||
| * @param datasetName | ||
| * @param jobId | ||
| * @return | ||
| */ | ||
| const fetchQuerySpeed = async (datasetName: string, jobId: string): Promise<QuerySpeedResp> => { | ||
| const resp = await querySql<QuerySpeedResp[]>(buildQuerySpeedSql(datasetName, jobId)); | ||
| const [data] = resp.data; | ||
| if ("undefined" === typeof data) { | ||
| throw new Error("Invalid query speed."); | ||
| } | ||
|
|
||
| return data; | ||
| }; | ||
|
hoophalab marked this conversation as resolved.
Resolved
|
||
|
|
||
| export {fetchQuerySpeed}; | ||
Uh oh!
There was an error while loading. Please reload this page.