Skip to content

Commit

Permalink
[Enterprise Search] Fix logic for long running and orphaned jobs (ela…
Browse files Browse the repository at this point in the history
…stic#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 2e178f8)
  • Loading branch information
sphilipse committed Nov 29, 2022
1 parent 7375f91 commit fc5d4b5
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions x-pack/plugins/enterprise_search/server/lib/stats/get_sync_jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
],
},
},
});
Expand All @@ -51,7 +57,7 @@ export const fetchSyncJobsStats = async (client: IScopedClusterClient): Promise<
},
{
range: {
last_seen: {
started_at: {
lt: moment().subtract(1, 'day').toISOString(),
},
},
Expand All @@ -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,
},
},
});
Expand Down Expand Up @@ -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(),
},
},
},
Expand Down

0 comments on commit fc5d4b5

Please sign in to comment.