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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
be5e1f6
feat(webui): Show query speed in native search status.
hoophalab a15d14d
merge
hoophalab ab061fe
address comments
hoophalab 2473795
address comments
hoophalab d4517cf
update sql
hoophalab f21b4e0
Merge branch 'main' into speed
hoophalab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
components/webui/client/src/pages/SearchPage/SearchControls/QueryStatus/QuerySpeed/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| 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 () => { | ||
| if (null === searchJobId) { | ||
| return SPEED_DEFAULT; | ||
| } | ||
| const {bytes, duration} = await fetchQuerySpeed(cachedDataset ?? "", searchJobId); | ||
| return {latency: duration, speed: bytes / duration}; | ||
| }, | ||
| enabled: SEARCH_UI_STATE.DONE === searchUiState, | ||
| refetchInterval: false, | ||
| }); | ||
| const {latency, speed} = data; | ||
| return ( | ||
| <Text type={"secondary"}> | ||
| {` in ${latency.toFixed(3)} seconds (${formatSizeInBytes(speed)}/s)`} | ||
| </Text> | ||
| ); | ||
| }; | ||
|
|
||
| export default QuerySpeed; |
64 changes: 64 additions & 0 deletions
64
components/webui/client/src/pages/SearchPage/SearchControls/QueryStatus/QuerySpeed/utils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ( | ||
| SELECT job_id, archive_id | ||
| FROM query_tasks | ||
| WHERE | ||
| archive_id IS NOT NULL | ||
| AND job_id = ${jobId} | ||
| ), | ||
| 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 | ||
| ) | ||
| 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`; | ||
| }; | ||
|
|
||
| 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}; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the query lgtm