[Synthetics] Fix index not existence error (#134018)

This commit is contained in:
Shahzad 2022-06-13 19:51:56 +02:00 committed by GitHub
parent b0ff0c1c53
commit ef9ab9acdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 14 deletions

View file

@ -89,7 +89,7 @@ export function createUptimeESClient({
esError,
esRequestParams: esParams,
esRequestStatus,
esResponse: res.body,
esResponse: res?.body,
kibanaRequest: request!,
operationName: operationName ?? '',
startTime: startTimeNow,

View file

@ -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({ terminate_after: 1 });
return {
indices,
indexExists: total > 0,
docCount: count,
};
} = await uptimeEsClient.count({ terminate_after: 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;
}
};