From b475aa9a693610b0308abda5bec0d6bbade47727 Mon Sep 17 00:00:00 2001 From: Jared Rhizor Date: Tue, 4 Jan 2022 10:07:24 -0800 Subject: [PATCH] decrease cost of health check (#9288) --- airbyte-api/src/main/openapi/config.yaml | 4 ++-- .../airbyte/scheduler/app/SchedulerApp.java | 2 +- .../airbyte/server/apis/ConfigurationApi.java | 2 +- .../server/handlers/HealthCheckHandler.java | 22 +------------------ .../handlers/HealthCheckHandlerTest.java | 21 +++--------------- airbyte-webapp/src/config/defaultConfig.ts | 2 +- .../api/generated-api-html/index.html | 4 ++-- 7 files changed, 11 insertions(+), 46 deletions(-) diff --git a/airbyte-api/src/main/openapi/config.yaml b/airbyte-api/src/main/openapi/config.yaml index 7bc28ae6c92fe..602b45f2e897a 100644 --- a/airbyte-api/src/main/openapi/config.yaml +++ b/airbyte-api/src/main/openapi/config.yaml @@ -3198,9 +3198,9 @@ components: HealthCheckRead: type: object required: - - db + - available properties: - db: + available: type: boolean # General CheckConnectionRead: diff --git a/airbyte-scheduler/app/src/main/java/io/airbyte/scheduler/app/SchedulerApp.java b/airbyte-scheduler/app/src/main/java/io/airbyte/scheduler/app/SchedulerApp.java index c8e3223057c69..b807255cf9017 100644 --- a/airbyte-scheduler/app/src/main/java/io/airbyte/scheduler/app/SchedulerApp.java +++ b/airbyte-scheduler/app/src/main/java/io/airbyte/scheduler/app/SchedulerApp.java @@ -205,7 +205,7 @@ public static void waitForServer(final Configs configs) throws InterruptedExcept while (!isHealthy) { try { final HealthCheckRead healthCheck = apiClient.getHealthApi().getHealthCheck(); - isHealthy = healthCheck.getDb(); + isHealthy = healthCheck.getAvailable(); } catch (final ApiException e) { LOGGER.info("Waiting for server to become available..."); Thread.sleep(2000); diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/ConfigurationApi.java b/airbyte-server/src/main/java/io/airbyte/server/apis/ConfigurationApi.java index 9ecc6afe61386..05ec930a8ff70 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/apis/ConfigurationApi.java +++ b/airbyte-server/src/main/java/io/airbyte/server/apis/ConfigurationApi.java @@ -214,7 +214,7 @@ public ConfigurationApi(final ConfigRepository configRepository, jobHistoryHandler, schedulerHandler, operationsHandler); - healthCheckHandler = new HealthCheckHandler(configRepository); + healthCheckHandler = new HealthCheckHandler(); archiveHandler = new ArchiveHandler( airbyteVersion, configRepository, diff --git a/airbyte-server/src/main/java/io/airbyte/server/handlers/HealthCheckHandler.java b/airbyte-server/src/main/java/io/airbyte/server/handlers/HealthCheckHandler.java index ed360a10e5808..0495b3e40bd85 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/handlers/HealthCheckHandler.java +++ b/airbyte-server/src/main/java/io/airbyte/server/handlers/HealthCheckHandler.java @@ -5,31 +5,11 @@ package io.airbyte.server.handlers; import io.airbyte.api.model.HealthCheckRead; -import io.airbyte.config.persistence.ConfigRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class HealthCheckHandler { - private static final Logger LOGGER = LoggerFactory.getLogger(HealthCheckHandler.class); - - private final ConfigRepository configRepository; - - public HealthCheckHandler(final ConfigRepository configRepository) { - this.configRepository = configRepository; - } - - // todo (cgardens) - add more checks as we go. public HealthCheckRead health() { - boolean databaseHealth = false; - try { - configRepository.listStandardWorkspaces(true); - databaseHealth = true; - } catch (final Exception e) { - LOGGER.error("database health check failed."); - } - - return new HealthCheckRead().db(databaseHealth); + return new HealthCheckRead().available(true); } } diff --git a/airbyte-server/src/test/java/io/airbyte/server/handlers/HealthCheckHandlerTest.java b/airbyte-server/src/test/java/io/airbyte/server/handlers/HealthCheckHandlerTest.java index 0ae0ebea5ad34..2462c384b46bb 100644 --- a/airbyte-server/src/test/java/io/airbyte/server/handlers/HealthCheckHandlerTest.java +++ b/airbyte-server/src/test/java/io/airbyte/server/handlers/HealthCheckHandlerTest.java @@ -5,31 +5,16 @@ package io.airbyte.server.handlers; import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import io.airbyte.api.model.HealthCheckRead; -import io.airbyte.config.StandardWorkspace; -import io.airbyte.config.persistence.ConfigRepository; -import io.airbyte.validation.json.JsonValidationException; -import java.io.IOException; -import java.util.Collections; import org.junit.jupiter.api.Test; class HealthCheckHandlerTest { @Test - void testDbHealth() throws IOException, JsonValidationException { - final ConfigRepository configRepository = mock(ConfigRepository.class); - final HealthCheckHandler healthCheckHandler = new HealthCheckHandler(configRepository); - - // check db healthy - when(configRepository.listStandardWorkspaces(true)).thenReturn(Collections.singletonList(new StandardWorkspace())); - assertEquals(new HealthCheckRead().db(true), healthCheckHandler.health()); - - doThrow(IOException.class).when(configRepository).listStandardWorkspaces(true); - assertEquals(new HealthCheckRead().db(false), healthCheckHandler.health()); + void testDbHealth() { + final HealthCheckHandler healthCheckHandler = new HealthCheckHandler(); + assertEquals(new HealthCheckRead().available(true), healthCheckHandler.health()); } } diff --git a/airbyte-webapp/src/config/defaultConfig.ts b/airbyte-webapp/src/config/defaultConfig.ts index c245f3b9e8ea7..b187c6856c408 100644 --- a/airbyte-webapp/src/config/defaultConfig.ts +++ b/airbyte-webapp/src/config/defaultConfig.ts @@ -18,7 +18,7 @@ const features: Feature[] = [ const defaultConfig: Config = { ui: uiConfig, segment: { enabled: true, token: "" }, - healthCheckInterval: 10000, + healthCheckInterval: 20000, version: "dev", apiUrl: `${window.location.protocol}//${window.location.hostname}:8001/api/v1/`, integrationUrl: "/docs", diff --git a/docs/reference/api/generated-api-html/index.html b/docs/reference/api/generated-api-html/index.html index c1f96a772aa2b..bff6feaf45603 100644 --- a/docs/reference/api/generated-api-html/index.html +++ b/docs/reference/api/generated-api-html/index.html @@ -2784,7 +2784,7 @@

Return type

Example data

Content-Type: application/json
{
-  "db" : true
+  "available" : true
 }

Produces

@@ -7572,7 +7572,7 @@

DestinationUpdate - HealthCheckRead - Up

-
db
+
available