Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decrease cost of health check #9288

Merged
merged 1 commit into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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