Search in sources :

Example 6 with CircuitBreakerStats

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

the class CircuitBreakerServiceIT method testRamAccountingTermsEnum.

public void testRamAccountingTermsEnum() throws Exception {
    if (noopBreakerUsed()) {
        logger.info("--> noop breakers used, skipping test");
        return;
    }
    final Client client = client();
    // Create an index where the mappings have a field data filter
    assertAcked(prepareCreate("ramtest").setSource("{\"mappings\": {\"type\": {\"properties\": {\"test\": " + "{\"type\": \"text\",\"fielddata\": true,\"fielddata_frequency_filter\": {\"max\": 10000}}}}}}", XContentType.JSON));
    ensureGreen("ramtest");
    // index some different terms so we have some field data for loading
    int docCount = scaledRandomIntBetween(300, 1000);
    List<IndexRequestBuilder> reqs = new ArrayList<>();
    for (long id = 0; id < docCount; id++) {
        reqs.add(client.prepareIndex("ramtest", "type", Long.toString(id)).setSource("test", "value" + id));
    }
    indexRandom(true, false, true, reqs);
    // execute a search that loads field data (sorting on the "test" field)
    client.prepareSearch("ramtest").setQuery(matchAllQuery()).addSort("test", SortOrder.DESC).get();
    // clear field data cache (thus setting the loaded field data back to 0)
    clearFieldData();
    // Update circuit breaker settings
    Settings settings = Settings.builder().put(HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), "100b").put(HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_OVERHEAD_SETTING.getKey(), 1.05).build();
    assertAcked(client.admin().cluster().prepareUpdateSettings().setTransientSettings(settings));
    // execute a search that loads field data (sorting on the "test" field)
    // again, this time it should trip the breaker
    SearchRequestBuilder searchRequest = client.prepareSearch("ramtest").setQuery(matchAllQuery()).addSort("test", SortOrder.DESC);
    String errMsg = "Data too large, data for [test] would be";
    assertFailures(searchRequest, RestStatus.INTERNAL_SERVER_ERROR, containsString(errMsg));
    errMsg = "which is larger than the limit of [100/100b]";
    assertFailures(searchRequest, RestStatus.INTERNAL_SERVER_ERROR, containsString(errMsg));
    NodesStatsResponse stats = client.admin().cluster().prepareNodesStats().setBreaker(true).get();
    int breaks = 0;
    for (NodeStats stat : stats.getNodes()) {
        CircuitBreakerStats breakerStats = stat.getBreaker().getStats(CircuitBreaker.FIELDDATA);
        breaks += breakerStats.getTrippedCount();
    }
    assertThat(breaks, greaterThanOrEqualTo(1));
}
Also used : IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) CircuitBreakerStats(org.elasticsearch.indices.breaker.CircuitBreakerStats) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Client(org.elasticsearch.client.Client) Settings(org.elasticsearch.common.settings.Settings) BreakerSettings(org.elasticsearch.indices.breaker.BreakerSettings)

Aggregations

CircuitBreakerStats (org.elasticsearch.indices.breaker.CircuitBreakerStats)6 ArrayList (java.util.ArrayList)3 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)3 NodesStatsResponse (org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse)3 BreakerSettings (org.elasticsearch.indices.breaker.BreakerSettings)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 HashMap (java.util.HashMap)2 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)2 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)2 Client (org.elasticsearch.client.Client)2 Settings (org.elasticsearch.common.settings.Settings)2 DiscoveryStats (org.elasticsearch.discovery.DiscoveryStats)2 PendingClusterStateStats (org.elasticsearch.discovery.zen.PendingClusterStateStats)2 HttpStats (org.elasticsearch.http.HttpStats)2 AllCircuitBreakerStats (org.elasticsearch.indices.breaker.AllCircuitBreakerStats)2 CircuitBreakerService (org.elasticsearch.indices.breaker.CircuitBreakerService)2 HierarchyCircuitBreakerService (org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService)2 IngestStats (org.elasticsearch.ingest.IngestStats)2 FsInfo (org.elasticsearch.monitor.fs.FsInfo)2 JvmStats (org.elasticsearch.monitor.jvm.JvmStats)2