Skip to content

Commit

Permalink
Revert "Adding debug mode to circuit breakers to be able to evaluate …
Browse files Browse the repository at this point in the history
…behavior (#153)"

This reverts commit 38c7694.
  • Loading branch information
Justin Sweeney committed Apr 26, 2024
1 parent baf21fa commit 80b45cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
package org.apache.solr.util.circuitbreaker;

import com.google.common.annotations.VisibleForTesting;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.PluginInfo;
import org.apache.solr.util.plugin.PluginInfoInitialized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Manages all registered circuit breaker instances. Responsible for a holistic view of whether a
Expand All @@ -42,18 +39,13 @@
* term solution. There will be a follow up with a SIP for a schema API design.
*/
public class CircuitBreakerManager implements PluginInfoInitialized {

private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
// Class private to potentially allow "family" of circuit breakers to be enabled or disabled
private final boolean enableCircuitBreakerManager;

private final boolean debugMode;

private final List<CircuitBreaker> circuitBreakerList = new ArrayList<>();

public CircuitBreakerManager(final boolean enableCircuitBreakerManager, final boolean debugMode) {
public CircuitBreakerManager(final boolean enableCircuitBreakerManager) {
this.enableCircuitBreakerManager = enableCircuitBreakerManager;
this.debugMode = debugMode;
}

@Override
Expand Down Expand Up @@ -86,20 +78,11 @@ public List<CircuitBreaker> checkTripped() {
if (enableCircuitBreakerManager) {
for (CircuitBreaker circuitBreaker : circuitBreakerList) {
if (circuitBreaker.isEnabled() && circuitBreaker.isTripped()) {
if (debugMode) {
if (log.isInfoEnabled()) {
log.info(
"Circuit tripped for {} with debug info {}",
circuitBreaker.getClass().getName(),
circuitBreaker.getDebugInfo());
}
} else {
if (triggeredCircuitBreakers == null) {
triggeredCircuitBreakers = new ArrayList<>();
}

triggeredCircuitBreakers.add(circuitBreaker);
if (triggeredCircuitBreakers == null) {
triggeredCircuitBreakers = new ArrayList<>();
}

triggeredCircuitBreakers.add(circuitBreaker);
}
}
}
Expand All @@ -117,16 +100,7 @@ public boolean checkAnyTripped() {
if (enableCircuitBreakerManager) {
for (CircuitBreaker circuitBreaker : circuitBreakerList) {
if (circuitBreaker.isEnabled() && circuitBreaker.isTripped()) {
if (debugMode) {
if (log.isInfoEnabled()) {
log.info(
"Circuit tripped for {} with debug info {}",
circuitBreaker.getClass().getName(),
circuitBreaker.getDebugInfo());
}
} else {
return true;
}
return true;
}
}
}
Expand Down Expand Up @@ -162,11 +136,7 @@ public static CircuitBreakerManager build(PluginInfo pluginInfo) {
pluginInfo == null
? false
: Boolean.parseBoolean(pluginInfo.attributes.getOrDefault("enabled", "false"));
boolean debugMode =
pluginInfo == null
? false
: Boolean.parseBoolean(pluginInfo.attributes.getOrDefault("debugMode", "false"));
CircuitBreakerManager circuitBreakerManager = new CircuitBreakerManager(enabled, debugMode);
CircuitBreakerManager circuitBreakerManager = new CircuitBreakerManager(enabled);

circuitBreakerManager.init(pluginInfo);

Expand Down
15 changes: 0 additions & 15 deletions solr/core/src/test/org/apache/solr/util/TestCircuitBreaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,6 @@ public void testFakeCPUCircuitBreaker() {
}
}

public void testCircuitBreakerDebug() {
CircuitBreakerManager circuitBreakerManager = new CircuitBreakerManager(true, true);
PluginInfo pluginInfo =
h.getCore().getSolrConfig().getPluginInfo(CircuitBreakerManager.class.getName());

CircuitBreaker.CircuitBreakerConfig circuitBreakerConfig =
CircuitBreakerManager.buildCBConfig(pluginInfo);
CircuitBreaker circuitBreaker = new FakeCPUCircuitBreaker(circuitBreakerConfig);
circuitBreakerManager.register(circuitBreaker);

assertFalse(circuitBreakerManager.checkAnyTripped());

assertNull(circuitBreakerManager.checkTripped());
}

private void removeAllExistingCircuitBreakers() {
List<CircuitBreaker> registeredCircuitBreakers =
h.getCore().getCircuitBreakerManager().getRegisteredCircuitBreakers();
Expand Down

0 comments on commit 80b45cb

Please sign in to comment.