Skip to content

Commit

Permalink
uptime - handle index not found errors (elastic#142685)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiqueclarke authored Oct 5, 2022
1 parent a2a2418 commit 9ad4a71
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/uptime/server/lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function createUptimeESClient({
esError,
esRequestParams: esParams,
esRequestStatus,
esResponse: res.body,
esResponse: res?.body,
kibanaRequest: request!,
operationName: operationName ?? '',
startTime: startTimeNow,
Expand Down
38 changes: 25 additions & 13 deletions x-pack/plugins/uptime/server/lib/requests/get_index_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,30 @@ import { StatesIndexStatus } from '../../../common/runtime_types';
export const getIndexStatus: UMElasticsearchQueryFn<{}, StatesIndexStatus> = async ({
uptimeEsClient,
}) => {
const {
indices,
result: {
body: {
_shards: { total },
count,
try {
const {
indices,
result: {
body: {
_shards: { total },
count,
},
},
},
} = await uptimeEsClient.count({ terminateAfter: 1 });
return {
indices,
indexExists: total > 0,
docCount: count,
};
} = await uptimeEsClient.count({ terminateAfter: 1 });
return {
indices,
indexExists: total > 0,
docCount: count,
};
} catch (e) {
if (e.meta.statusCode === 404) {
// we don't throw an error for index not found
return {
indices: '',
indexExists: false,
docCount: 0,
};
}
throw e;
}
};

0 comments on commit 9ad4a71

Please sign in to comment.