Skip to content

Commit

Permalink
[8.6] [Enterprise Search] Fix logic for long running and orphaned jobs (
Browse files Browse the repository at this point in the history
#145714) (#146514)

# Backport

This will backport the following commits from `main` to `8.6`:
- [[Enterprise Search] Fix logic for long running and orphaned jobs
(#145714)](#145714)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Sander
Philipse","email":"94373878+sphilipse@users.noreply.github.com"},"sourceCommit":{"committedDate":"2022-11-22T13:27:46Z","message":"[Enterprise
Search] Fix logic for long running and orphaned jobs (#145714)\n\nThis
fixes the logic for long-running connector sync jobs: they
should\r\nlook at started_at rather than last_seen.\r\nIt also fixes the
logic for orphaned jobs, which were displaying the\r\nopposite of what
they should have been
displaying.","sha":"2e178f8f450ad6019903af17881c8368806816c8","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:EnterpriseSearch","v8.6.0","v8.7.0"],"number":145714,"url":"https://github.com/elastic/kibana/pull/145714","mergeCommit":{"message":"[Enterprise
Search] Fix logic for long running and orphaned jobs (#145714)\n\nThis
fixes the logic for long-running connector sync jobs: they
should\r\nlook at started_at rather than last_seen.\r\nIt also fixes the
logic for orphaned jobs, which were displaying the\r\nopposite of what
they should have been
displaying.","sha":"2e178f8f450ad6019903af17881c8368806816c8"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/145714","number":145714,"mergeCommit":{"message":"[Enterprise
Search] Fix logic for long running and orphaned jobs (#145714)\n\nThis
fixes the logic for long-running connector sync jobs: they
should\r\nlook at started_at rather than last_seen.\r\nIt also fixes the
logic for orphaned jobs, which were displaying the\r\nopposite of what
they should have been
displaying.","sha":"2e178f8f450ad6019903af17881c8368806816c8"}}]}]
BACKPORT-->
  • Loading branch information
sphilipse authored Nov 29, 2022
1 parent ba7a37e commit 218162f
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 218162f

Please sign in to comment.