From fc5d4b5d2d4f529ee43b32d21659f6d3548f4bad Mon Sep 17 00:00:00 2001 From: Sander Philipse <94373878+sphilipse@users.noreply.github.com> Date: Tue, 22 Nov 2022 14:27:46 +0100 Subject: [PATCH] [Enterprise Search] Fix logic for long running and orphaned jobs (#145714) This fixes the logic for long-running connector sync jobs: they should look at started_at rather than last_seen. It also fixes the logic for orphaned jobs, which were displaying the opposite of what they should have been displaying. (cherry picked from commit 2e178f8f450ad6019903af17881c8368806816c8) --- .../server/lib/stats/get_sync_jobs.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/enterprise_search/server/lib/stats/get_sync_jobs.ts b/x-pack/plugins/enterprise_search/server/lib/stats/get_sync_jobs.ts index 99d62926eddd2..64d1adc45ff16 100644 --- a/x-pack/plugins/enterprise_search/server/lib/stats/get_sync_jobs.ts +++ b/x-pack/plugins/enterprise_search/server/lib/stats/get_sync_jobs.ts @@ -24,8 +24,14 @@ export const fetchSyncJobsStats = async (client: IScopedClusterClient): Promise< const orphanedJobsCountResponse = await client.asCurrentUser.count({ index: CONNECTORS_JOBS_INDEX, query: { - terms: { - 'connector.id': ids, + bool: { + must_not: [ + { + terms: { + 'connector.id': ids, + }, + }, + ], }, }, }); @@ -51,7 +57,7 @@ export const fetchSyncJobsStats = async (client: IScopedClusterClient): Promise< }, { range: { - last_seen: { + started_at: { lt: moment().subtract(1, 'day').toISOString(), }, }, @@ -62,10 +68,10 @@ export const fetchSyncJobsStats = async (client: IScopedClusterClient): Promise< }); const errorResponse = await client.asCurrentUser.count({ - index: CONNECTORS_JOBS_INDEX, + index: CONNECTORS_INDEX, query: { term: { - status: SyncStatus.ERROR, + last_sync_status: SyncStatus.ERROR, }, }, }); @@ -109,7 +115,7 @@ export const fetchSyncJobsStats = async (client: IScopedClusterClient): Promise< { range: { last_seen: { - gt: moment().subtract(30, 'minutes').toISOString(), + lt: moment().subtract(30, 'minutes').toISOString(), }, }, },