Search in sources :

Example 1 with CircuitBreakerStats

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

the class CircuitBreakerServiceIT method testCustomCircuitBreakerRegistration.

public void testCustomCircuitBreakerRegistration() throws Exception {
    Iterable<CircuitBreakerService> serviceIter = internalCluster().getInstances(CircuitBreakerService.class);
    final String breakerName = "customBreaker";
    BreakerSettings breakerSettings = new BreakerSettings(breakerName, 8, 1.03);
    CircuitBreaker breaker = null;
    for (CircuitBreakerService s : serviceIter) {
        s.registerBreaker(breakerSettings);
        breaker = s.getBreaker(breakerSettings.getName());
    }
    if (breaker != null) {
        try {
            breaker.addEstimateBytesAndMaybeBreak(16, "test");
        } catch (CircuitBreakingException e) {
        // ignore, we forced a circuit break
        }
    }
    NodesStatsResponse stats = client().admin().cluster().prepareNodesStats().clear().setBreaker(true).get();
    int breaks = 0;
    for (NodeStats stat : stats.getNodes()) {
        CircuitBreakerStats breakerStats = stat.getBreaker().getStats(breakerName);
        breaks += breakerStats.getTrippedCount();
    }
    assertThat(breaks, greaterThanOrEqualTo(1));
}
Also used : NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) BreakerSettings(org.elasticsearch.indices.breaker.BreakerSettings) NoopCircuitBreaker(org.elasticsearch.common.breaker.NoopCircuitBreaker) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) CircuitBreakerStats(org.elasticsearch.indices.breaker.CircuitBreakerStats) CircuitBreakingException(org.elasticsearch.common.breaker.CircuitBreakingException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService)

Example 2 with CircuitBreakerStats

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

the class CircuitBreakerServiceIT method testMemoryBreaker.

public void testMemoryBreaker() throws Exception {
    if (noopBreakerUsed()) {
        logger.info("--> noop breakers used, skipping test");
        return;
    }
    assertAcked(prepareCreate("cb-test", 1, Settings.builder().put(SETTING_NUMBER_OF_REPLICAS, between(0, 1))).addMapping("type", "test", "type=text,fielddata=true"));
    final Client client = client();
    // 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("cb-test", "type", Long.toString(id)).setSource("test", "value" + id));
    }
    indexRandom(true, false, true, reqs);
    // 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("cb-test").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)

Example 3 with CircuitBreakerStats

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

the class NodeStatsTests method createNodeStats.

