webiny / webiny-js

Open-source serverless enterprise CMS. Includes a headless CMS, page builder, form builder, and file manager. Easy to customize and expand. Deploys to AWS.
https://www.webiny.com
Other
7.24k stars 590 forks source link

fix(api-elasticsearch): health and node checks #4143

Closed brunozoric closed 2 months ago

brunozoric commented 2 months ago

Changes

This PR introduces Elasticsearch/OpenSearch health and node checks. They need to be called manually, but they will help with determining if the cluster is good for writes/reads.

How Has This Been Tested?

Jest.

Usage

// Configure the utility.
const waitUntilHealthy = createWaitUntilHealthy(client, {
    minStatus: ElasticsearchCatHealthStatus.Yellow,
    maxProcessorPercent: 101,
    maxWaitingTime: 30,
    waitingTimeStep: 5,
    maxRamPercent: 101
});
// Wait until the cluster is healthy.
// It will throw an error on Abort and on Timeout (when maxWaitingTime is hit).
const { runs, runningTime } = await waitUntilHealthy.wait({
    async onUnhealthy(params) {
        const { runs, startedAt, mustEndAt, waitingTimeStep } = params;
    },
    async onTimeout(params) {
        const { runs, startedAt, mustEndAt, waitingTimeStep } = params;
        // log some info?
    }
});

// continue with your regular code