Skip to content

Commit

Permalink
Merge branch 'feature/improve-incident-messages' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rnschk committed May 24, 2021
2 parents d10c8ab + b6ced18 commit e5e2342
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public final class InstantIncidentException extends RuntimeException {
*
*/
public InstantIncidentException() {
super();
}

/**
Expand Down Expand Up @@ -74,7 +75,7 @@ public InstantIncidentException(final String message, final Throwable cause) {
* @param cause root cause passed to the process
*/
public InstantIncidentException(final Throwable cause) {
super(cause);
super(null, cause);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ private long nextRetryInterval(final Integer remainingRetries, String retryPrope
return 0L;
}

if (retryProperty == null || retryProperty.trim().isEmpty()) {
// if empty retry-config, start again using the default
return nextRetryInterval(remainingRetries, this.valueVault.getDefaultRetryConfig(), true);
}

retryProperty = retryProperty.replace(" ", "").toUpperCase();

Matcher retryListMatcher = this.valueVault.getRetryListPattern().matcher(retryProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public final class RetryConfigValues {
//@formatter:off
private static final long FALLBACK_INTERVAL = 5 * 60 * 1000L; // 5 minutes
private static final String FALLBACK_RETRY_CONFIG = "R3/PT5M";
private static final String FALLBACK_RETRY_CONFIG_NAME = "RETRY_CONFIG";

private static final String RETRY_LIST_REGEX = "^([Pp](?:\\d+[Dd])?(?:[Tt](?!$)(?:\\d+[Hh])?(?:\\d+[Mm])?(?:\\d+[Ss])?)?)(,([Pp](?:\\d+[Dd])?(?:[Tt](?!$)(?:\\d+[Hh])?(?:\\d+[Mm])?(?:\\d+[Ss])?)?))*$";
private static final String RETRY_CYCLE_REGEX = "^(?:[Rr](?<times>\\d+)/)(?<interval>(?:[Pp](?:\\d+[Yy])?)(?:\\d+[Mm])?(?:\\d+[Dd])?(?:[Tt](?!$)(?:\\d+[Hh])?(?:\\d+[Mm])?(?:\\d+[Ss])?)?)$";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
import java.io.StringWriter;
import java.util.Objects;

import static java.lang.String.format;
import static java.util.Objects.isNull;


public class FailureService {

Expand Down Expand Up @@ -79,12 +82,44 @@ public void handleFailure(final Class<?> origin,
}


private String getErrorMessage(final Throwable throwable) {
if (throwable instanceof InstantIncidentException && Objects.nonNull(throwable.getCause())) {
// if instant-incident, probably root cause is more relevant
return this.getErrorMessage(throwable.getCause());
private String getErrorMessage(final Throwable exception) {

if (!(exception instanceof InstantIncidentException)) {
// AnotherTypeException() -> "AnotherType: another-message"
return exception.getClass().getSimpleName() + ": " + exception.getMessage();
}

if (isNull(exception.getMessage())) { // no message

if (isNull(exception.getCause())) {
// no root-cause: InstantIncidentException()
// -> InstantIncident
return "InstantIncident";

} else {
// with root-cause: InstantIncidentException(cause)
// -> CauseType: cause-message (InstantIncident)
return format("%s: %s (InstantIncident)",
exception.getCause().getClass().getSimpleName(),
exception.getCause().getMessage());
}

} else { // with message

if (isNull(exception.getCause())) {
// no root-cause: InstantIncidentException("message")
// -> InstantIncident: message
return "InstantIncident: " + exception.getMessage();

} else {
// with root-cause InstantIncidentException("message", cause)
// -> CauseType: cause-message (InstantIncident: message)
return format("%s: %s (InstantIncident: %s)",
exception.getCause().getClass().getSimpleName(),
exception.getCause().getMessage(),
exception.getMessage());
}
}
return throwable.getClass().getSimpleName() + ": " + throwable.getMessage();
}


Expand All @@ -102,10 +137,10 @@ private String getStackTrace(final Throwable throwable) {

private void logFailure(final Class<?> origin, final Throwable throwable, final int remainingRetries, final Long nextRetryInterval) {
// log remaining time only if retries > 0
final String millisIfRemainingRetry = String.format("%s", (remainingRetries == 0) ? "" : ", next retry in " + nextRetryInterval + "ms");
final String millisIfRemainingRetry = format("%s", (remainingRetries == 0) ? "" : ", next retry in " + nextRetryInterval + "ms");

final String errorLogString =
String.format("%s: %s. There are %s retry(s) left%s",
format("%s: %s. There are %s retry(s) left%s",
throwable.getClass().getSimpleName(),
throwable.getMessage(),
remainingRetries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void instantIncidentExceptionWithRootCause() {
this.verifyHandleFailure();

// assert
this.assertErrorMessage(rootCause.getClass().getSimpleName() + ": " + rootCause.getMessage());
this.assertErrorMessage("RuntimeException: root-cause (InstantIncident: no-retries)");
this.assertErrorDetails(rootCause);
this.assertNextRetryInterval(0);
this.assertNoRemainingRetries();
Expand All @@ -101,7 +101,7 @@ public void emptyInstantIncidentExceptionWithRootCause() {
this.verifyHandleFailure();

// assert
this.assertErrorMessage("InstantIncidentException: null");
this.assertErrorMessage("InstantIncident");
//this.assertErrorDetails(new InstantIncidentException());
this.assertNextRetryInterval(0);
this.assertNoRemainingRetries();
Expand All @@ -120,7 +120,7 @@ public void emptyRootInstantIncidentException() {
this.verifyHandleFailure();

// assert
this.assertErrorMessage("RuntimeException: null");
this.assertErrorMessage("RuntimeException: null (InstantIncident)");
this.assertErrorDetails(instantIncidentException.getCause());
this.assertNextRetryInterval(0);
this.assertNoRemainingRetries();
Expand All @@ -140,7 +140,7 @@ public void instantIncidentException() {
this.verifyHandleFailure();

// assert
this.assertErrorMessage("InstantIncidentException: instant-incident-no-retries-plz");
this.assertErrorMessage("InstantIncident: instant-incident-no-retries-plz");
this.assertErrorDetails(instantIncidentException);
this.assertNextRetryInterval(0);
this.assertNoRemainingRetries();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@

import static org.mockito.Mockito.when;

@TestPropertySource(properties = "de.viadee.bpm.camunda.external-task.retry-config.defaults=R3/PT1D")
@TestPropertySource(properties = "de.viadee.bpm.camunda.external-task.retry-config.default-behavior=R3/PT1D")
public class InvalidDefaultBehaviourTest extends BaseTest {


@Test
public void runtimeException() {
// prepare
when(this.externalTask.getRetries()).thenReturn(null);
when(this.externalTask.getExtensionProperty(this.properties.getIdentifier())).thenReturn("invld!");

// test
this.externalTaskRetryAspect.handleErrorAfterThrown(this.joinPoint, new RuntimeException(), this.externalTask, this.externalTaskService);
Expand Down

0 comments on commit e5e2342

Please sign in to comment.