private static NodeStats createNodeStats() {
    DiscoveryNode node = new DiscoveryNode("test_node", buildNewFakeTransportAddress(), emptyMap(), emptySet(), VersionUtils.randomVersion(random()));
    OsStats osStats = null;
    if (frequently()) {
        double[] loadAverages = new double[3];
        for (int i = 0; i < 3; i++) {
            loadAverages[i] = randomBoolean() ? randomDouble() : -1;
        }
        osStats = new OsStats(System.currentTimeMillis(), new OsStats.Cpu(randomShort(), loadAverages), new OsStats.Mem(randomLong(), randomLong()), new OsStats.Swap(randomLong(), randomLong()), new OsStats.Cgroup(randomAsciiOfLength(8), randomNonNegativeLong(), randomAsciiOfLength(8), randomNonNegativeLong(), randomNonNegativeLong(), new OsStats.Cgroup.CpuStat(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong())));
    }
    ProcessStats processStats = frequently() ? new ProcessStats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), new ProcessStats.Cpu(randomShort(), randomNonNegativeLong()), new ProcessStats.Mem(randomNonNegativeLong())) : null;
    JvmStats jvmStats = null;
    if (frequently()) {
        int numMemoryPools = randomIntBetween(0, 10);
        List<JvmStats.MemoryPool> memoryPools = new ArrayList<>(numMemoryPools);
        for (int i = 0; i < numMemoryPools; i++) {
            memoryPools.add(new JvmStats.MemoryPool(randomAsciiOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
        }
        JvmStats.Threads threads = new JvmStats.Threads(randomIntBetween(1, 1000), randomIntBetween(1, 1000));
        int numGarbageCollectors = randomIntBetween(0, 10);
        JvmStats.GarbageCollector[] garbageCollectorsArray = new JvmStats.GarbageCollector[numGarbageCollectors];
        for (int i = 0; i < numGarbageCollectors; i++) {
            garbageCollectorsArray[i] = new JvmStats.GarbageCollector(randomAsciiOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong());
        }
        JvmStats.GarbageCollectors garbageCollectors = new JvmStats.GarbageCollectors(garbageCollectorsArray);
        int numBufferPools = randomIntBetween(0, 10);
        List<JvmStats.BufferPool> bufferPoolList = new ArrayList<>();
        for (int i = 0; i < numBufferPools; i++) {
            bufferPoolList.add(new JvmStats.BufferPool(randomAsciiOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
        }
        JvmStats.Classes classes = new JvmStats.Classes(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong());
        jvmStats = frequently() ? new JvmStats(randomNonNegativeLong(), randomNonNegativeLong(), new JvmStats.Mem(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), memoryPools), threads, garbageCollectors, randomBoolean() ? Collections.emptyList() : bufferPoolList, classes) : null;
    }
    ThreadPoolStats threadPoolStats = null;
    if (frequently()) {
        int numThreadPoolStats = randomIntBetween(0, 10);
        List<ThreadPoolStats.Stats> threadPoolStatsList = new ArrayList<>();
        for (int i = 0; i < numThreadPoolStats; i++) {
            threadPoolStatsList.add(new ThreadPoolStats.Stats(randomAsciiOfLengthBetween(3, 10), randomIntBetween(1, 1000), randomIntBetween(1, 1000), randomIntBetween(1, 1000), randomNonNegativeLong(), randomIntBetween(1, 1000), randomIntBetween(1, 1000)));
        }
        threadPoolStats = new ThreadPoolStats(threadPoolStatsList);
    }
    FsInfo fsInfo = null;
    if (frequently()) {
        int numDeviceStats = randomIntBetween(0, 10);
        FsInfo.DeviceStats[] deviceStatsArray = new FsInfo.DeviceStats[numDeviceStats];
        for (int i = 0; i < numDeviceStats; i++) {
            FsInfo.DeviceStats previousDeviceStats = randomBoolean() ? null : new FsInfo.DeviceStats(randomInt(), randomInt(), randomAsciiOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), null);
            deviceStatsArray[i] = new FsInfo.DeviceStats(randomInt(), randomInt(), randomAsciiOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), previousDeviceStats);
        }
        FsInfo.IoStats ioStats = new FsInfo.IoStats(deviceStatsArray);
        int numPaths = randomIntBetween(0, 10);
        FsInfo.Path[] paths = new FsInfo.Path[numPaths];
        for (int i = 0; i < numPaths; i++) {
            paths[i] = new FsInfo.Path(randomAsciiOfLengthBetween(3, 10), randomBoolean() ? randomAsciiOfLengthBetween(3, 10) : null, randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong());
        }
        fsInfo = new FsInfo(randomNonNegativeLong(), ioStats, paths);
    }
    TransportStats transportStats = frequently() ? new TransportStats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()) : null;
    HttpStats httpStats = frequently() ? new HttpStats(randomNonNegativeLong(), randomNonNegativeLong()) : null;
    AllCircuitBreakerStats allCircuitBreakerStats = null;
    if (frequently()) {
        int numCircuitBreakerStats = randomIntBetween(0, 10);
        CircuitBreakerStats[] circuitBreakerStatsArray = new CircuitBreakerStats[numCircuitBreakerStats];
        for (int i = 0; i < numCircuitBreakerStats; i++) {
            circuitBreakerStatsArray[i] = new CircuitBreakerStats(randomAsciiOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomDouble(), randomNonNegativeLong());
        }
        allCircuitBreakerStats = new AllCircuitBreakerStats(circuitBreakerStatsArray);
    }
    ScriptStats scriptStats = frequently() ? new ScriptStats(randomNonNegativeLong(), randomNonNegativeLong()) : null;
    DiscoveryStats discoveryStats = frequently() ? new DiscoveryStats(randomBoolean() ? new PendingClusterStateStats(randomInt(), randomInt(), randomInt()) : null) : null;
    IngestStats ingestStats = null;
    if (frequently()) {
        IngestStats.Stats totalStats = new IngestStats.Stats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong());
        int numStatsPerPipeline = randomIntBetween(0, 10);
        Map<String, IngestStats.Stats> statsPerPipeline = new HashMap<>();
        for (int i = 0; i < numStatsPerPipeline; i++) {
            statsPerPipeline.put(randomAsciiOfLengthBetween(3, 10), new IngestStats.Stats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
        }
        ingestStats = new IngestStats(totalStats, statsPerPipeline);
    }
    //TODO NodeIndicesStats are not tested here, way too complicated to create, also they need to be migrated to Writeable yet
    return new NodeStats(node, randomNonNegativeLong(), null, osStats, processStats, jvmStats, threadPoolStats, fsInfo, transportStats, httpStats, allCircuitBreakerStats, scriptStats, discoveryStats, ingestStats);
}
Also used : HashMap(java.util.HashMap) DiscoveryStats(org.elasticsearch.discovery.DiscoveryStats) ArrayList(java.util.ArrayList) ThreadPoolStats(org.elasticsearch.threadpool.ThreadPoolStats) TransportStats(org.elasticsearch.transport.TransportStats) CircuitBreakerStats(org.elasticsearch.indices.breaker.CircuitBreakerStats) AllCircuitBreakerStats(org.elasticsearch.indices.breaker.AllCircuitBreakerStats) ScriptStats(org.elasticsearch.script.ScriptStats) PendingClusterStateStats(org.elasticsearch.discovery.zen.PendingClusterStateStats) IngestStats(org.elasticsearch.ingest.IngestStats) PendingClusterStateStats(org.elasticsearch.discovery.zen.PendingClusterStateStats) IngestStats(org.elasticsearch.ingest.IngestStats) CircuitBreakerStats(org.elasticsearch.indices.breaker.CircuitBreakerStats) HttpStats(org.elasticsearch.http.HttpStats) AllCircuitBreakerStats(org.elasticsearch.indices.breaker.AllCircuitBreakerStats) ThreadPoolStats(org.elasticsearch.threadpool.ThreadPoolStats) DiscoveryStats(org.elasticsearch.discovery.DiscoveryStats) ScriptStats(org.elasticsearch.script.ScriptStats) OsStats(org.elasticsearch.monitor.os.OsStats) JvmStats(org.elasticsearch.monitor.jvm.JvmStats) ProcessStats(org.elasticsearch.monitor.process.ProcessStats) TransportStats(org.elasticsearch.transport.TransportStats) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) FsInfo(org.elasticsearch.monitor.fs.FsInfo) HttpStats(org.elasticsearch.http.HttpStats) JvmStats(org.elasticsearch.monitor.jvm.JvmStats) ProcessStats(org.elasticsearch.monitor.process.ProcessStats) OsStats(org.elasticsearch.monitor.os.OsStats) AllCircuitBreakerStats(org.elasticsearch.indices.breaker.AllCircuitBreakerStats)

Example 4 with CircuitBreakerStats

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

the class NodeStatsTests method testSerialization.

public void testSerialization() throws IOException {
    NodeStats nodeStats = createNodeStats();
    try (BytesStreamOutput out = new BytesStreamOutput()) {
        nodeStats.writeTo(out);
        try (StreamInput in = out.bytes().streamInput()) {
            NodeStats deserializedNodeStats = NodeStats.readNodeStats(in);
            assertEquals(nodeStats.getNode(), deserializedNodeStats.getNode());
            assertEquals(nodeStats.getTimestamp(), deserializedNodeStats.getTimestamp());
            if (nodeStats.getOs() == null) {
                assertNull(deserializedNodeStats.getOs());
            } else {
                assertEquals(nodeStats.getOs().getTimestamp(), deserializedNodeStats.getOs().getTimestamp());
                assertEquals(nodeStats.getOs().getSwap().getFree(), deserializedNodeStats.getOs().getSwap().getFree());
                assertEquals(nodeStats.getOs().getSwap().getTotal(), deserializedNodeStats.getOs().getSwap().getTotal());
                assertEquals(nodeStats.getOs().getSwap().getUsed(), deserializedNodeStats.getOs().getSwap().getUsed());
                assertEquals(nodeStats.getOs().getMem().getFree(), deserializedNodeStats.getOs().getMem().getFree());
                assertEquals(nodeStats.getOs().getMem().getTotal(), deserializedNodeStats.getOs().getMem().getTotal());
                assertEquals(nodeStats.getOs().getMem().getUsed(), deserializedNodeStats.getOs().getMem().getUsed());
                assertEquals(nodeStats.getOs().getMem().getFreePercent(), deserializedNodeStats.getOs().getMem().getFreePercent());
                assertEquals(nodeStats.getOs().getMem().getUsedPercent(), deserializedNodeStats.getOs().getMem().getUsedPercent());
                assertEquals(nodeStats.getOs().getCpu().getPercent(), deserializedNodeStats.getOs().getCpu().getPercent());
                assertEquals(nodeStats.getOs().getCgroup().getCpuAcctControlGroup(), deserializedNodeStats.getOs().getCgroup().getCpuAcctControlGroup());
                assertEquals(nodeStats.getOs().getCgroup().getCpuAcctUsageNanos(), deserializedNodeStats.getOs().getCgroup().getCpuAcctUsageNanos());
                assertEquals(nodeStats.getOs().getCgroup().getCpuControlGroup(), deserializedNodeStats.getOs().getCgroup().getCpuControlGroup());
                assertEquals(nodeStats.getOs().getCgroup().getCpuCfsPeriodMicros(), deserializedNodeStats.getOs().getCgroup().getCpuCfsPeriodMicros());
                assertEquals(nodeStats.getOs().getCgroup().getCpuCfsQuotaMicros(), deserializedNodeStats.getOs().getCgroup().getCpuCfsQuotaMicros());
                assertEquals(nodeStats.getOs().getCgroup().getCpuStat().getNumberOfElapsedPeriods(), deserializedNodeStats.getOs().getCgroup().getCpuStat().getNumberOfElapsedPeriods());
                assertEquals(nodeStats.getOs().getCgroup().getCpuStat().getNumberOfTimesThrottled(), deserializedNodeStats.getOs().getCgroup().getCpuStat().getNumberOfTimesThrottled());
                assertEquals(nodeStats.getOs().getCgroup().getCpuStat().getTimeThrottledNanos(), deserializedNodeStats.getOs().getCgroup().getCpuStat().getTimeThrottledNanos());
                assertArrayEquals(nodeStats.getOs().getCpu().getLoadAverage(), deserializedNodeStats.getOs().getCpu().getLoadAverage(), 0);
            }
            if (nodeStats.getProcess() == null) {
                assertNull(deserializedNodeStats.getProcess());
            } else {
                assertEquals(nodeStats.getProcess().getTimestamp(), deserializedNodeStats.getProcess().getTimestamp());
                assertEquals(nodeStats.getProcess().getCpu().getTotal(), deserializedNodeStats.getProcess().getCpu().getTotal());
                assertEquals(nodeStats.getProcess().getCpu().getPercent(), deserializedNodeStats.getProcess().getCpu().getPercent());
                assertEquals(nodeStats.getProcess().getMem().getTotalVirtual(), deserializedNodeStats.getProcess().getMem().getTotalVirtual());
                assertEquals(nodeStats.getProcess().getMaxFileDescriptors(), deserializedNodeStats.getProcess().getMaxFileDescriptors());
                assertEquals(nodeStats.getProcess().getOpenFileDescriptors(), deserializedNodeStats.getProcess().getOpenFileDescriptors());
            }
            JvmStats jvm = nodeStats.getJvm();
            JvmStats deserializedJvm = deserializedNodeStats.getJvm();
            if (jvm == null) {
                assertNull(deserializedJvm);
            } else {
                JvmStats.Mem mem = jvm.getMem();
                JvmStats.Mem deserializedMem = deserializedJvm.getMem();
                assertEquals(jvm.getTimestamp(), deserializedJvm.getTimestamp());
                assertEquals(mem.getHeapUsedPercent(), deserializedMem.getHeapUsedPercent());
                assertEquals(mem.getHeapUsed(), deserializedMem.getHeapUsed());
                assertEquals(mem.getHeapCommitted(), deserializedMem.getHeapCommitted());
                assertEquals(mem.getNonHeapCommitted(), deserializedMem.getNonHeapCommitted());
                assertEquals(mem.getNonHeapUsed(), deserializedMem.getNonHeapUsed());
                assertEquals(mem.getHeapMax(), deserializedMem.getHeapMax());
                JvmStats.Classes classes = jvm.getClasses();
                assertEquals(classes.getLoadedClassCount(), deserializedJvm.getClasses().getLoadedClassCount());
                assertEquals(classes.getTotalLoadedClassCount(), deserializedJvm.getClasses().getTotalLoadedClassCount());
                assertEquals(classes.getUnloadedClassCount(), deserializedJvm.getClasses().getUnloadedClassCount());
                assertEquals(jvm.getGc().getCollectors().length, deserializedJvm.getGc().getCollectors().length);
                for (int i = 0; i < jvm.getGc().getCollectors().length; i++) {
                    JvmStats.GarbageCollector garbageCollector = jvm.getGc().getCollectors()[i];
                    JvmStats.GarbageCollector deserializedGarbageCollector = deserializedJvm.getGc().getCollectors()[i];
                    assertEquals(garbageCollector.getName(), deserializedGarbageCollector.getName());
                    assertEquals(garbageCollector.getCollectionCount(), deserializedGarbageCollector.getCollectionCount());
                    assertEquals(garbageCollector.getCollectionTime(), deserializedGarbageCollector.getCollectionTime());
                }
                assertEquals(jvm.getThreads().getCount(), deserializedJvm.getThreads().getCount());
                assertEquals(jvm.getThreads().getPeakCount(), deserializedJvm.getThreads().getPeakCount());
                assertEquals(jvm.getUptime(), deserializedJvm.getUptime());
                if (jvm.getBufferPools() == null) {
                    assertNull(deserializedJvm.getBufferPools());
                } else {
                    assertEquals(jvm.getBufferPools().size(), deserializedJvm.getBufferPools().size());
                    for (int i = 0; i < jvm.getBufferPools().size(); i++) {
                        JvmStats.BufferPool bufferPool = jvm.getBufferPools().get(i);
                        JvmStats.BufferPool deserializedBufferPool = deserializedJvm.getBufferPools().get(i);
                        assertEquals(bufferPool.getName(), deserializedBufferPool.getName());
                        assertEquals(bufferPool.getCount(), deserializedBufferPool.getCount());
                        assertEquals(bufferPool.getTotalCapacity(), deserializedBufferPool.getTotalCapacity());
                        assertEquals(bufferPool.getUsed(), deserializedBufferPool.getUsed());
                    }
                }
            }
            if (nodeStats.getThreadPool() == null) {
                assertNull(deserializedNodeStats.getThreadPool());
            } else {
                Iterator<ThreadPoolStats.Stats> threadPoolIterator = nodeStats.getThreadPool().iterator();
                Iterator<ThreadPoolStats.Stats> deserializedThreadPoolIterator = deserializedNodeStats.getThreadPool().iterator();
                while (threadPoolIterator.hasNext()) {
                    ThreadPoolStats.Stats stats = threadPoolIterator.next();
                    ThreadPoolStats.Stats deserializedStats = deserializedThreadPoolIterator.next();
                    assertEquals(stats.getName(), deserializedStats.getName());
                    assertEquals(stats.getThreads(), deserializedStats.getThreads());
                    assertEquals(stats.getActive(), deserializedStats.getActive());
                    assertEquals(stats.getLargest(), deserializedStats.getLargest());
                    assertEquals(stats.getCompleted(), deserializedStats.getCompleted());
                    assertEquals(stats.getQueue(), deserializedStats.getQueue());
                    assertEquals(stats.getRejected(), deserializedStats.getRejected());
                }
            }
            FsInfo fs = nodeStats.getFs();
            FsInfo deserializedFs = deserializedNodeStats.getFs();
            if (fs == null) {
                assertNull(deserializedFs);
            } else {
                assertEquals(fs.getTimestamp(), deserializedFs.getTimestamp());
                assertEquals(fs.getTotal().getAvailable(), deserializedFs.getTotal().getAvailable());
                assertEquals(fs.getTotal().getTotal(), deserializedFs.getTotal().getTotal());
                assertEquals(fs.getTotal().getFree(), deserializedFs.getTotal().getFree());
                assertEquals(fs.getTotal().getMount(), deserializedFs.getTotal().getMount());
                assertEquals(fs.getTotal().getPath(), deserializedFs.getTotal().getPath());
                assertEquals(fs.getTotal().getSpins(), deserializedFs.getTotal().getSpins());
                assertEquals(fs.getTotal().getType(), deserializedFs.getTotal().getType());
                FsInfo.IoStats ioStats = fs.getIoStats();
                FsInfo.IoStats deserializedIoStats = deserializedFs.getIoStats();
                assertEquals(ioStats.getTotalOperations(), deserializedIoStats.getTotalOperations());
                assertEquals(ioStats.getTotalReadKilobytes(), deserializedIoStats.getTotalReadKilobytes());
                assertEquals(ioStats.getTotalReadOperations(), deserializedIoStats.getTotalReadOperations());
                assertEquals(ioStats.getTotalWriteKilobytes(), deserializedIoStats.getTotalWriteKilobytes());
                assertEquals(ioStats.getTotalWriteOperations(), deserializedIoStats.getTotalWriteOperations());
                assertEquals(ioStats.getDevicesStats().length, deserializedIoStats.getDevicesStats().length);
                for (int i = 0; i < ioStats.getDevicesStats().length; i++) {
                    FsInfo.DeviceStats deviceStats = ioStats.getDevicesStats()[i];
                    FsInfo.DeviceStats deserializedDeviceStats = deserializedIoStats.getDevicesStats()[i];
                    assertEquals(deviceStats.operations(), deserializedDeviceStats.operations());
                    assertEquals(deviceStats.readKilobytes(), deserializedDeviceStats.readKilobytes());
                    assertEquals(deviceStats.readOperations(), deserializedDeviceStats.readOperations());
                    assertEquals(deviceStats.writeKilobytes(), deserializedDeviceStats.writeKilobytes());
                    assertEquals(deviceStats.writeOperations(), deserializedDeviceStats.writeOperations());
                }
            }
            if (nodeStats.getTransport() == null) {
                assertNull(deserializedNodeStats.getTransport());
            } else {
                assertEquals(nodeStats.getTransport().getRxCount(), deserializedNodeStats.getTransport().getRxCount());
                assertEquals(nodeStats.getTransport().getRxSize(), deserializedNodeStats.getTransport().getRxSize());
                assertEquals(nodeStats.getTransport().getServerOpen(), deserializedNodeStats.getTransport().getServerOpen());
                assertEquals(nodeStats.getTransport().getTxCount(), deserializedNodeStats.getTransport().getTxCount());
                assertEquals(nodeStats.getTransport().getTxSize(), deserializedNodeStats.getTransport().getTxSize());
            }
            if (nodeStats.getHttp() == null) {
                assertNull(deserializedNodeStats.getHttp());
            } else {
                assertEquals(nodeStats.getHttp().getServerOpen(), deserializedNodeStats.getHttp().getServerOpen());
                assertEquals(nodeStats.getHttp().getTotalOpen(), deserializedNodeStats.getHttp().getTotalOpen());
            }
            if (nodeStats.getBreaker() == null) {
                assertNull(deserializedNodeStats.getBreaker());
            } else {
                assertEquals(nodeStats.getBreaker().getAllStats().length, deserializedNodeStats.getBreaker().getAllStats().length);
                for (int i = 0; i < nodeStats.getBreaker().getAllStats().length; i++) {
                    CircuitBreakerStats circuitBreakerStats = nodeStats.getBreaker().getAllStats()[i];
                    CircuitBreakerStats deserializedCircuitBreakerStats = deserializedNodeStats.getBreaker().getAllStats()[i];
                    assertEquals(circuitBreakerStats.getEstimated(), deserializedCircuitBreakerStats.getEstimated());
                    assertEquals(circuitBreakerStats.getLimit(), deserializedCircuitBreakerStats.getLimit());
                    assertEquals(circuitBreakerStats.getName(), deserializedCircuitBreakerStats.getName());
                    assertEquals(circuitBreakerStats.getOverhead(), deserializedCircuitBreakerStats.getOverhead(), 0);
                    assertEquals(circuitBreakerStats.getTrippedCount(), deserializedCircuitBreakerStats.getTrippedCount(), 0);
                }
            }
            ScriptStats scriptStats = nodeStats.getScriptStats();
            if (scriptStats == null) {
                assertNull(deserializedNodeStats.getScriptStats());
            } else {
                assertEquals(scriptStats.getCacheEvictions(), deserializedNodeStats.getScriptStats().getCacheEvictions());
                assertEquals(scriptStats.getCompilations(), deserializedNodeStats.getScriptStats().getCompilations());
            }
            DiscoveryStats discoveryStats = nodeStats.getDiscoveryStats();
            DiscoveryStats deserializedDiscoveryStats = deserializedNodeStats.getDiscoveryStats();
            if (discoveryStats == null) {
                assertNull(deserializedDiscoveryStats);
            } else {
                PendingClusterStateStats queueStats = discoveryStats.getQueueStats();
                if (queueStats == null) {
                    assertNull(deserializedDiscoveryStats.getQueueStats());
                } else {
                    assertEquals(queueStats.getCommitted(), deserializedDiscoveryStats.getQueueStats().getCommitted());
                    assertEquals(queueStats.getTotal(), deserializedDiscoveryStats.getQueueStats().getTotal());
                    assertEquals(queueStats.getPending(), deserializedDiscoveryStats.getQueueStats().getPending());
                }
            }
            IngestStats ingestStats = nodeStats.getIngestStats();
            IngestStats deserializedIngestStats = deserializedNodeStats.getIngestStats();
            if (ingestStats == null) {
                assertNull(deserializedIngestStats);
            } else {
                IngestStats.Stats totalStats = ingestStats.getTotalStats();
                assertEquals(totalStats.getIngestCount(), deserializedIngestStats.getTotalStats().getIngestCount());
                assertEquals(totalStats.getIngestCurrent(), deserializedIngestStats.getTotalStats().getIngestCurrent());
                assertEquals(totalStats.getIngestFailedCount(), deserializedIngestStats.getTotalStats().getIngestFailedCount());
                assertEquals(totalStats.getIngestTimeInMillis(), deserializedIngestStats.getTotalStats().getIngestTimeInMillis());
                assertEquals(ingestStats.getStatsPerPipeline().size(), deserializedIngestStats.getStatsPerPipeline().size());
                for (Map.Entry<String, IngestStats.Stats> entry : ingestStats.getStatsPerPipeline().entrySet()) {
                    IngestStats.Stats stats = entry.getValue();
                    IngestStats.Stats deserializedStats = deserializedIngestStats.getStatsPerPipeline().get(entry.getKey());
                    assertEquals(stats.getIngestFailedCount(), deserializedStats.getIngestFailedCount());
                    assertEquals(stats.getIngestTimeInMillis(), deserializedStats.getIngestTimeInMillis());
                    assertEquals(stats.getIngestCurrent(), deserializedStats.getIngestCurrent());
                    assertEquals(stats.getIngestCount(), deserializedStats.getIngestCount());
                }
            }
        }
    }
}
Also used : DiscoveryStats(org.elasticsearch.discovery.DiscoveryStats) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) FsInfo(org.elasticsearch.monitor.fs.FsInfo) ThreadPoolStats(org.elasticsearch.threadpool.ThreadPoolStats) CircuitBreakerStats(org.elasticsearch.indices.breaker.CircuitBreakerStats) AllCircuitBreakerStats(org.elasticsearch.indices.breaker.AllCircuitBreakerStats) JvmStats(org.elasticsearch.monitor.jvm.JvmStats) ScriptStats(org.elasticsearch.script.ScriptStats) PendingClusterStateStats(org.elasticsearch.discovery.zen.PendingClusterStateStats) IngestStats(org.elasticsearch.ingest.IngestStats) StreamInput(org.elasticsearch.common.io.stream.StreamInput) PendingClusterStateStats(org.elasticsearch.discovery.zen.PendingClusterStateStats) IngestStats(org.elasticsearch.ingest.IngestStats) CircuitBreakerStats(org.elasticsearch.indices.breaker.CircuitBreakerStats) HttpStats(org.elasticsearch.http.HttpStats) AllCircuitBreakerStats(org.elasticsearch.indices.breaker.AllCircuitBreakerStats) ThreadPoolStats(org.elasticsearch.threadpool.ThreadPoolStats) DiscoveryStats(org.elasticsearch.discovery.DiscoveryStats) ScriptStats(org.elasticsearch.script.ScriptStats) OsStats(org.elasticsearch.monitor.os.OsStats) JvmStats(org.elasticsearch.monitor.jvm.JvmStats) ProcessStats(org.elasticsearch.monitor.process.ProcessStats) TransportStats(org.elasticsearch.transport.TransportStats) HashMap(java.util.HashMap) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap)

Example 5 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