Search in sources :

Example 6 with HystrixCollapserKey

use of com.netflix.hystrix.HystrixCollapserKey in project Hystrix by Netflix.

the class CumulativeCollapserEventCounterStreamTest method testEmptyStreamProducesZeros.

@Test
public void testEmptyStreamProducesZeros() {
    HystrixCollapserKey key = HystrixCollapserKey.Factory.asKey("CumulativeCollapser-A");
    stream = CumulativeCollapserEventCounterStream.getInstance(key, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(getSubscriber(latch));
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
    assertEquals(HystrixEventType.Collapser.values().length, stream.getLatest().length);
    assertEquals(0, stream.getLatest(HystrixEventType.Collapser.ADDED_TO_BATCH));
    assertEquals(0, stream.getLatest(HystrixEventType.Collapser.BATCH_EXECUTED));
    assertEquals(0, stream.getLatest(HystrixEventType.Collapser.RESPONSE_FROM_CACHE));
}
Also used : HystrixCollapserKey(com.netflix.hystrix.HystrixCollapserKey) CountDownLatch(java.util.concurrent.CountDownLatch) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Example 7 with HystrixCollapserKey

use of com.netflix.hystrix.HystrixCollapserKey in project Hystrix by Netflix.

the class RollingCollapserEventCounterStreamTest method testCollapsed.

@Test
public void testCollapsed() {
    HystrixCollapserKey key = HystrixCollapserKey.Factory.asKey("RollingCollapser-B");
    stream = RollingCollapserEventCounterStream.getInstance(key, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(getSubscriber(latch));
    for (int i = 0; i < 3; i++) {
        CommandStreamTest.Collapser.from(key, i).observe();
    }
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    assertEquals(HystrixEventType.Collapser.values().length, stream.getLatest().length);
    long[] expected = new long[HystrixEventType.Collapser.values().length];
    expected[HystrixEventType.Collapser.BATCH_EXECUTED.ordinal()] = 1;
    expected[HystrixEventType.Collapser.ADDED_TO_BATCH.ordinal()] = 3;
    System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
    assertArrayEquals(expected, stream.getLatest());
}
Also used : HystrixCollapserKey(com.netflix.hystrix.HystrixCollapserKey) CountDownLatch(java.util.concurrent.CountDownLatch) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Example 8 with HystrixCollapserKey

use of com.netflix.hystrix.HystrixCollapserKey in project Hystrix by Netflix.

the class RollingCollapserEventCounterStreamTest method testCollapsedAndResponseFromCache.

@Test
public void testCollapsedAndResponseFromCache() {
    HystrixCollapserKey key = HystrixCollapserKey.Factory.asKey("RollingCollapser-C");
    stream = RollingCollapserEventCounterStream.getInstance(key, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(getSubscriber(latch));
    for (int i = 0; i < 3; i++) {
        CommandStreamTest.Collapser.from(key, i).observe();
        //same arg - should get a response from cache
        CommandStreamTest.Collapser.from(key, i).observe();
        //same arg - should get a response from cache
        CommandStreamTest.Collapser.from(key, i).observe();
    }
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    assertEquals(HystrixEventType.Collapser.values().length, stream.getLatest().length);
    long[] expected = new long[HystrixEventType.Collapser.values().length];
    expected[HystrixEventType.Collapser.BATCH_EXECUTED.ordinal()] = 1;
    expected[HystrixEventType.Collapser.ADDED_TO_BATCH.ordinal()] = 3;
    expected[HystrixEventType.Collapser.RESPONSE_FROM_CACHE.ordinal()] = 6;
    System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
    assertArrayEquals(expected, stream.getLatest());
}
Also used : HystrixCollapserKey(com.netflix.hystrix.HystrixCollapserKey) CountDownLatch(java.util.concurrent.CountDownLatch) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Example 9 with HystrixCollapserKey

use of com.netflix.hystrix.HystrixCollapserKey in project Hystrix by Netflix.

the class SerialHystrixDashboardData method writeCollapserMetrics.

private static void writeCollapserMetrics(final HystrixCollapserMetrics collapserMetrics, JsonGenerator json) throws IOException {
    HystrixCollapserKey key = collapserMetrics.getCollapserKey();
    json.writeStartObject();
    json.writeStringField("type", "HystrixCollapser");
    json.writeStringField("name", key.name());
    json.writeNumberField("currentTime", System.currentTimeMillis());
    safelyWriteNumberField(json, "rollingCountRequestsBatched", new Func0<Long>() {

        @Override
        public Long call() {
            return collapserMetrics.getRollingCount(HystrixEventType.Collapser.ADDED_TO_BATCH);
        }
    });
    safelyWriteNumberField(json, "rollingCountBatches", new Func0<Long>() {

        @Override
        public Long call() {
            return collapserMetrics.getRollingCount(HystrixEventType.Collapser.BATCH_EXECUTED);
        }
    });
    safelyWriteNumberField(json, "rollingCountResponsesFromCache", new Func0<Long>() {

        @Override
        public Long call() {
            return collapserMetrics.getRollingCount(HystrixEventType.Collapser.RESPONSE_FROM_CACHE);
        }
    });
    // batch size percentiles
    json.writeNumberField("batchSize_mean", collapserMetrics.getBatchSizeMean());
    json.writeObjectFieldStart("batchSize");
    json.writeNumberField("25", collapserMetrics.getBatchSizePercentile(25));
    json.writeNumberField("50", collapserMetrics.getBatchSizePercentile(50));
    json.writeNumberField("75", collapserMetrics.getBatchSizePercentile(75));
    json.writeNumberField("90", collapserMetrics.getBatchSizePercentile(90));
    json.writeNumberField("95", collapserMetrics.getBatchSizePercentile(95));
    json.writeNumberField("99", collapserMetrics.getBatchSizePercentile(99));
    json.writeNumberField("99.5", collapserMetrics.getBatchSizePercentile(99.5));
    json.writeNumberField("100", collapserMetrics.getBatchSizePercentile(100));
    json.writeEndObject();
    // shard size percentiles (commented-out for now)
    //json.writeNumberField("shardSize_mean", collapserMetrics.getShardSizeMean());
    //json.writeObjectFieldStart("shardSize");
    //json.writeNumberField("25", collapserMetrics.getShardSizePercentile(25));
    //json.writeNumberField("50", collapserMetrics.getShardSizePercentile(50));
    //json.writeNumberField("75", collapserMetrics.getShardSizePercentile(75));
    //json.writeNumberField("90", collapserMetrics.getShardSizePercentile(90));
    //json.writeNumberField("95", collapserMetrics.getShardSizePercentile(95));
    //json.writeNumberField("99", collapserMetrics.getShardSizePercentile(99));
    //json.writeNumberField("99.5", collapserMetrics.getShardSizePercentile(99.5));
    //json.writeNumberField("100", collapserMetrics.getShardSizePercentile(100));
    //json.writeEndObject();
    //json.writeNumberField("propertyValue_metricsRollingStatisticalWindowInMilliseconds", collapserMetrics.getProperties().metricsRollingStatisticalWindowInMilliseconds().get());
    json.writeBooleanField("propertyValue_requestCacheEnabled", collapserMetrics.getProperties().requestCacheEnabled().get());
    json.writeNumberField("propertyValue_maxRequestsInBatch", collapserMetrics.getProperties().maxRequestsInBatch().get());
    json.writeNumberField("propertyValue_timerDelayInMilliseconds", collapserMetrics.getProperties().timerDelayInMilliseconds().get());
    // this will get summed across all instances in a cluster
    json.writeNumberField("reportingHosts", 1);
    json.writeEndObject();
}
Also used : HystrixCollapserKey(com.netflix.hystrix.HystrixCollapserKey)

Example 10 with HystrixCollapserKey

use of com.netflix.hystrix.HystrixCollapserKey in project Hystrix by Netflix.

the class RollingCollapserBatchSizeDistributionStreamTest method testBatchesAgeOut.

//by doing a take(30), all metrics should fall out of window and we should observe an empty histogram
@Test
public void testBatchesAgeOut() {
    HystrixCollapserKey key = HystrixCollapserKey.Factory.asKey("Collapser-Batch-Size-B");
    stream = RollingCollapserBatchSizeDistributionStream.getInstance(key, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(30).subscribe(new Subscriber<CachedValuesHistogram>() {

        @Override
        public void onCompleted() {
            latch.countDown();
        }

        @Override
        public void onError(Throwable e) {
            fail(e.getMessage());
        }

        @Override
        public void onNext(CachedValuesHistogram distribution) {
            System.out.println("OnNext @ " + System.currentTimeMillis());
        }
    });
    Collapser.from(key, 1).observe();
    Collapser.from(key, 2).observe();
    Collapser.from(key, 3).observe();
    try {
        Thread.sleep(200);
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    Collapser.from(key, 4).observe();
    try {
        Thread.sleep(200);
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    Collapser.from(key, 5).observe();
    Collapser.from(key, 6).observe();
    Collapser.from(key, 7).observe();
    Collapser.from(key, 8).observe();
    Collapser.from(key, 9).observe();
    try {
        Thread.sleep(200);
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    Collapser.from(key, 10).observe();
    Collapser.from(key, 11).observe();
    Collapser.from(key, 12).observe();
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    assertEquals(0, stream.getLatest().getTotalCount());
    assertEquals(0, stream.getLatestMean());
}
Also used : CachedValuesHistogram(com.netflix.hystrix.metric.CachedValuesHistogram) HystrixCollapserKey(com.netflix.hystrix.HystrixCollapserKey) CountDownLatch(java.util.concurrent.CountDownLatch) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Aggregations

HystrixCollapserKey (com.netflix.hystrix.HystrixCollapserKey)15 CommandStreamTest (com.netflix.hystrix.metric.CommandStreamTest)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 Test (org.junit.Test)11 CachedValuesHistogram (com.netflix.hystrix.metric.CachedValuesHistogram)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 HystrixCommandKey (com.netflix.hystrix.HystrixCommandKey)2 HystrixThreadPoolKey (com.netflix.hystrix.HystrixThreadPoolKey)2 HystrixCollapserConfiguration (com.netflix.hystrix.config.HystrixCollapserConfiguration)2 HystrixCommandConfiguration (com.netflix.hystrix.config.HystrixCommandConfiguration)2 HystrixThreadPoolConfiguration (com.netflix.hystrix.config.HystrixThreadPoolConfiguration)2 StringWriter (java.io.StringWriter)2 Map (java.util.Map)2 IOException (java.io.IOException)1