@Override public Number getValue() { return properties.circuitBreakerErrorThresholdPercentage().get(); } });
@Override public void onNext(HealthCounts hc) { // check if we are past the statisticalWindowVolumeThreshold if (hc.getTotalRequests() < properties.circuitBreakerRequestVolumeThreshold().get()) { // we are not past the minimum volume threshold for the stat window, // so no change to circuit status. // if it was CLOSED, it stays CLOSED // if it was half-open, we need to wait for a successful command execution // if it was open, we need to wait for sleep window to elapse } else { if (hc.getErrorPercentage() < properties.circuitBreakerErrorThresholdPercentage().get()) { //we are not past the minimum error threshold for the stat window, // so no change to circuit status. // if it was CLOSED, it stays CLOSED // if it was half-open, we need to wait for a successful command execution // if it was open, we need to wait for sleep window to elapse } else { // our failure rate is too high, we need to set the state to OPEN if (status.compareAndSet(Status.CLOSED, Status.OPEN)) { circuitOpened.set(System.currentTimeMillis()); } } } } });
assertEquals(30, command.getProperties().circuitBreakerRequestVolumeThreshold().get().intValue()); assertEquals(250, command.getProperties().circuitBreakerSleepWindowInMilliseconds().get().intValue()); assertEquals(60, command.getProperties().circuitBreakerErrorThresholdPercentage().get().intValue()); assertEquals(false, command.getProperties().circuitBreakerForceOpen().get().booleanValue()); assertEquals(true, command.getProperties().circuitBreakerForceClosed().get().booleanValue());
commandProperties.circuitBreakerErrorThresholdPercentage().get(), commandProperties.circuitBreakerForceClosed().get(), commandProperties.circuitBreakerForceOpen().get(),
@Override public Number getValue() { return properties.circuitBreakerErrorThresholdPercentage().get(); } });
@Override public Number call() { return properties.circuitBreakerErrorThresholdPercentage().get(); } });
@Override public Number getValue() { return properties.circuitBreakerErrorThresholdPercentage().get(); } });
@Override public Number value() { return properties.circuitBreakerErrorThresholdPercentage().get(); } });
public CircutBreakerEvent(HystrixCommandKey commandKey, Type type) { super(type); HystrixCommandMetrics hystrixCommandMetrics = HystrixCommandMetrics.getInstance(commandKey); if (hystrixCommandMetrics != null) { if (hystrixCommandMetrics.getCommandGroup() instanceof CustomizeCommandGroupKey) { CustomizeCommandGroupKey customCommandGroupKey = (CustomizeCommandGroupKey) hystrixCommandMetrics.getCommandGroup(); this.microservice = customCommandGroupKey.getInstance().getMicroserviceName(); this.role = customCommandGroupKey.getInstance().getInvocationType().name(); this.schema = customCommandGroupKey.getInstance().getSchemaId(); this.operation = customCommandGroupKey.getInstance().getOperationName(); } this.currentTotalRequest = hystrixCommandMetrics.getHealthCounts().getTotalRequests(); this.currentErrorPercentage = hystrixCommandMetrics.getHealthCounts().getErrorCount(); this.currentErrorCount = hystrixCommandMetrics.getHealthCounts().getErrorPercentage(); this.requestVolumeThreshold = hystrixCommandMetrics.getProperties().circuitBreakerRequestVolumeThreshold().get(); this.sleepWindowInMilliseconds = hystrixCommandMetrics.getProperties().circuitBreakerSleepWindowInMilliseconds().get(); this.errorThresholdPercentage = hystrixCommandMetrics.getProperties().circuitBreakerErrorThresholdPercentage().get(); } }
private void checkThresholds() { long failed = this.failedInvocations.get(); long sum = failed + this.successfulInvocations.get(); if (sum >= this.properties.circuitBreakerRequestVolumeThreshold().get() && (double) failed / sum >= (double) this.properties.circuitBreakerErrorThresholdPercentage().get() / 100) { if (status.compareAndSet(Status.CLOSED, Status.OPEN)) { circuitOpened.set(System.currentTimeMillis()); this.failedInvocations.set(0); this.successfulInvocations.set(0); this.remainingHalfOpenInvocations.set(successThreshold); if (this.metricsCollection != null) { this.metricsCollection.getOpened().inc(); this.markStatusChange(Status.CLOSED); } } } }
@Override public boolean isOpen() { if (circuitOpen.get()) { // if we're open we immediately return true and don't bother attempting to 'close' ourself as that is left to allowSingleTest and a subsequent successful test to close return true; } // we're closed, so let's see if errors have made us so we should trip the circuit open HealthCounts health = metrics.getHealthCounts(); // check if we are past the statisticalWindowVolumeThreshold if (health.getTotalRequests() < properties.circuitBreakerRequestVolumeThreshold().get()) { // we are not past the minimum volume threshold for the statisticalWindow so we'll return false immediately and not calculate anything return false; } if (health.getErrorPercentage() < properties.circuitBreakerErrorThresholdPercentage().get()) { return false; } else { // our failure rate is too high, trip the circuit if (circuitOpen.compareAndSet(false, true)) { // if the previousValue was false then we want to set the currentTime circuitOpenedOrLastTestedTime.set(System.currentTimeMillis()); return true; } else { // How could previousValue be true? If another thread was going through this code at the same time a race-condition could have // caused another thread to set it to true already even though we were in the process of doing the same // In this case, we know the circuit is open, so let the other thread set the currentTime and report back that the circuit is open return true; } } }
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.writeNumberField("propertyValue_circuitBreakerErrorThresholdPercentage", commandProperties.circuitBreakerErrorThresholdPercentage().get()); json.writeBooleanField("propertyValue_circuitBreakerForceOpen", commandProperties.circuitBreakerForceOpen().get()); json.writeBooleanField("propertyValue_circuitBreakerForceClosed", commandProperties.circuitBreakerForceClosed().get());
json.writeNumberField("propertyValue_circuitBreakerErrorThresholdPercentage", commandProperties.circuitBreakerErrorThresholdPercentage().get()); json.writeBooleanField("propertyValue_circuitBreakerForceOpen", commandProperties.circuitBreakerForceOpen().get()); json.writeBooleanField("propertyValue_circuitBreakerForceClosed", commandProperties.circuitBreakerForceClosed().get());
json.writeNumberField("propertyValue_circuitBreakerErrorThresholdPercentage", commandProperties.circuitBreakerErrorThresholdPercentage().get()); json.writeBooleanField("propertyValue_circuitBreakerForceOpen", commandProperties.circuitBreakerForceOpen().get()); json.writeBooleanField("propertyValue_circuitBreakerForceClosed", commandProperties.circuitBreakerForceClosed().get());
public CircutBreakerEvent(HystrixCommandKey commandKey, Type type) { super(type); HystrixCommandMetrics hystrixCommandMetrics = HystrixCommandMetrics.getInstance(commandKey); if (hystrixCommandMetrics != null) { if (hystrixCommandMetrics.getCommandGroup() instanceof CustomizeCommandGroupKey) { CustomizeCommandGroupKey customCommandGroupKey = (CustomizeCommandGroupKey) hystrixCommandMetrics.getCommandGroup(); this.microservice = customCommandGroupKey.getInstance().getMicroserviceName(); this.role = customCommandGroupKey.getInstance().getInvocationType().name(); this.schema = customCommandGroupKey.getInstance().getSchemaId(); this.operation = customCommandGroupKey.getInstance().getOperationName(); } this.currentTotalRequest = hystrixCommandMetrics.getHealthCounts().getTotalRequests(); this.currentErrorPercentage = hystrixCommandMetrics.getHealthCounts().getErrorCount(); this.currentErrorCount = hystrixCommandMetrics.getHealthCounts().getErrorPercentage(); this.requestVolumeThreshold = hystrixCommandMetrics.getProperties().circuitBreakerRequestVolumeThreshold().get(); this.sleepWindowInMilliseconds = hystrixCommandMetrics.getProperties().circuitBreakerSleepWindowInMilliseconds().get(); this.errorThresholdPercentage = hystrixCommandMetrics.getProperties().circuitBreakerErrorThresholdPercentage().get(); } }
public static TenacityConfiguration getTenacityConfiguration(TenacityPropertyKey key) { final HystrixCommandProperties commandProperties = TenacityCommand.getCommandProperties(key); final HystrixThreadPoolProperties threadPoolProperties = TenacityCommand.getThreadpoolProperties(key); return new TenacityConfiguration( new ThreadPoolConfiguration( threadPoolProperties.coreSize().get(), threadPoolProperties.keepAliveTimeMinutes().get(), threadPoolProperties.maxQueueSize().get(), threadPoolProperties.queueSizeRejectionThreshold().get(), threadPoolProperties.metricsRollingStatisticalWindowInMilliseconds().get(), threadPoolProperties.metricsRollingStatisticalWindowBuckets().get()), new CircuitBreakerConfiguration( commandProperties.circuitBreakerRequestVolumeThreshold().get(), commandProperties.circuitBreakerSleepWindowInMilliseconds().get(), commandProperties.circuitBreakerErrorThresholdPercentage().get(), commandProperties.metricsRollingStatisticalWindowInMilliseconds().get(), commandProperties.metricsRollingStatisticalWindowBuckets().get()), new SemaphoreConfiguration( commandProperties.executionIsolationSemaphoreMaxConcurrentRequests().get(), commandProperties.fallbackIsolationSemaphoreMaxConcurrentRequests().get()), commandProperties.executionTimeoutInMilliseconds().get(), commandProperties.executionIsolationStrategy().get()); } }
public static TenacityConfiguration getTenacityConfiguration(TenacityPropertyKey key) { final HystrixCommandProperties commandProperties = TenacityCommand.getCommandProperties(key); final HystrixThreadPoolProperties threadPoolProperties = TenacityCommand.getThreadpoolProperties(key); return new TenacityConfiguration( new ThreadPoolConfiguration( threadPoolProperties.coreSize().get(), threadPoolProperties.keepAliveTimeMinutes().get(), threadPoolProperties.maxQueueSize().get(), threadPoolProperties.queueSizeRejectionThreshold().get(), threadPoolProperties.metricsRollingStatisticalWindowInMilliseconds().get(), threadPoolProperties.metricsRollingStatisticalWindowBuckets().get()), new CircuitBreakerConfiguration( commandProperties.circuitBreakerRequestVolumeThreshold().get(), commandProperties.circuitBreakerSleepWindowInMilliseconds().get(), commandProperties.circuitBreakerErrorThresholdPercentage().get(), commandProperties.metricsRollingStatisticalWindowInMilliseconds().get(), commandProperties.metricsRollingStatisticalWindowBuckets().get()), new SemaphoreConfiguration( commandProperties.executionIsolationSemaphoreMaxConcurrentRequests().get(), commandProperties.fallbackIsolationSemaphoreMaxConcurrentRequests().get()), commandProperties.executionTimeoutInMilliseconds().get(), commandProperties.executionIsolationStrategy().get()); } }
commandProperties.circuitBreakerErrorThresholdPercentage().get(), commandProperties.circuitBreakerForceClosed().get(), commandProperties.circuitBreakerForceOpen().get(),