Search in sources :

Example 76 with HystrixCommandKey

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

the class HealthCountsStreamTest method testSingleSuccess.

@Test
public void testSingleSuccess() {
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-Health-B");
    stream = HealthCountsStream.getInstance(key, 10, 100);
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(getSubscriber(latch));
    CommandStreamTest.Command cmd = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.SUCCESS, 20);
    cmd.observe();
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
    assertEquals(0L, stream.getLatest().getErrorCount());
    assertEquals(1L, stream.getLatest().getTotalRequests());
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) CountDownLatch(java.util.concurrent.CountDownLatch) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Example 77 with HystrixCommandKey

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

the class HealthCountsStreamTest method testShortCircuited.

@Test
public void testShortCircuited() {
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-Health-G");
    stream = HealthCountsStream.getInstance(key, 10, 100);
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(getSubscriber(latch));
    //3 failures in a row will trip circuit.  let bucket roll once then submit 2 requests.
    //should see 3 FAILUREs and 2 SHORT_CIRCUITs and then 5 FALLBACK_SUCCESSes
    CommandStreamTest.Command failure1 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.FAILURE, 20);
    CommandStreamTest.Command failure2 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.FAILURE, 20);
    CommandStreamTest.Command failure3 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.FAILURE, 20);
    CommandStreamTest.Command shortCircuit1 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.SUCCESS);
    CommandStreamTest.Command shortCircuit2 = CommandStreamTest.Command.from(groupKey, key, HystrixEventType.SUCCESS);
    failure1.observe();
    failure2.observe();
    failure3.observe();
    try {
        Thread.sleep(500);
    } catch (InterruptedException ie) {
        fail(ie.getMessage());
    }
    shortCircuit1.observe();
    shortCircuit2.observe();
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    assertTrue(shortCircuit1.isResponseShortCircuited());
    assertTrue(shortCircuit2.isResponseShortCircuited());
    System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
    //should only see failures here, not SHORT-CIRCUITS
    assertEquals(3L, stream.getLatest().getErrorCount());
    assertEquals(3L, stream.getLatest().getTotalRequests());
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) CountDownLatch(java.util.concurrent.CountDownLatch) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Example 78 with HystrixCommandKey

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

the class SerialHystrixConfiguration method serializeConfiguration.

private static void serializeConfiguration(HystrixConfiguration config, JsonGenerator json) {
    try {
        json.writeStartObject();
        json.writeStringField("type", "HystrixConfig");
        json.writeObjectFieldStart("commands");
        for (Map.Entry<HystrixCommandKey, HystrixCommandConfiguration> entry : config.getCommandConfig().entrySet()) {
            final HystrixCommandKey key = entry.getKey();
            final HystrixCommandConfiguration commandConfig = entry.getValue();
            writeCommandConfigJson(json, key, commandConfig);
        }
        json.writeEndObject();
        json.writeObjectFieldStart("threadpools");
        for (Map.Entry<HystrixThreadPoolKey, HystrixThreadPoolConfiguration> entry : config.getThreadPoolConfig().entrySet()) {
            final HystrixThreadPoolKey threadPoolKey = entry.getKey();
            final HystrixThreadPoolConfiguration threadPoolConfig = entry.getValue();
            writeThreadPoolConfigJson(json, threadPoolKey, threadPoolConfig);
        }
        json.writeEndObject();
        json.writeObjectFieldStart("collapsers");
        for (Map.Entry<HystrixCollapserKey, HystrixCollapserConfiguration> entry : config.getCollapserConfig().entrySet()) {
            final HystrixCollapserKey collapserKey = entry.getKey();
            final HystrixCollapserConfiguration collapserConfig = entry.getValue();
            writeCollapserConfigJson(json, collapserKey, collapserConfig);
        }
        json.writeEndObject();
        json.writeEndObject();
        json.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) HystrixCommandConfiguration(com.netflix.hystrix.config.HystrixCommandConfiguration) HystrixCollapserKey(com.netflix.hystrix.HystrixCollapserKey) HystrixThreadPoolKey(com.netflix.hystrix.HystrixThreadPoolKey) Map(java.util.Map) HystrixCollapserConfiguration(com.netflix.hystrix.config.HystrixCollapserConfiguration) IOException(java.io.IOException) HystrixThreadPoolConfiguration(com.netflix.hystrix.config.HystrixThreadPoolConfiguration)

Example 79 with HystrixCommandKey

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

the class SerialHystrixDashboardData method writeCommandMetrics.

private static void writeCommandMetrics(final HystrixCommandMetrics commandMetrics, JsonGenerator json) throws IOException {
    HystrixCommandKey key = commandMetrics.getCommandKey();
    HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(key);
    json.writeStartObject();
    json.writeStringField("type", "HystrixCommand");
    json.writeStringField("name", key.name());
    json.writeStringField("group", commandMetrics.getCommandGroup().name());
    json.writeNumberField("currentTime", System.currentTimeMillis());
    // circuit breaker
    if (circuitBreaker == null) {
        // circuit breaker is disabled and thus never open
        json.writeBooleanField("isCircuitBreakerOpen", false);
    } else {
        json.writeBooleanField("isCircuitBreakerOpen", circuitBreaker.isOpen());
    }
    HystrixCommandMetrics.HealthCounts healthCounts = commandMetrics.getHealthCounts();
    json.writeNumberField("errorPercentage", healthCounts.getErrorPercentage());
    json.writeNumberField("errorCount", healthCounts.getErrorCount());
    json.writeNumberField("requestCount", healthCounts.getTotalRequests());
    // rolling counters
    safelyWriteNumberField(json, "rollingCountBadRequests", new Func0<Long>() {

        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.BAD_REQUEST);
        }
    });
    safelyWriteNumberField(json, "rollingCountCollapsedRequests", new Func0<Long>() {

        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.COLLAPSED);
        }
    });
    safelyWriteNumberField(json, "rollingCountEmit", new Func0<Long>() {

        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.EMIT);
        }
    });
    safelyWriteNumberField(json, "rollingCountExceptionsThrown", new Func0<Long>() {

        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.EXCEPTION_THROWN);
        }
    });
    safelyWriteNumberField(json, "rollingCountFailure", new Func0<Long>() {

        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.FAILURE);
        }
    });
    safelyWriteNumberField(json, "rollingCountFallbackEmit", new Func0<Long>() {

        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.FALLBACK_EMIT);
        }
    });
    safelyWriteNumberField(json, "rollingCountFallbackFailure", new Func0<Long>() {

        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.FALLBACK_FAILURE);
        }
    });
    safelyWriteNumberField(json, "rollingCountFallbackMissing", new Func0<Long>() {

        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.FALLBACK_MISSING);
        }
    });
    safelyWriteNumberField(json, "rollingCountFallbackRejection", new Func0<Long>() {

        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.FALLBACK_REJECTION);
        }
    });
    safelyWriteNumberField(json, "rollingCountFallbackSuccess", new Func0<Long>() {

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

        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.RESPONSE_FROM_CACHE);
        }
    });
    safelyWriteNumberField(json, "rollingCountSemaphoreRejected", new Func0<Long>() {

        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.SEMAPHORE_REJECTED);
        }
    });
    safelyWriteNumberField(json, "rollingCountShortCircuited", new Func0<Long>() {

        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.SHORT_CIRCUITED);
        }
    });
    safelyWriteNumberField(json, "rollingCountSuccess", new Func0<Long>() {

        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.SUCCESS);
        }
    });
    safelyWriteNumberField(json, "rollingCountThreadPoolRejected", new Func0<Long>() {

        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.THREAD_POOL_REJECTED);
        }
    });
    safelyWriteNumberField(json, "rollingCountTimeout", new Func0<Long>() {

        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.TIMEOUT);
        }
    });
    json.writeNumberField("currentConcurrentExecutionCount", commandMetrics.getCurrentConcurrentExecutionCount());
    json.writeNumberField("rollingMaxConcurrentExecutionCount", commandMetrics.getRollingMaxConcurrentExecutions());
    // latency percentiles
    json.writeNumberField("latencyExecute_mean", commandMetrics.getExecutionTimeMean());
    json.writeObjectFieldStart("latencyExecute");
    json.writeNumberField("0", commandMetrics.getExecutionTimePercentile(0));
    json.writeNumberField("25", commandMetrics.getExecutionTimePercentile(25));
    json.writeNumberField("50", commandMetrics.getExecutionTimePercentile(50));
    json.writeNumberField("75", commandMetrics.getExecutionTimePercentile(75));
    json.writeNumberField("90", commandMetrics.getExecutionTimePercentile(90));
    json.writeNumberField("95", commandMetrics.getExecutionTimePercentile(95));
    json.writeNumberField("99", commandMetrics.getExecutionTimePercentile(99));
    json.writeNumberField("99.5", commandMetrics.getExecutionTimePercentile(99.5));
    json.writeNumberField("100", commandMetrics.getExecutionTimePercentile(100));
    json.writeEndObject();
    //
    json.writeNumberField("latencyTotal_mean", commandMetrics.getTotalTimeMean());
    json.writeObjectFieldStart("latencyTotal");
    json.writeNumberField("0", commandMetrics.getTotalTimePercentile(0));
    json.writeNumberField("25", commandMetrics.getTotalTimePercentile(25));
    json.writeNumberField("50", commandMetrics.getTotalTimePercentile(50));
    json.writeNumberField("75", commandMetrics.getTotalTimePercentile(75));
    json.writeNumberField("90", commandMetrics.getTotalTimePercentile(90));
    json.writeNumberField("95", commandMetrics.getTotalTimePercentile(95));
    json.writeNumberField("99", commandMetrics.getTotalTimePercentile(99));
    json.writeNumberField("99.5", commandMetrics.getTotalTimePercentile(99.5));
    json.writeNumberField("100", commandMetrics.getTotalTimePercentile(100));
    json.writeEndObject();
    // property values for reporting what is actually seen by the command rather than what was set somewhere
    HystrixCommandProperties commandProperties = commandMetrics.getProperties();
    json.writeNumberField("propertyValue_circuitBreakerRequestVolumeThreshold", commandProperties.circuitBreakerRequestVolumeThreshold().get());
    json.writeNumberField("propertyValue_circuitBreakerSleepWindowInMilliseconds", commandProperties.circuitBreakerSleepWindowInMilliseconds().get());
    json.writeNumberField("propertyValue_circuitBreakerErrorThresholdPercentage", commandProperties.circuitBreakerErrorThresholdPercentage().get());
    json.writeBooleanField("propertyValue_circuitBreakerForceOpen", commandProperties.circuitBreakerForceOpen().get());
    json.writeBooleanField("propertyValue_circuitBreakerForceClosed", commandProperties.circuitBreakerForceClosed().get());
    json.writeBooleanField("propertyValue_circuitBreakerEnabled", commandProperties.circuitBreakerEnabled().get());
    json.writeStringField("propertyValue_executionIsolationStrategy", commandProperties.executionIsolationStrategy().get().name());
    json.writeNumberField("propertyValue_executionIsolationThreadTimeoutInMilliseconds", commandProperties.executionTimeoutInMilliseconds().get());
    json.writeNumberField("propertyValue_executionTimeoutInMilliseconds", commandProperties.executionTimeoutInMilliseconds().get());
    json.writeBooleanField("propertyValue_executionIsolationThreadInterruptOnTimeout", commandProperties.executionIsolationThreadInterruptOnTimeout().get());
    json.writeStringField("propertyValue_executionIsolationThreadPoolKeyOverride", commandProperties.executionIsolationThreadPoolKeyOverride().get());
    json.writeNumberField("propertyValue_executionIsolationSemaphoreMaxConcurrentRequests", commandProperties.executionIsolationSemaphoreMaxConcurrentRequests().get());
    json.writeNumberField("propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests", commandProperties.fallbackIsolationSemaphoreMaxConcurrentRequests().get());
    /*
                     * The following are commented out as these rarely change and are verbose for streaming for something people don't change.
                     * We could perhaps allow a property or request argument to include these.
                     */
    //                    json.put("propertyValue_metricsRollingPercentileEnabled", commandProperties.metricsRollingPercentileEnabled().get());
    //                    json.put("propertyValue_metricsRollingPercentileBucketSize", commandProperties.metricsRollingPercentileBucketSize().get());
    //                    json.put("propertyValue_metricsRollingPercentileWindow", commandProperties.metricsRollingPercentileWindowInMilliseconds().get());
    //                    json.put("propertyValue_metricsRollingPercentileWindowBuckets", commandProperties.metricsRollingPercentileWindowBuckets().get());
    //                    json.put("propertyValue_metricsRollingStatisticalWindowBuckets", commandProperties.metricsRollingStatisticalWindowBuckets().get());
    json.writeNumberField("propertyValue_metricsRollingStatisticalWindowInMilliseconds", commandProperties.metricsRollingStatisticalWindowInMilliseconds().get());
    json.writeBooleanField("propertyValue_requestCacheEnabled", commandProperties.requestCacheEnabled().get());
    json.writeBooleanField("propertyValue_requestLogEnabled", commandProperties.requestLogEnabled().get());
    // this will get summed across all instances in a cluster
    json.writeNumberField("reportingHosts", 1);
    json.writeStringField("threadPool", commandMetrics.getThreadPoolKey().name());
    json.writeEndObject();
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) HystrixCommandProperties(com.netflix.hystrix.HystrixCommandProperties) HystrixCircuitBreaker(com.netflix.hystrix.HystrixCircuitBreaker) HystrixCommandMetrics(com.netflix.hystrix.HystrixCommandMetrics)

Example 80 with HystrixCommandKey

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

the class RollingCommandLatencyDistributionStreamTest method testEmptyStreamProducesEmptyDistributions.

@Test
public void testEmptyStreamProducesEmptyDistributions() {
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-Latency-A");
    stream = RollingCommandLatencyDistributionStream.getInstance(key, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).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());
            assertEquals(0, distribution.getTotalCount());
        }
    });
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    assertEquals(0, stream.getLatest().getTotalCount());
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) CachedValuesHistogram(com.netflix.hystrix.metric.CachedValuesHistogram) CountDownLatch(java.util.concurrent.CountDownLatch) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Aggregations

HystrixCommandKey (com.netflix.hystrix.HystrixCommandKey)113 Test (org.junit.Test)106 CommandStreamTest (com.netflix.hystrix.metric.CommandStreamTest)99 CountDownLatch (java.util.concurrent.CountDownLatch)99 HystrixThreadPoolKey (com.netflix.hystrix.HystrixThreadPoolKey)42 HystrixCommandGroupKey (com.netflix.hystrix.HystrixCommandGroupKey)38 ArrayList (java.util.ArrayList)25 CachedValuesHistogram (com.netflix.hystrix.metric.CachedValuesHistogram)9 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)8 HystrixContextRunnable (com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable)8 HystrixCommandMetrics (com.netflix.hystrix.HystrixCommandMetrics)7 HystrixCircuitBreaker (com.netflix.hystrix.HystrixCircuitBreaker)5 HystrixCommand (com.netflix.hystrix.HystrixCommand)4 Map (java.util.Map)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 HystrixPropertiesCommandDefault (com.netflix.hystrix.strategy.properties.HystrixPropertiesCommandDefault)3 StringWriter (java.io.StringWriter)3 HystrixCollapserKey (com.netflix.hystrix.HystrixCollapserKey)2 HystrixCollapserConfiguration (com.netflix.hystrix.config.HystrixCollapserConfiguration)2 HystrixCommandConfiguration (com.netflix.hystrix.config.HystrixCommandConfiguration)2