From 0f33d748da335f4056ee1bbd34f4199636edfa81 Mon Sep 17 00:00:00 2001 From: cgardens Date: Mon, 30 Nov 2020 08:09:50 -0800 Subject: [PATCH 1/4] wip --- airbyte-api/src/main/openapi/config.yaml | 26 ++++++++++++++++++- .../airbyte/server/apis/ConfigurationApi.java | 8 ++++++ .../server/handlers/HealthCheckHandler.java | 13 ++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 airbyte-server/src/main/java/io/airbyte/server/handlers/HealthCheckHandler.java diff --git a/airbyte-api/src/main/openapi/config.yaml b/airbyte-api/src/main/openapi/config.yaml index cc0614a25950..d9338e15311f 100644 --- a/airbyte-api/src/main/openapi/config.yaml +++ b/airbyte-api/src/main/openapi/config.yaml @@ -50,6 +50,8 @@ tags: description: Connection between sources and destinations. - name: web_backend description: Connection between sources and destinations. + - name: health + description: Healthchecks paths: /v1/workspaces/get: @@ -914,7 +916,21 @@ paths: $ref: "#/components/schemas/DebugRead" "404": description: Debug info not found - + /v1/health: + get: + tags: + - health + summary: Health Check + operationId: getHealthCheck + responses: + "200": + description: Successful operation + content: + application/json: + schema: + $ref: "#/components/schemas/HealthCheckRead" + "404": + description: Debug info not found components: securitySchemes: bearerAuth: @@ -1618,6 +1634,14 @@ components: type: array items: type: string + # Health + HealthCheckRead: + type: object + required: + - db + properties: + db: + type: boolean # General CheckConnectionRead: type: object 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 67f94f29fd77..fd496abcfb54 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 @@ -43,6 +43,7 @@ import io.airbyte.api.model.DestinationReadList; import io.airbyte.api.model.DestinationRecreate; import io.airbyte.api.model.DestinationUpdate; +import io.airbyte.api.model.HealthCheckRead; import io.airbyte.api.model.JobIdRequestBody; import io.airbyte.api.model.JobInfoRead; import io.airbyte.api.model.JobListRequestBody; @@ -332,6 +333,13 @@ public DebugRead getDebuggingInfo() { return execute(debugInfoHandler::getInfo); } + // HEALTH + @Override + public HealthCheckRead getHealthCheck() { + return null; + } + + // WEB BACKEND @Override 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 new file mode 100644 index 000000000000..e2b539cf10c5 --- /dev/null +++ b/airbyte-server/src/main/java/io/airbyte/server/handlers/HealthCheckHandler.java @@ -0,0 +1,13 @@ +package io.airbyte.server.handlers; + +import io.airbyte.api.model.HealthCheckRead; + +public class HealthCheckHandler { + + public HealthCheckHandler() { + } + + public HealthCheckRead health() { + return null; + } +} From feb03b433eebb0abd424d2c71aebdaccde50f4dd Mon Sep 17 00:00:00 2001 From: cgardens Date: Mon, 30 Nov 2020 13:17:20 -0800 Subject: [PATCH 2/4] add health check --- .../airbyte/server/apis/ConfigurationApi.java | 6 ++- .../server/handlers/HealthCheckHandler.java | 45 ++++++++++++++++++- 2 files changed, 47 insertions(+), 4 deletions(-) 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 fd496abcfb54..0c90a4869cea 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 @@ -76,6 +76,7 @@ import io.airbyte.server.handlers.DebugInfoHandler; import io.airbyte.server.handlers.DestinationDefinitionsHandler; import io.airbyte.server.handlers.DestinationHandler; +import io.airbyte.server.handlers.HealthCheckHandler; import io.airbyte.server.handlers.JobHistoryHandler; import io.airbyte.server.handlers.SchedulerHandler; import io.airbyte.server.handlers.SourceDefinitionsHandler; @@ -106,6 +107,7 @@ public class ConfigurationApi implements io.airbyte.api.V1Api { private final WebBackendConnectionsHandler webBackendConnectionsHandler; private final WebBackendSourceHandler webBackendSourceHandler; private final WebBackendDestinationHandler webBackendDestinationHandler; + private final HealthCheckHandler healthCheckHandler; public ConfigurationApi(final ConfigRepository configRepository, final SchedulerPersistence schedulerPersistence, final SpecCache specCache) { final JsonSchemaValidator schemaValidator = new JsonSchemaValidator(); @@ -122,6 +124,7 @@ public ConfigurationApi(final ConfigRepository configRepository, final Scheduler webBackendSourceHandler = new WebBackendSourceHandler(sourceHandler, schedulerHandler); webBackendDestinationHandler = new WebBackendDestinationHandler(destinationHandler, schedulerHandler); debugInfoHandler = new DebugInfoHandler(configRepository); + healthCheckHandler = new HealthCheckHandler(configRepository); } // WORKSPACE @@ -336,10 +339,9 @@ public DebugRead getDebuggingInfo() { // HEALTH @Override public HealthCheckRead getHealthCheck() { - return null; + return healthCheckHandler.health(); } - // WEB BACKEND @Override 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 e2b539cf10c5..ee4688428340 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 @@ -1,13 +1,54 @@ +/* + * MIT License + * + * Copyright (c) 2020 Airbyte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package io.airbyte.server.handlers; import io.airbyte.api.model.HealthCheckRead; +import io.airbyte.config.persistence.ConfigRepository; +import io.airbyte.config.persistence.PersistenceConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class HealthCheckHandler { - public HealthCheckHandler() { + private static final Logger LOGGER = LoggerFactory.getLogger(HealthCheckHandler.class); + + private final ConfigRepository configRepository; + + public HealthCheckHandler(ConfigRepository configRepository) { + this.configRepository = configRepository; } public HealthCheckRead health() { - return null; + boolean databaseHealth = false; + try { + databaseHealth = configRepository.getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID) != null; + } catch (Exception e) { + LOGGER.error("database health check failed."); + } + + return new HealthCheckRead().db(databaseHealth); } + } From b9b9f60ee4e8d1482160708b24c1d9f59fc05a92 Mon Sep 17 00:00:00 2001 From: cgardens Date: Mon, 30 Nov 2020 14:13:27 -0800 Subject: [PATCH 3/4] add tests --- .../server/handlers/HealthCheckHandler.java | 1 + .../handlers/HealthCheckHandlerTest.java | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 airbyte-server/src/test/java/io/airbyte/server/handlers/HealthCheckHandlerTest.java 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 ee4688428340..ba62cbdac414 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 @@ -40,6 +40,7 @@ public HealthCheckHandler(ConfigRepository configRepository) { this.configRepository = configRepository; } + // todo (cgardens) - add more checks as we go. public HealthCheckRead health() { boolean databaseHealth = false; try { 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 new file mode 100644 index 000000000000..dbd5d4093710 --- /dev/null +++ b/airbyte-server/src/test/java/io/airbyte/server/handlers/HealthCheckHandlerTest.java @@ -0,0 +1,60 @@ +/* + * MIT License + * + * Copyright (c) 2020 Airbyte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +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.ConfigNotFoundException; +import io.airbyte.config.persistence.ConfigRepository; +import io.airbyte.config.persistence.PersistenceConstants; +import io.airbyte.validation.json.JsonValidationException; +import java.io.IOException; +import org.junit.jupiter.api.Test; + +class HealthCheckHandlerTest { + + @Test + void testDbHealth() throws ConfigNotFoundException, IOException, JsonValidationException { + final ConfigRepository configRepository = mock(ConfigRepository.class); + final HealthCheckHandler healthCheckHandler = new HealthCheckHandler(configRepository); + + // check db healthy + when(configRepository.getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID)).thenReturn(new StandardWorkspace()); + assertEquals(new HealthCheckRead().db(true), healthCheckHandler.health()); + + // check db unhealthy + when(configRepository.getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID)).thenReturn(null); + assertEquals(new HealthCheckRead().db(false), healthCheckHandler.health()); + + doThrow(IOException.class).when(configRepository.getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID)); + assertEquals(new HealthCheckRead().db(false), healthCheckHandler.health()); + } + +} From 7887503c2b4c010f956e49ed5d37dfecc1293402 Mon Sep 17 00:00:00 2001 From: cgardens Date: Mon, 30 Nov 2020 14:15:10 -0800 Subject: [PATCH 4/4] unfinished stubbing => finished stubbing --- .../java/io/airbyte/server/handlers/HealthCheckHandlerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 dbd5d4093710..71e881fd668d 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 @@ -53,7 +53,7 @@ void testDbHealth() throws ConfigNotFoundException, IOException, JsonValidationE when(configRepository.getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID)).thenReturn(null); assertEquals(new HealthCheckRead().db(false), healthCheckHandler.health()); - doThrow(IOException.class).when(configRepository.getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID)); + doThrow(IOException.class).when(configRepository).getStandardWorkspace(PersistenceConstants.DEFAULT_WORKSPACE_ID); assertEquals(new HealthCheckRead().db(false), healthCheckHandler.health()); }