diff --git a/src/config/healthcheck.js b/src/config/healthcheck.js index ae12cae..888d865 100644 --- a/src/config/healthcheck.js +++ b/src/config/healthcheck.js @@ -229,7 +229,7 @@ export async function getStatus(appConfig, params) { resolve(status); }); } -export default async function healthcheck(appConfig, query) { +export default async function healthcheck(appConfig, params) { // is index ok? // return index update date // run default query, see number of results @@ -244,7 +244,8 @@ export default async function healthcheck(appConfig, query) { queryTimeSecondsThreshold_WARNING, failedSyncThreshold_OK, failedSyncThreshold_WARNING, - } = query; + now, + } = params; documentCountThreshold = documentCountThreshold || default_documentCountThreshold; queryTimeSecondsThreshold_OK = @@ -260,6 +261,7 @@ export default async function healthcheck(appConfig, query) { const airflow_params = { FAILED_SYNC_THRESHOLD_WARNING: failedSyncThreshold_WARNING, FAILED_SYNC_THRESHOLD_OK: failedSyncThreshold_OK, + now: now, }; /////////////////// diff --git a/src/config/healthcheck.test.js b/src/config/healthcheck.test.js index 0792ccb..7695624 100644 --- a/src/config/healthcheck.test.js +++ b/src/config/healthcheck.test.js @@ -7,6 +7,8 @@ import { getlastsuccessfultasks_for_site, getStatus, } from './healthcheck'; +import healthcheck from './healthcheck'; + import { runRequest } from '@eeacms/search'; import failed_scheduled_atempts_since_last_started_resp from './healthcheck_queries/failed_scheduled_atempts_since_last_started_resp.json'; @@ -24,6 +26,7 @@ const SLOTS = [ jest.mock('@eeacms/search', () => ({ SLOTS: SLOTS, runRequest: jest.fn(), + buildRequest: jest.fn(), })); const query1 = { @@ -231,6 +234,47 @@ describe('test parsing the response from elasticsearch for empty response', () = describe('test the status of the index', () => { it('test', async () => { runRequest + .mockReturnValueOnce( + Promise.resolve({ body: last_scheduled_started_indexing_resp }), + ) + .mockReturnValueOnce( + Promise.resolve({ + body: failed_scheduled_atempts_since_last_started_resp, + }), + ) + .mockReturnValueOnce( + Promise.resolve({ + body: last_sync_task_since_last_start_resp, + }), + // ) + // .mockReturnValueOnce( + // Promise.resolve({ + // body: started_or_finished_site_since_last_started_resp, + // }), + ); + const params = { index_name: 'test_index', now: 1695732000000 }; + const status = await getStatus({}, params); + expect(status).toEqual({ status: 'OK' }); + }); +}); + +describe('test the healthcheck', () => { + it('test', async () => { + runRequest + .mockReturnValueOnce( + Promise.resolve({ body: { hits: { total: { value: 60001 } } } }), + ) + .mockReturnValueOnce( + Promise.resolve({ + body: { + elapsed: { + step1: [{ query: { delta: 0.5 } }], + step2: [{ query: { delta: 0.6 } }], + }, + }, + }), + ) + .mockReturnValueOnce( Promise.resolve({ body: last_scheduled_started_indexing_resp }), ) @@ -250,7 +294,7 @@ describe('test the status of the index', () => { }), ); const params = { index_name: 'test_index', now: 1695732000000 }; - const status = await getStatus({}, params); - expect(status).toEqual({ status: 'OK' }); + const status = await healthcheck({}, params); + expect(status).toEqual({ status: '1K' }); }); });