mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Search Playground] Add Search execution time badge (#216711)
## Summary This PR adds an execution_time badge in the Preview of Search Playground.  ### Feature Flag ** This work is behind the `searchPlayground:searchModeEnabled` feature flag ** Enable feature with Dev Tools ``` POST kbn:/internal/kibana/settings/searchPlayground:searchModeEnabled {"value": true} ``` OR Enable feature in `kibana.dev.yml` ```yaml uiSettings.overrides: 'searchPlayground:searchModeEnabled': true ``` ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ...
This commit is contained in:
parent
972da88f8f
commit
230354b6c9
6 changed files with 79 additions and 23 deletions
|
@ -22,6 +22,7 @@ import {
|
|||
EuiText,
|
||||
EuiSpacer,
|
||||
Pagination,
|
||||
EuiBadge,
|
||||
} from '@elastic/eui';
|
||||
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
@ -34,6 +35,7 @@ import { Result } from '..';
|
|||
import { type ResultProps } from './result/result';
|
||||
|
||||
interface DocumentListProps {
|
||||
executionTime?: number;
|
||||
dataTelemetryIdPrefix: string;
|
||||
docs: SearchHit[];
|
||||
docsPerPage: number;
|
||||
|
@ -47,6 +49,7 @@ interface DocumentListProps {
|
|||
}
|
||||
|
||||
export const DocumentList: React.FC<DocumentListProps> = ({
|
||||
executionTime,
|
||||
dataTelemetryIdPrefix,
|
||||
docs,
|
||||
docsPerPage,
|
||||
|
@ -76,28 +79,39 @@ export const DocumentList: React.FC<DocumentListProps> = ({
|
|||
onPageClick={onPaginate}
|
||||
/>
|
||||
<EuiSpacer size="m" />
|
||||
<EuiText size="xs">
|
||||
<p>
|
||||
<FormattedMessage
|
||||
id="searchIndexDocuments.documentList.description"
|
||||
defaultMessage="Showing {results} of {total}.
|
||||
Search results maxed at {maximum} documents."
|
||||
values={{
|
||||
maximum: <FormattedNumber value={10000} />,
|
||||
results: (
|
||||
<strong>
|
||||
<FormattedNumber value={docs.length} />
|
||||
</strong>
|
||||
),
|
||||
total: (
|
||||
<strong>
|
||||
<FormattedNumber value={meta.totalItemCount} />
|
||||
</strong>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</p>
|
||||
</EuiText>
|
||||
<EuiFlexGroup alignItems="center" justifyContent="spaceBetween" gutterSize="s">
|
||||
<EuiFlexItem>
|
||||
<EuiText size="xs">
|
||||
<p>
|
||||
<FormattedMessage
|
||||
id="searchIndexDocuments.documentList.description"
|
||||
defaultMessage="Showing {results} of {total}.
|
||||
Search results maxed at {maximum} documents."
|
||||
values={{
|
||||
maximum: <FormattedNumber value={10000} />,
|
||||
results: (
|
||||
<strong>
|
||||
<FormattedNumber value={docs.length} />
|
||||
</strong>
|
||||
),
|
||||
total: (
|
||||
<strong>
|
||||
<FormattedNumber value={meta.totalItemCount} />
|
||||
</strong>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</p>
|
||||
</EuiText>
|
||||
</EuiFlexItem>
|
||||
{executionTime !== undefined && (
|
||||
<EuiFlexItem grow={false}>
|
||||
<EuiBadge data-test-subj="executionTimeBadge" color="default">
|
||||
{executionTime} ms
|
||||
</EuiBadge>
|
||||
</EuiFlexItem>
|
||||
)}
|
||||
</EuiFlexGroup>
|
||||
{isLoading && <EuiProgress size="xs" color="primary" />}
|
||||
<EuiSpacer size="m" />
|
||||
{docs.map((doc) => {
|
||||
|
|
|
@ -92,4 +92,37 @@ describe('DocumentList', () => {
|
|||
);
|
||||
expect(screen.getByText('Results are limited to 10,000 documents')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe('executionTime badge', () => {
|
||||
test('does not display the badge when executionTime is missing', () => {
|
||||
const values = {
|
||||
...DEFAULT_VALUES,
|
||||
};
|
||||
|
||||
render(
|
||||
<I18nProvider>
|
||||
<DocumentList {...values} />
|
||||
</I18nProvider>
|
||||
);
|
||||
|
||||
expect(screen.queryByTestId('executionTimeBadge')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('displays the badge when executionTime is present', () => {
|
||||
const values = {
|
||||
...DEFAULT_VALUES,
|
||||
executionTime: 234, // Set executionTime to a valid value
|
||||
};
|
||||
|
||||
render(
|
||||
<I18nProvider>
|
||||
<DocumentList {...values} />
|
||||
</I18nProvider>
|
||||
);
|
||||
|
||||
const badge = screen.getByTestId('executionTimeBadge');
|
||||
expect(badge).toBeInTheDocument();
|
||||
expect(badge).toHaveTextContent('234 ms');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -19,6 +19,7 @@ import { useKibana } from '../../hooks/use_kibana';
|
|||
import { Pagination } from '../../types';
|
||||
|
||||
export interface ResultListArgs {
|
||||
executionTime: number;
|
||||
searchResults: SearchHit[];
|
||||
mappings?: IndicesGetMappingResponse;
|
||||
pagination: Pagination;
|
||||
|
@ -26,6 +27,7 @@ export interface ResultListArgs {
|
|||
}
|
||||
|
||||
export const ResultList: React.FC<ResultListArgs> = ({
|
||||
executionTime,
|
||||
searchResults,
|
||||
mappings,
|
||||
pagination,
|
||||
|
@ -46,6 +48,7 @@ export const ResultList: React.FC<ResultListArgs> = ({
|
|||
return (
|
||||
<>
|
||||
<DocumentList
|
||||
executionTime={executionTime}
|
||||
dataTelemetryIdPrefix="result-list"
|
||||
docs={searchResults}
|
||||
docsPerPage={10}
|
||||
|
|
|
@ -41,7 +41,7 @@ export const SearchMode: React.FC = () => {
|
|||
pagination: Pagination;
|
||||
}>({ query: searchBarValue, pagination: DEFAULT_PAGINATION });
|
||||
|
||||
const { results, pagination } = useSearchPreview(searchQuery);
|
||||
const { executionTime, results, pagination } = useSearchPreview(searchQuery);
|
||||
const { data: mappingData } = useIndexMappings();
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
|
@ -101,6 +101,7 @@ export const SearchMode: React.FC = () => {
|
|||
<EuiFlexItem>
|
||||
{searchQuery.query ? (
|
||||
<ResultList
|
||||
executionTime={executionTime}
|
||||
searchResults={results}
|
||||
mappings={mappingData}
|
||||
pagination={pagination}
|
||||
|
|
|
@ -23,6 +23,7 @@ export interface FetchSearchResultsArgs {
|
|||
}
|
||||
|
||||
interface UseSearchPreviewData {
|
||||
executionTime: number;
|
||||
results: SearchHit[];
|
||||
pagination: Pagination;
|
||||
}
|
||||
|
@ -33,6 +34,7 @@ export interface UseSearchPreviewResponse {
|
|||
}
|
||||
|
||||
export const DEFAULT_SEARCH_PREVIEW_DATA: UseSearchPreviewData = {
|
||||
executionTime: 0,
|
||||
results: [],
|
||||
pagination: DEFAULT_PAGINATION,
|
||||
};
|
||||
|
@ -45,6 +47,7 @@ export const fetchSearchResults = async ({
|
|||
http,
|
||||
}: FetchSearchResultsArgs): Promise<UseSearchPreviewData> => {
|
||||
return http.post<{
|
||||
executionTime: number;
|
||||
results: SearchHit[];
|
||||
pagination: Pagination;
|
||||
}>(APIRoutes.POST_SEARCH_QUERY, {
|
||||
|
@ -98,6 +101,7 @@ export const useSearchPreview = ({
|
|||
});
|
||||
|
||||
return {
|
||||
executionTime: data.executionTime,
|
||||
pagination: data.pagination,
|
||||
results: data.results,
|
||||
};
|
||||
|
|
|
@ -320,6 +320,7 @@ export function defineRoutes({
|
|||
|
||||
return response.ok({
|
||||
body: {
|
||||
executionTime: searchResult.took,
|
||||
results: searchResult.hits.hits,
|
||||
pagination: {
|
||||
from,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue