Skip to content

Commit

Permalink
decrease cost of health check (#9288)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhizor authored Jan 4, 2022
1 parent c0a46c1 commit b475aa9
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 46 deletions.
4 changes: 2 additions & 2 deletions airbyte-api/src/main/openapi/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3198,9 +3198,9 @@ components:
HealthCheckRead:
type: object
required:
- db
- available
properties:
db:
available:
type: boolean
# General
CheckConnectionRead:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public ConfigurationApi(final ConfigRepository configRepository,
jobHistoryHandler,
schedulerHandler,
operationsHandler);
healthCheckHandler = new HealthCheckHandler(configRepository);
healthCheckHandler = new HealthCheckHandler();
archiveHandler = new ArchiveHandler(
airbyteVersion,
configRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
2 changes: 1 addition & 1 deletion airbyte-webapp/src/config/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/api/generated-api-html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2784,7 +2784,7 @@ <h3 class="field-label">Return type</h3>
<h3 class="field-label">Example data</h3>
<div class="example-data-content-type">Content-Type: application/json</div>
<pre class="example"><code>{
"db" : true
"available" : true
}</code></pre>

<h3 class="field-label">Produces</h3>
Expand Down Expand Up @@ -7572,7 +7572,7 @@ <h3><a name="DestinationUpdate"><code>DestinationUpdate</code> - </a> <a class="
<h3><a name="HealthCheckRead"><code>HealthCheckRead</code> - </a> <a class="up" href="#__Models">Up</a></h3>
<div class='model-description'></div>
<div class="field-items">
<div class="param">db </div><div class="param-desc"><span class="param-type"><a href="#boolean">Boolean</a></span> </div>
<div class="param">available </div><div class="param-desc"><span class="param-type"><a href="#boolean">Boolean</a></span> </div>
</div> <!-- field-items -->
</div>
<div class="model">
Expand Down

0 comments on commit b475aa9

Please sign in to comment.