Skip to content

Commit

Permalink
merge: #9213
Browse files Browse the repository at this point in the history
9213: [Backport stable/8.0] Do not log health status unnecessarily r=deepthidevaki a=github-actions[bot]

# Description
Backport of #9208 to `stable/8.0`.

relates to #9207

Co-authored-by: Deepthi Devaki Akkoorath <deepthidevaki@gmail.com>
  • Loading branch information
zeebe-bors-camunda[bot] and deepthidevaki committed Apr 22, 2022
2 parents 5317f7c + 1aa745b commit 82d666f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,15 @@ private void calculateHealth() {
final var previousReport = healthReport;
healthReport = calculateStatus();

if (previousReport == healthReport) {
if (previousReport.equals(healthReport)) {
return;
}

switch (healthReport.getStatus()) {
case HEALTHY:
failureListeners.forEach(FailureListener::onRecovered);
break;

case UNHEALTHY:
failureListeners.forEach((l) -> l.onFailure(healthReport));
break;

case DEAD:
failureListeners.forEach((l) -> l.onUnrecoverableFailure(healthReport));
break;

default:
log.warn("Unknown health status {}", healthReport);
break;
case HEALTHY -> failureListeners.forEach(FailureListener::onRecovered);
case UNHEALTHY -> failureListeners.forEach(l -> l.onFailure(healthReport));
case DEAD -> failureListeners.forEach(l -> l.onUnrecoverableFailure(healthReport));
default -> log.warn("Unknown health status {}", healthReport);
}

logComponentStatus(healthReport);
Expand Down
38 changes: 1 addition & 37 deletions util/src/main/java/io/camunda/zeebe/util/health/HealthIssue.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,7 @@
* A health issue contains information about the cause for unhealthy/dead components. It can either
* be a string message, a {@link Throwable} or another {@link HealthReport}.
*/
public final class HealthIssue {

private final String message;
private final Throwable throwable;
private final HealthReport cause;

private HealthIssue(final String message, final Throwable throwable, final HealthReport cause) {
this.message = message;
this.throwable = throwable;
this.cause = cause;
}
public record HealthIssue(String message, Throwable throwable, HealthReport cause) {

public static HealthIssue of(final String message) {
return new HealthIssue(message, null, null);
Expand All @@ -34,30 +24,4 @@ public static HealthIssue of(final Throwable throwable) {
public static HealthIssue of(final HealthReport cause) {
return new HealthIssue(null, null, cause);
}

@Override
public String toString() {
if (cause != null) {
return cause.toString();
}
if (message != null) {
return "'" + message + "'";
}
if (throwable != null) {
return throwable.toString();
}
return "unknown";
}

public String getMessage() {
return message;
}

public Throwable getThrowable() {
return throwable;
}

public HealthReport getCause() {
return cause;
}
}
33 changes: 33 additions & 0 deletions util/src/main/java/io/camunda/zeebe/util/health/HealthReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package io.camunda.zeebe.util.health;

import java.util.Objects;
import java.util.StringJoiner;

/**
Expand Down Expand Up @@ -79,6 +80,38 @@ public HealthIssue getIssue() {
return issue;
}

@Override
public int hashCode() {
int result = component != null ? component.hashCode() : 0;
result = 31 * result + (componentName != null ? componentName.hashCode() : 0);
result = 31 * result + (status != null ? status.hashCode() : 0);
result = 31 * result + (issue != null ? issue.hashCode() : 0);
return result;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

final HealthReport that = (HealthReport) o;

if (!Objects.equals(component, that.component)) {
return false;
}
if (!Objects.equals(componentName, that.componentName)) {
return false;
}
if (status != that.status) {
return false;
}
return Objects.equals(issue, that.issue);
}

@Override
public String toString() {
final var name = componentName == null ? component.getName() : componentName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void shouldTrackRootIssue() {
waitUntilAllDone();

// then
assertThat(monitor.getHealthReport().getIssue().getCause().getIssue()).isEqualTo(issue);
assertThat(monitor.getHealthReport().getIssue().cause().getIssue()).isEqualTo(issue);
}

private void waitUntilAllDone() {
Expand Down

0 comments on commit 82d666f

Please sign in to comment.