Add logging to native health check#231
Open
fsamuel-bs wants to merge 1 commit intopalantir:masterfrom
Open
Conversation
We fail after 2 minutes when checking the native health check. This might not be enough time to have all the docker containers up. We can configure the timeout, but it was quite hard to debug this without logging.
fsamuel-bs
commented
Mar 21, 2018
|
|
||
| @FunctionalInterface | ||
| public interface ClusterHealthCheck { | ||
| Logger log = LoggerFactory.getLogger(ClusterHealthCheck.class); |
Author
There was a problem hiding this comment.
Having this here is sad. Should I make ClusterHealthCheck an abstract class and have this as a private variable?
Contributor
There was a problem hiding this comment.
Nope - instead, note that this is only used in NativeHealthCheck and do
static ClusterHealthCheck nativeHealthChecks() {
return new ClusterHealthCheck() {
static final Logger log = LoggerFactory.getLogger(ClusterHealthCheck.class);
@Override
SuccessOrFailure isClusterHealthy(Cluster cluster) throws InterruptedException {
Set<String> unhealthyContainers = new LinkedHashSet<>();
.........
}
}
}
j-baker
reviewed
Mar 27, 2018
| return cluster -> { | ||
| Set<String> unhealthyContainers = new LinkedHashSet<>(); | ||
| try { | ||
| log.info("Checking health of containers {}", |
Contributor
There was a problem hiding this comment.
these may be a little spammy, FYI. Think this is done in a fairly tight loop, so you may end up with many log lines.
Instead, I'd recommend doing this like:
Set<String> lastUnhealthyContainers = new LinkedHashSet<>();
return new ClusterHealthCheck() {
@Override
public SuccessOrFailure isClusterHealthy(Cluster cluster) throws InterruptedException {
Set<String> currentUnhealthyContainers = new LinkedHashSet<>();
boolean healthyContainerSetChanged = false;
for (Container container : cluster.allContainers()) {
State state = container.state();
if (state == State.UNHEALTHY) {
currentUnhealthyContainers.add(container.getContainerName());
}
}
if (currentUnhealthyContainers.equals(lastUnhealthyContainers)) {
log(currentUnhealthyContainers);
lastUnhealthyContainers.clear();
lastUnhealthyContainers.addAll(currentUnhealthyContainers);
}
if (!currentUnhealthyContainers.isEmpty()) {
return SuccessOrFailure.failure("The following containers are not healthy: " ...);
}
return SuccessOrFailure.success();
}
}
Contributor
There was a problem hiding this comment.
where you only log if the state has actually changed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We fail after 2 minutes when checking the native health check.
This might not be enough time to have all the docker containers up.
We can configure the timeout, but it was quite hard to debug it without logging.