mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[SearchProfiler] Handle scenario when user has no indices (#128066)
This commit is contained in:
parent
c55bb917fa
commit
d253355234
3 changed files with 89 additions and 14 deletions
|
@ -21,6 +21,16 @@ interface ReturnValue {
|
|||
error?: string;
|
||||
}
|
||||
|
||||
interface ProfileResponse {
|
||||
profile?: { shards: ShardSerialized[] };
|
||||
_shards: {
|
||||
failed: number;
|
||||
skipped: number;
|
||||
total: number;
|
||||
successful: number;
|
||||
};
|
||||
}
|
||||
|
||||
const extractProfilerErrorMessage = (e: any): string | undefined => {
|
||||
if (e.body?.attributes?.error?.reason) {
|
||||
const { reason, line, col } = e.body.attributes.error;
|
||||
|
@ -67,8 +77,7 @@ export const useRequestProfile = () => {
|
|||
|
||||
try {
|
||||
const resp = await http.post<
|
||||
| { ok: true; resp: { profile: { shards: ShardSerialized[] } } }
|
||||
| { ok: false; err: { msg: string } }
|
||||
{ ok: true; resp: ProfileResponse } | { ok: false; err: { msg: string } }
|
||||
>('../api/searchprofiler/profile', {
|
||||
body: JSON.stringify(payload),
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
|
@ -78,7 +87,23 @@ export const useRequestProfile = () => {
|
|||
return { data: null, error: resp.err.msg };
|
||||
}
|
||||
|
||||
return { data: resp.resp.profile.shards };
|
||||
// If a user attempts to run Search Profiler without any indices,
|
||||
// _shards=0 and a "profile" output will not be returned
|
||||
if (resp.resp._shards.total === 0) {
|
||||
notifications.addDanger({
|
||||
'data-test-subj': 'noShardsNotification',
|
||||
title: i18n.translate('xpack.searchProfiler.errorNoShardsTitle', {
|
||||
defaultMessage: 'Unable to profile',
|
||||
}),
|
||||
text: i18n.translate('xpack.searchProfiler.errorNoShardsDescription', {
|
||||
defaultMessage: 'Verify your index input matches a valid index',
|
||||
}),
|
||||
});
|
||||
|
||||
return { data: null };
|
||||
}
|
||||
|
||||
return { data: resp.resp.profile!.shards };
|
||||
} catch (e) {
|
||||
const profilerErrorMessage = extractProfilerErrorMessage(e);
|
||||
if (profilerErrorMessage) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue