Search in sources :

Example 1 with HierarchyCircuitBreakerService

use of org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService in project elasticsearch by elastic.

the class CircuitBreakerUnitTests method testRegisterCustomBreaker.

public void testRegisterCustomBreaker() throws Exception {
    CircuitBreakerService service = new HierarchyCircuitBreakerService(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
    String customName = "custom";
    BreakerSettings settings = new BreakerSettings(customName, 20, 1.0);
    service.registerBreaker(settings);
    CircuitBreaker breaker = service.getBreaker(customName);
    assertThat(breaker, notNullValue());
    assertThat(breaker, instanceOf(CircuitBreaker.class));
    assertThat(breaker.getName(), is(customName));
}
Also used : BreakerSettings(org.elasticsearch.indices.breaker.BreakerSettings) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService)

Example 2 with HierarchyCircuitBreakerService

use of org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService in project elasticsearch by elastic.

the class RestControllerTests method setup.

@Before
public void setup() {
    Settings settings = Settings.EMPTY;
    circuitBreakerService = new HierarchyCircuitBreakerService(Settings.builder().put(HierarchyCircuitBreakerService.IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), BREAKER_LIMIT).build(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
    // we can do this here only because we know that we don't adjust breaker settings dynamically in the test
    inFlightRequestsBreaker = circuitBreakerService.getBreaker(CircuitBreaker.IN_FLIGHT_REQUESTS);
    HttpServerTransport httpServerTransport = new TestHttpServerTransport();
    restController = new RestController(settings, Collections.emptySet(), null, null, circuitBreakerService);
    restController.registerHandler(RestRequest.Method.GET, "/", (request, channel, client) -> channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY)));
    restController.registerHandler(RestRequest.Method.GET, "/error", (request, channel, client) -> {
        throw new IllegalArgumentException("test error");
    });
    httpServerTransport.start();
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) Settings(org.elasticsearch.common.settings.Settings) HttpTransportSettings(org.elasticsearch.http.HttpTransportSettings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Before(org.junit.Before)

Example 3 with HierarchyCircuitBreakerService

use of org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService in project elasticsearch by elastic.

the class ZenFaultDetectionTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    Settings settings = Settings.builder().put(HierarchyCircuitBreakerService.IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), new ByteSizeValue(0)).build();
    ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    threadPool = new TestThreadPool(getClass().getName());
    circuitBreakerService = new HierarchyCircuitBreakerService(settings, clusterSettings);
    settingsA = Settings.builder().put("node.name", "TS_A").put(settings).build();
    serviceA = build(settingsA, version0);
    nodeA = serviceA.getLocalDiscoNode();
    settingsB = Settings.builder().put("node.name", "TS_B").put(settings).build();
    serviceB = build(settingsB, version1);
    nodeB = serviceB.getLocalDiscoNode();
    clusterServiceA = createClusterService(settingsA, threadPool, nodeA);
    clusterServiceB = createClusterService(settingsB, threadPool, nodeB);
    // wait till all nodes are properly connected and the event has been sent, so tests in this class
    // will not get this callback called on the connections done in this setup
    final CountDownLatch latch = new CountDownLatch(2);
    TransportConnectionListener waitForConnection = new TransportConnectionListener() {

        @Override
        public void onNodeConnected(DiscoveryNode node) {
            latch.countDown();
        }

        @Override
        public void onNodeDisconnected(DiscoveryNode node) {
            fail("disconnect should not be called " + node);
        }
    };
    serviceA.addConnectionListener(waitForConnection);
    serviceB.addConnectionListener(waitForConnection);
    serviceA.connectToNode(nodeB);
    serviceA.connectToNode(nodeA);
    serviceB.connectToNode(nodeA);
    serviceB.connectToNode(nodeB);
    assertThat("failed to wait for all nodes to connect", latch.await(5, TimeUnit.SECONDS), equalTo(true));
    serviceA.removeConnectionListener(waitForConnection);
    serviceB.removeConnectionListener(waitForConnection);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) CountDownLatch(java.util.concurrent.CountDownLatch) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) TransportConnectionListener(org.elasticsearch.transport.TransportConnectionListener) Before(org.junit.Before)

Example 4 with HierarchyCircuitBreakerService

use of org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService in project crate by crate.

the class CrateCircuitBreakerServiceTest method testBreakerSettingsAssignment.

@Test
public void testBreakerSettingsAssignment() throws Exception {
    Settings settings = Settings.builder().put(CrateCircuitBreakerService.QUERY_CIRCUIT_BREAKER_LIMIT_SETTING, "10m").put(CrateCircuitBreakerService.QUERY_CIRCUIT_BREAKER_OVERHEAD_SETTING, 1.0).build();
    final NodeSettingsService.Listener[] listeners = new NodeSettingsService.Listener[1];
    NodeSettingsService settingsService = new NodeSettingsService(settings) {

        @Override
        public void addListener(Listener listener) {
            listeners[0] = listener;
        }
    };
    CircuitBreakerService esBreakerService = spy(new HierarchyCircuitBreakerService(Settings.EMPTY, settingsService));
    CrateCircuitBreakerService breakerService = new CrateCircuitBreakerService(settings, settingsService, esBreakerService);
    CircuitBreaker breaker = breakerService.getBreaker(CrateCircuitBreakerService.QUERY);
    assertThat(breaker.getLimit(), is(10_485_760L));
    assertThat(breaker.getOverhead(), is(1.0));
    Settings newSettings = Settings.settingsBuilder().put(CrateCircuitBreakerService.QUERY_CIRCUIT_BREAKER_LIMIT_SETTING, "100m").put(CrateCircuitBreakerService.QUERY_CIRCUIT_BREAKER_OVERHEAD_SETTING, 2.0).build();
    listeners[0].onRefreshSettings(newSettings);
    // expecting 4 times because registerBreaker() is also called from constructor of CrateCircuitBreakerService 3 times
    verify(esBreakerService, times(4)).registerBreaker(Matchers.any());
    breaker = breakerService.getBreaker(CrateCircuitBreakerService.QUERY);
    assertThat(breaker.getLimit(), is(104_857_600L));
    assertThat(breaker.getOverhead(), is(2.0));
    // updating with same settings should not register a new breaker
    listeners[0].onRefreshSettings(newSettings);
    verify(esBreakerService, times(4)).registerBreaker(Matchers.any());
}
Also used : CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) NodeSettingsService(org.elasticsearch.node.settings.NodeSettingsService) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 5 with HierarchyCircuitBreakerService

use of org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService in project crate by crate.

the class CrateCircuitBreakerServiceTest method testQueryCircuitBreakerDynamicSettings.

@Test
public void testQueryCircuitBreakerDynamicSettings() throws Exception {
    final NodeSettingsService.Listener[] listeners = new NodeSettingsService.Listener[1];
    NodeSettingsService settingsService = new NodeSettingsService(Settings.EMPTY) {

        @Override
        public void addListener(Listener listener) {
            listeners[0] = listener;
        }
    };
    CircuitBreakerService esBreakerService = new HierarchyCircuitBreakerService(Settings.EMPTY, settingsService);
    CrateCircuitBreakerService breakerService = new CrateCircuitBreakerService(Settings.EMPTY, settingsService, esBreakerService);
    Settings newSettings = Settings.settingsBuilder().put(CrateCircuitBreakerService.QUERY_CIRCUIT_BREAKER_OVERHEAD_SETTING, 2.0).build();
    listeners[0].onRefreshSettings(newSettings);
    CircuitBreaker breaker = breakerService.getBreaker(CrateCircuitBreakerService.QUERY);
    assertThat(breaker, notNullValue());
    assertThat(breaker, instanceOf(CircuitBreaker.class));
    assertThat(breaker.getOverhead(), is(2.0));
}
Also used : CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) NodeSettingsService(org.elasticsearch.node.settings.NodeSettingsService) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

HierarchyCircuitBreakerService (org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService)16 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)10 CircuitBreakerService (org.elasticsearch.indices.breaker.CircuitBreakerService)10 Settings (org.elasticsearch.common.settings.Settings)7 CircuitBreaker (org.elasticsearch.common.breaker.CircuitBreaker)6 Test (org.junit.Test)6 BreakerSettings (org.elasticsearch.indices.breaker.BreakerSettings)3 Before (org.junit.Before)3 CrateUnitTest (io.crate.test.integration.CrateUnitTest)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 CircuitBreakingException (org.elasticsearch.common.breaker.CircuitBreakingException)2 NodeSettingsService (org.elasticsearch.node.settings.NodeSettingsService)2 CrateCircuitBreakerService (io.crate.breaker.CrateCircuitBreakerService)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)1