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

feat: add health check endpoint #3501

Merged
merged 23 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fd22534
feat: add healthcheck endpoint
vcrfxia Oct 7, 2019
6d10311
feat: switch to configexception
vcrfxia Oct 8, 2019
5abf820
feat: make healthcheck interval configurable
vcrfxia Oct 8, 2019
4cebe97
feat: update healthcheck response detail to be a class
vcrfxia Oct 8, 2019
34441bd
feat: healthcheck should not be authenticated
vcrfxia Oct 8, 2019
89297e6
Merge branch 'master' into healthcheck-endpoint
vcrfxia Oct 9, 2019
47818cf
refactor: split out KsqlTarget helper methods
vcrfxia Oct 9, 2019
d619f74
fix: use ServerInternalKsqlClient to get around auth issues
vcrfxia Oct 9, 2019
612f0c0
fix: make Check an interface
vcrfxia Oct 10, 2019
f795d34
fix: move cached response expiry into ResponseCache
vcrfxia Oct 10, 2019
5fa0002
docs: add java doc to ServerInternalKsqlClient
vcrfxia Oct 10, 2019
e8e0647
refactor: make health check two words
vcrfxia Oct 10, 2019
fc0bbba
docs: add docs for new endpoint
vcrfxia Oct 10, 2019
cae31e6
docs: jim's feedback
vcrfxia Oct 10, 2019
548ca3c
refactor: switch to Guava's cache implementation
vcrfxia Oct 14, 2019
3a754bd
fix: sergio's feedback
vcrfxia Oct 14, 2019
ef0797f
fix: checkstyle
vcrfxia Oct 14, 2019
2611061
fix: fix bug in getting entity from response. add integration test
vcrfxia Oct 15, 2019
6d2103b
test: vinoth's feedback
vcrfxia Oct 15, 2019
a678d9e
refactor: switch to LoadingCache
vcrfxia Oct 15, 2019
01cf409
style: checkstyle
vcrfxia Oct 15, 2019
8b176f3
fix: findbugs
vcrfxia Oct 15, 2019
0db13de
fix: make check names public so clients don't have to hardcode
vcrfxia Oct 16, 2019
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
Prev Previous commit
Next Next commit
feat: update healthcheck response detail to be a class
  • Loading branch information
vcrfxia committed Oct 8, 2019
commit 4cebe97bc1f4324733e877b6220b889ec0684b63
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.common.collect.ImmutableList;
import io.confluent.ksql.rest.client.RestResponse;
import io.confluent.ksql.rest.entity.HealthcheckResponse;
import io.confluent.ksql.rest.entity.HealthcheckResponseDetail;
import io.confluent.ksql.rest.entity.KsqlEntityList;
import io.confluent.ksql.rest.server.KsqlRestConfig;
import io.confluent.ksql.services.ServiceContext;
Expand Down Expand Up @@ -46,12 +47,13 @@ public HealthcheckAgent(final ServiceContext serviceContext, final KsqlRestConfi
}

public HealthcheckResponse checkHealth() {
final Map<String, Boolean> results = DEFAULT_CHECKS.stream()
final Map<String, HealthcheckResponseDetail> results = DEFAULT_CHECKS.stream()
.collect(Collectors.toMap(
Check::getName,
check -> isSuccessful(check.getKsqlStatement())
check -> new HealthcheckResponseDetail(isSuccessful(check.getKsqlStatement()))
));
final boolean allHealthy = results.values().stream()
.map(HealthcheckResponseDetail::getIsHealthy)
.reduce(Boolean::logicalAnd)
.orElse(true);
return new HealthcheckResponse(allHealthy, results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public void shouldCheckHealth() {

// Then:
verify(ksqlClient, atLeastOnce()).makeKsqlRequest(eq(SERVER_URI), any());
assertThat(response.getDetails().get("metastore"), is(true));
assertThat(response.getDetails().get("kafka"), is(true));
assertThat(response.getDetails().get("metastore").getIsHealthy(), is(true));
assertThat(response.getDetails().get("kafka").getIsHealthy(), is(true));
assertThat(response.getIsHealthy(), is(true));
}

Expand All @@ -99,7 +99,7 @@ public void shouldReturnUnhealthyIfMetastoreCheckFails() {
final HealthcheckResponse response = healthcheckAgent.checkHealth();

// Then:
assertThat(response.getDetails().get("metastore"), is(false));
assertThat(response.getDetails().get("metastore").getIsHealthy(), is(false));
assertThat(response.getIsHealthy(), is(false));
}

Expand All @@ -113,7 +113,7 @@ public void shouldReturnUnhealthyIfKafkaCheckFails() {
final HealthcheckResponse response = healthcheckAgent.checkHealth();

// Then:
assertThat(response.getDetails().get("kafka"), is(false));
assertThat(response.getDetails().get("kafka").getIsHealthy(), is(false));
assertThat(response.getIsHealthy(), is(false));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
@Immutable
public final class HealthcheckResponse {
private final boolean isHealthy;
private final Map<String, Boolean> details;
private final Map<String, HealthcheckResponseDetail> details;

@JsonCreator
public HealthcheckResponse(
@JsonProperty("isHealthy") final boolean isHealthy,
stevenpyzhang marked this conversation as resolved.
Show resolved Hide resolved
@JsonProperty("details") final Map<String, Boolean> details
@JsonProperty("details") final Map<String, HealthcheckResponseDetail> details
) {
this.isHealthy = isHealthy;
this.details = Objects.requireNonNull(details, "details");
Expand All @@ -41,7 +41,7 @@ public boolean getIsHealthy() {
return isHealthy;
}

public Map<String, Boolean> getDetails() {
public Map<String, HealthcheckResponseDetail> getDetails() {
return details;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2019 Confluent Inc.
*
* Licensed under the Confluent Community License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.confluent.io/confluent-community-license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package io.confluent.ksql.rest.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.errorprone.annotations.Immutable;
import java.util.Objects;

@JsonIgnoreProperties(ignoreUnknown = true)
@Immutable
public final class HealthcheckResponseDetail {
stevenpyzhang marked this conversation as resolved.
Show resolved Hide resolved
private final boolean isHealthy;

@JsonCreator
public HealthcheckResponseDetail(
@JsonProperty("isHealthy") final boolean isHealthy
) {
this.isHealthy = isHealthy;
}

public boolean getIsHealthy() {
return isHealthy;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}

if (o == null || getClass() != o.getClass()) {
return false;
}

final HealthcheckResponseDetail that = (HealthcheckResponseDetail) o;
return isHealthy == that.isHealthy;
}

@Override
public int hashCode() {
return Objects.hash(isHealthy);
}
}