Skip to content

Commit

Permalink
Adding debug mode for circuit breakers (#162)
Browse files Browse the repository at this point in the history
* Adding debug mode for circuit breakers

* Tidying code
  • Loading branch information
Justin Sweeney authored and patsonluk committed Nov 27, 2023
1 parent 673122f commit 36b312a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public abstract class CircuitBreaker implements NamedListInitializedPlugin, Clos
private final List<SolrRequestType> SUPPORTED_TYPES =
List.of(SolrRequestType.QUERY, SolrRequestType.UPDATE);

private boolean debugMode = false;

@Override
public void init(NamedList<?> args) {
SolrPluginUtils.invokeSetters(this, args);
Expand All @@ -62,6 +64,10 @@ public CircuitBreaker() {}
/** Get error message when the circuit breaker triggers */
public abstract String getErrorMessage();

public boolean isDebugMode() {
return debugMode;
}

@Override
public void close() throws IOException {
// Nothing to do by default
Expand Down Expand Up @@ -110,4 +116,8 @@ public static SolrException.ErrorCode getErrorCode(List<CircuitBreaker> trippedC
return SolrException.ErrorCode.TOO_MANY_REQUESTS;
}
}

public void setDebugMode(boolean debugMode) {
this.debugMode = debugMode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,20 @@ public List<CircuitBreaker> checkTripped(SolrRequestType requestType) {
for (CircuitBreaker circuitBreaker :
circuitBreakerMap.getOrDefault(requestType, Collections.emptyList())) {
if (circuitBreaker.isTripped()) {
if (triggeredCircuitBreakers == null) {
triggeredCircuitBreakers = new ArrayList<>();
if (circuitBreaker.isDebugMode()) {
if (log.isInfoEnabled()) {
log.info(
"Circuit breaker {} has tripped: {}",
circuitBreaker.getClass().getSimpleName(),
circuitBreaker.getErrorMessage());
}
} else {
if (triggeredCircuitBreakers == null) {
triggeredCircuitBreakers = new ArrayList<>();
}

triggeredCircuitBreakers.add(circuitBreaker);
}

triggeredCircuitBreakers.add(circuitBreaker);
}
}

Expand Down

0 comments on commit 36b312a

Please sign in to comment.