com.netflix.hystrix.util.HystrixRollingNumberEvent Java Examples

The following examples show how to use com.netflix.hystrix.util.HystrixRollingNumberEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HystrixCommandFacadeTest.java    From astrix with Apache License 2.0 6 votes vote down vote up
@Test
public void normalExceptionsThrownIsTreatedAsPartOfNormalApiFlowAndDoesNotCountAsFailure() throws Throwable {
	initMetrics(ping);
	pingServer.setFault(() -> {
		throw new MyDomainException();
	});
	try {
		ping.ping("foo");
		fail("Expected service unavailable");
	} catch (MyDomainException e) {
		// Expcected
	} 
	
	eventually(() -> {
		// Note that from the perspective of a circuit-breaker an exception thrown
		// by the underlying service call (typically a service call) should not
		// count as failure and therefore not (possibly) trip circuit breaker.
		assertEquals(2, getEventCountForCommand(HystrixRollingNumberEvent.SUCCESS)); //+1 from init
		assertEquals(0, getEventCountForCommand(HystrixRollingNumberEvent.FAILURE));
	});
}
 
Example #2
Source File: HystrixObservableCommandFacadeTest.java    From astrix with Apache License 2.0 6 votes vote down vote up
@Test
public void semaphoreRejectedCountsAsFailure() throws Exception {
	pingServer.setResult(Observable.create(new OnSubscribe<String>() {
		@Override
		public void call(Subscriber<? super String> t1) {
			// Simulate timeout by not invoking subscriber
		}
	}));
	Observable<String> ftObservable1 = ping.ping();
	Observable<String> ftObservable2 = ping.ping();

	// Subscribe to observables, ignore emitted items/errors
	ftObservable1.subscribe((item) -> {}, (exception) -> {});
	ftObservable2.subscribe((item) -> {}, (exception) -> {});

	eventually(() -> {
		assertEquals(0, getEventCountForCommand(HystrixRollingNumberEvent.SUCCESS));
		assertEquals(1, getEventCountForCommand(HystrixRollingNumberEvent.SEMAPHORE_REJECTED));
	});
}
 
Example #3
Source File: HystrixObservableCommandFacadeTest.java    From astrix with Apache License 2.0 6 votes vote down vote up
@Test
public void throwsServiceUnavailableOnTimeouts() throws Exception {
	pingServer.setResult(Observable.create(new OnSubscribe<String>() {
		@Override
		public void call(Subscriber<? super String> t1) {
			// Simulate timeout by not invoking subscriber
		}
	}));
	try {
		ping.ping().toBlocking().first();
		fail("All ServiceUnavailableException should be thrown on timeout");
	} catch (ServiceUnavailableException e) {
		// Expcected
	}
	eventually(() -> {
		assertEquals(0, getEventCountForCommand(HystrixRollingNumberEvent.SUCCESS));
		assertEquals(1, getEventCountForCommand(HystrixRollingNumberEvent.TIMEOUT));
		assertEquals(0, getEventCountForCommand(HystrixRollingNumberEvent.SEMAPHORE_REJECTED));
	});
}
 
Example #4
Source File: HystrixObservableCommandFacadeTest.java    From astrix with Apache License 2.0 6 votes vote down vote up
@Test
public void normalExceptionsThrownIsTreatedAsPartOfNormalApiFlowAndDoesNotCountAsFailure() throws Exception {
	pingServer.setResult(Observable.<String>error(new MyDomainException()));
	try {
		ping.ping().toBlocking().first();
		fail("All regular exception should be propagated as is from underlying observable");
	} catch (MyDomainException e) {
		// Expcected
	}
	
	eventually(() -> {
		// Note that from the perspective of a circuit-breaker an exception thrown
		// by the underlying observable (typically a service call) should not
		// count as failure and therefore not (possibly) trip circuit breaker.
		assertEquals(1, getEventCountForCommand(HystrixRollingNumberEvent.SUCCESS));
		assertEquals(0, getEventCountForCommand(HystrixRollingNumberEvent.FAILURE));
	});
}
 
Example #5
Source File: TenacityCircuitBreakerTest.java    From tenacity with Apache License 2.0 5 votes vote down vote up
@Test
public void circuitBreakerShouldOpen() throws URISyntaxException, InterruptedException {
    final TenacityFailingCommand tenacityFailingCommand = new TenacityFailingCommand();
    tenacityFailingCommand
            .getCumulativeCommandEventCounterStream()
            .startCachingStreamValuesIfUnstarted();
    final int numberOfExecutions = 500;

    for (int i = 0; i < numberOfExecutions; i++) {
        new TenacityFailingCommand().execute();

        //Allow for circuit breaker calculations to take place and open the circuit
        if (i == (numberOfExecutions / 2)) {
            Thread.sleep(500);
        }
    }

    Thread.sleep(1000);

    final HystrixCommandMetrics sleepCommandMetrics = tenacityFailingCommand.getCommandMetrics();
    assertThat(sleepCommandMetrics
                    .getCumulativeCount(HystrixRollingNumberEvent.TIMEOUT))
            .isZero();
    assertThat(sleepCommandMetrics
                    .getCumulativeCount(HystrixRollingNumberEvent.FALLBACK_SUCCESS))
            .isEqualTo(numberOfExecutions);
    assertThat(sleepCommandMetrics
                    .getCumulativeCount(HystrixRollingNumberEvent.SHORT_CIRCUITED))
            .isGreaterThan(50L);
    assertFalse("Allow request should be false", tenacityFailingCommand.getCircuitBreaker().allowRequest());
    assertTrue("Circuit Breaker should be open", tenacityFailingCommand.isCircuitBreakerOpen());
}
 
Example #6
Source File: HystrixPrometheusMetricsPublisherCollapser.java    From prometheus-hystrix with Apache License 2.0 5 votes vote down vote up
private void createRollingCountForEvent(String metric, final HystrixRollingNumberEvent event) {
    String doc = "These are \"point in time\" counts representing the last X seconds.";
    addGauge(metric, doc, new Callable<Number>() {
        @Override
        public Number call() throws Exception {
            return metrics.getRollingCount(event);
        }
    });
}
 
Example #7
Source File: HystrixPrometheusMetricsPublisherCollapser.java    From prometheus-hystrix with Apache License 2.0 5 votes vote down vote up
private void createCumulativeCountForEvent(String metric, final HystrixRollingNumberEvent event) {
    String doc = "These are cumulative counts since the start of the application.";
    addGauge(metric, doc, new Callable<Number>() {
        @Override
        public Number call() throws Exception {
            return metrics.getCumulativeCount(event);
        }
    });
}
 
Example #8
Source File: TenacityCircuitBreakerTest.java    From tenacity with Apache License 2.0 5 votes vote down vote up
@Test
public void circuitBreakerShouldBeClosed() throws URISyntaxException, InterruptedException {
    final TenacityFailingCommand tenacityFailingCommand = new TenacityFailingCommand();
    tenacityFailingCommand
            .getCumulativeCommandEventCounterStream()
            .startCachingStreamValuesIfUnstarted();
    final int numberOfExecutions = 10;

    for (int i = 0; i < numberOfExecutions; i++) {
        new TenacityFailingCommand().execute();
        assertTrue("Allow request should be true", tenacityFailingCommand.getCircuitBreaker().allowRequest());
        assertFalse("Circuit Breaker should not be open", tenacityFailingCommand.isCircuitBreakerOpen());
    }

    Thread.sleep(1000);

    final HystrixCommandMetrics sleepCommandMetrics = tenacityFailingCommand.getCommandMetrics();
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.TIMEOUT))
            .isEqualTo(0L);
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.FALLBACK_SUCCESS))
            .isEqualTo(10L);
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.SHORT_CIRCUITED))
            .isEqualTo(0L);
    assertTrue("Allow request should be true", tenacityFailingCommand.getCircuitBreaker().allowRequest());
    assertFalse("Circuit Breaker should not be open", tenacityFailingCommand.isCircuitBreakerOpen());
}
 
Example #9
Source File: HystrixFaulttoleranceIntegrationTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
private int getEventCountForCommand(HystrixRollingNumberEvent hystrixRollingNumberEvent, HystrixCommandKey commandKey) {
	HystrixCommandMetrics metrics = HystrixCommandMetrics.getInstance(commandKey);
	if (metrics == null) {
		return 0;
	}
	int currentConcurrentExecutionCount = (int) metrics.getCumulativeCount(hystrixRollingNumberEvent);
	return currentConcurrentExecutionCount;
}
 
Example #10
Source File: TenacityObservableCommandTest.java    From tenacity with Apache License 2.0 5 votes vote down vote up
private static void executeTimeoutAndVerify(final TenacityObservableCommand<Boolean> timeoutCommand) throws InterruptedException {
    timeoutCommand.getCumulativeCommandEventCounterStream().startCachingStreamValuesIfUnstarted();
    try {
        assertTrue(timeoutCommand.observe().toBlocking().single());
    } catch (HystrixRuntimeException err) {
        assertEquals(err.getFailureType(), HystrixRuntimeException.FailureType.TIMEOUT);
    }

    Thread.sleep(1000);

    assertEquals(timeoutCommand.isResponseTimedOut(), true);
    assertEquals(timeoutCommand.getMetrics().getCumulativeCount(HystrixRollingNumberEvent.TIMEOUT), 1);
}
 
Example #11
Source File: HystrixObservableCommandFacadeTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
private int getEventCountForCommand(HystrixRollingNumberEvent hystrixRollingNumberEvent) {
	HystrixFaultToleranceFactory faultTolerance = (HystrixFaultToleranceFactory) AstrixApplicationContext.class.cast(this.context).getInstance(BeanFaultToleranceFactorySpi.class);
	HystrixCommandKey commandKey = faultTolerance.getCommandKey(AstrixBeanKey.create(Ping.class));
	HystrixCommandMetrics metrics = HystrixCommandMetrics.getInstance(commandKey);
	int currentConcurrentExecutionCount = (int) metrics.getCumulativeCount(hystrixRollingNumberEvent);
	return currentConcurrentExecutionCount;
}
 
Example #12
Source File: HystrixObservableCommandFacadeTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
@Test
public void serviceUnavailableThrownByUnderlyingObservableShouldCountAsFailure() throws Exception {
	pingServer.setResult(Observable.<String>error(new ServiceUnavailableException("")));
	try {
		ping.ping().toBlocking().first();
		fail("Expected service unavailable");
	} catch (ServiceUnavailableException e) {
		// Expcected
	}
	eventually(() -> {
		assertEquals(0, getEventCountForCommand(HystrixRollingNumberEvent.SUCCESS));
		assertEquals(1, getEventCountForCommand(HystrixRollingNumberEvent.FAILURE));
	});
}
 
Example #13
Source File: HystrixObservableCommandFacadeTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
@Test
public void underlyingObservableIsWrappedWithFaultTolerance() throws Throwable {
	pingServer.setResult(Observable.just("foo"));
	String result = ping.ping().toBlocking().first();

	assertEquals("foo", result);
	eventually(() -> {
		assertEquals(1, getEventCountForCommand(HystrixRollingNumberEvent.SUCCESS));
	});
}
 
Example #14
Source File: HystrixCommandFacadeTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
private int getEventCountForCommand(HystrixRollingNumberEvent hystrixRollingNumberEvent) {
	HystrixFaultToleranceFactory faultTolerance = (HystrixFaultToleranceFactory) AstrixApplicationContext.class.cast(this.context).getInstance(BeanFaultToleranceFactorySpi.class);
	HystrixCommandKey commandKey = faultTolerance.getCommandKey(AstrixBeanKey.create(Ping.class));
	HystrixCommandMetrics metrics = HystrixCommandMetrics.getInstance(commandKey);
	int currentConcurrentExecutionCount = (int) metrics.getCumulativeCount(hystrixRollingNumberEvent);
	return currentConcurrentExecutionCount;
}
 
Example #15
Source File: HystrixCommandFacadeTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
@Test
public void underlyingObservableIsWrappedWithFaultTolerance() throws Throwable {
	String result = ping.ping("foo");

	assertEquals("foo", result);
	eventually(() -> {
		assertEquals(1, getEventCountForCommand(HystrixRollingNumberEvent.SUCCESS));
	});
}
 
Example #16
Source File: TenacityObservableCommandTest.java    From tenacity with Apache License 2.0 4 votes vote down vote up
@Test
public void whenUsingObservableCommandsExperienceRejectionsIfSemaphoreLimitBreached() throws InterruptedException {
    final TenacityConfiguration tenacityConfiguration = new TenacityConfiguration();
    tenacityConfiguration.setExecutionIsolationThreadTimeoutInMillis(3000);
    tenacityConfiguration.setExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE);

    new TenacityPropertyRegister(
            ImmutableMap.<TenacityPropertyKey, TenacityConfiguration>of(DependencyKey.OBSERVABLE_TIMEOUT, tenacityConfiguration),
            new BreakerboxConfiguration())
            .register();

    new TimeoutObservable(Duration.milliseconds(500))
            .getCumulativeCommandEventCounterStream()
            .startCachingStreamValuesIfUnstarted();

    final int defaultSemaphoreMaxConcurrentRequests = new SemaphoreConfiguration().getMaxConcurrentRequests();
    final ImmutableList.Builder<Observable<Boolean>> observables = ImmutableList.builder();
    for (int i = 0; i < defaultSemaphoreMaxConcurrentRequests * 2; ++i) {
        final TimeoutObservable command = new TimeoutObservable(Duration.milliseconds(500));
        observables.add(command.observe());
    }

    for (Observable<Boolean> observable : observables.build()) {
        try {
            assertTrue(observable.toBlocking().single());
        } catch (HystrixRuntimeException err) {
            assertThat(err).isInstanceOf(HystrixRuntimeException.class);
            assertThat(err.getFailureType())
                    .isIn(HystrixRuntimeException.FailureType.REJECTED_SEMAPHORE_EXECUTION,
                            HystrixRuntimeException.FailureType.TIMEOUT);
        }
    }

    //Wait for metrics to be available
    Thread.sleep(1000);

    assertThat(TenacityObservableCommand
            .getCommandMetrics(DependencyKey.OBSERVABLE_TIMEOUT)
            .getCumulativeCount(HystrixRollingNumberEvent.SEMAPHORE_REJECTED))
            .isGreaterThan(0);
    assertThat(TenacityObservableCommand
            .getCommandMetrics(DependencyKey.OBSERVABLE_TIMEOUT)
            .getCumulativeCount(HystrixRollingNumberEvent.TIMEOUT))
            .isEqualTo(0);
    assertThat(TenacityObservableCommand
            .getCommandMetrics(DependencyKey.OBSERVABLE_TIMEOUT)
            .getCumulativeCount(HystrixRollingNumberEvent.SUCCESS))
            .isGreaterThan(0);
}
 
Example #17
Source File: TenacityObservableCommandTest.java    From tenacity with Apache License 2.0 4 votes vote down vote up
@Test
public void observableCommandCanAdjustSemaphoreMaxConcurrentExecutions() throws InterruptedException {
    final SemaphoreConfiguration semaphoreConfiguration = new SemaphoreConfiguration();
    semaphoreConfiguration.setMaxConcurrentRequests(50);

    final TenacityConfiguration tenacityConfiguration = new TenacityConfiguration();
    tenacityConfiguration.setSemaphore(semaphoreConfiguration);
    tenacityConfiguration.setExecutionIsolationThreadTimeoutInMillis(3000);

    new TenacityPropertyRegister(
            ImmutableMap.<TenacityPropertyKey, TenacityConfiguration>of(DependencyKey.OBSERVABLE_TIMEOUT, tenacityConfiguration),
            new BreakerboxConfiguration())
            .register();

    new TimeoutObservable(Duration.milliseconds(500))
            .getCumulativeCommandEventCounterStream()
            .startCachingStreamValuesIfUnstarted();

    final int defaultSemaphoreMaxConcurrentRequests = new SemaphoreConfiguration().getMaxConcurrentRequests();

    final ImmutableList.Builder<Observable<Boolean>> observables = ImmutableList.builder();
    for (int i = 0; i < defaultSemaphoreMaxConcurrentRequests * 2; ++i) {
        final TimeoutObservable command = new TimeoutObservable(Duration.milliseconds(500));
        observables.add(command.observe());
    }

    for (Observable<Boolean> observable : observables.build()) {
        try {
            assertTrue(observable.toBlocking().single());
        } catch (HystrixRuntimeException err) {
            fail("Failed to execute an observe: " + err);
        }
    }

    Thread.sleep(1000);

    assertThat(TenacityObservableCommand
            .getCommandMetrics(DependencyKey.OBSERVABLE_TIMEOUT)
            .getCumulativeCount(HystrixRollingNumberEvent.SEMAPHORE_REJECTED))
            .isEqualTo(0);
    assertThat(TenacityObservableCommand
            .getCommandMetrics(DependencyKey.OBSERVABLE_TIMEOUT)
            .getCumulativeCount(HystrixRollingNumberEvent.TIMEOUT))
            .isEqualTo(0);
    assertThat(TenacityObservableCommand
            .getCommandMetrics(DependencyKey.OBSERVABLE_TIMEOUT)
            .getCumulativeCount(HystrixRollingNumberEvent.SUCCESS))
            .isEqualTo(observables.build().size());
}
 
Example #18
Source File: TenacityPropertiesTest.java    From tenacity with Apache License 2.0 4 votes vote down vote up
@Test
public void queueRejectionWithBlockingQueue() throws Exception {
    final int queueMaxSize = 5;
    final TenacityConfiguration exampleConfiguration = new TenacityConfiguration(
            new ThreadPoolConfiguration(1, 1, 10, queueMaxSize, 10000, 10),
            new CircuitBreakerConfiguration(20, 5000, 50, 10000, 10),
            new SemaphoreConfiguration(),
            5000,
            HystrixCommandProperties.ExecutionIsolationStrategy.THREAD);

    final TenacityPropertyRegister tenacityPropertyRegister = new TenacityPropertyRegister(
            ImmutableMap.<TenacityPropertyKey, TenacityConfiguration>of(DependencyKey.SLEEP, exampleConfiguration),
            new BreakerboxConfiguration(),
            mock(ArchaiusPropertyRegister.class));

    tenacityPropertyRegister.register();

    new SleepCommand(DependencyKey.SLEEP).getCumulativeCommandEventCounterStream().startCachingStreamValuesIfUnstarted();

    final ImmutableList.Builder<Future<Optional<String>>> sleepCommands = ImmutableList.builder();
    for (int i = 0; i < queueMaxSize * 2; i++) {
        sleepCommands.add(new SleepCommand(DependencyKey.SLEEP).queue());
    }

    checkFutures(sleepCommands.build());

    final HystrixCommandMetrics sleepCommandMetrics = new SleepCommand(DependencyKey.SLEEP).getCommandMetrics();
    assertThat(sleepCommandMetrics
                    .getCumulativeCount(HystrixRollingNumberEvent.THREAD_POOL_REJECTED))
            .isEqualTo(4L);
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.TIMEOUT))
            .isEqualTo(0L);
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.FALLBACK_SUCCESS))
            .isEqualTo(4L);
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.SHORT_CIRCUITED))
            .isEqualTo(0L);

    final HystrixThreadPoolProperties threadPoolProperties = new SleepCommand(DependencyKey.SLEEP).getThreadpoolProperties();

    final ThreadPoolConfiguration threadPoolConfiguration = exampleConfiguration.getThreadpool();
    assertEquals(threadPoolProperties.queueSizeRejectionThreshold().get().intValue(), threadPoolConfiguration.getQueueSizeRejectionThreshold());
    assertEquals(threadPoolProperties.maxQueueSize().get().intValue(), threadPoolConfiguration.getMaxQueueSize());

    assertEquals(TenacityPropertyStore.getTenacityConfiguration(DependencyKey.SLEEP), exampleConfiguration);
}
 
Example #19
Source File: BeanFaultToleranceMetrics.java    From astrix with Apache License 2.0 4 votes vote down vote up
@Override
public long getSuccessCount() {
	return getCommandMetrics().map(me -> me.getCumulativeCount(HystrixRollingNumberEvent.SUCCESS))
							  .orElse(0L);
}
 
Example #20
Source File: TenacityPropertiesTest.java    From tenacity with Apache License 2.0 4 votes vote down vote up
@Test
public void queueRejectionWithSynchronousQueue() throws Exception {
    new SleepCommand(DependencyKey.EXAMPLE)
            .getCumulativeCommandEventCounterStream()
            .startCachingStreamValuesIfUnstarted();

    final ImmutableCollection.Builder<Future<Optional<String>>> futures = ImmutableList.builder();
    for (int i = 0; i < 50; i++) {
        futures.add(new SleepCommand(DependencyKey.EXAMPLE).queue());
    }

    checkFutures(futures.build());

    Thread.sleep(500);

    final HystrixCommandMetrics sleepCommandMetrics = new SleepCommand(DependencyKey.EXAMPLE).getCommandMetrics();
    assertThat(sleepCommandMetrics
                    .getCumulativeCount(HystrixRollingNumberEvent.THREAD_POOL_REJECTED))
            .isGreaterThan(15L);
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.TIMEOUT))
            .isEqualTo(0L);
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.FALLBACK_SUCCESS))
            .isGreaterThanOrEqualTo(40L);
    assertThat(sleepCommandMetrics
                    .getCumulativeCount(HystrixRollingNumberEvent.FALLBACK_FAILURE))
            .isEqualTo(0L);
    assertThat(sleepCommandMetrics
                    .getCumulativeCount(HystrixRollingNumberEvent.FALLBACK_REJECTION))
            .isEqualTo(0L);
    assertThat(sleepCommandMetrics
            .getCumulativeCount(HystrixRollingNumberEvent.SHORT_CIRCUITED))
            .isEqualTo(sleepCommandMetrics.getCumulativeCount(HystrixRollingNumberEvent.FALLBACK_SUCCESS) -
                    sleepCommandMetrics.getCumulativeCount(HystrixRollingNumberEvent.THREAD_POOL_REJECTED));

    final HystrixThreadPoolProperties threadPoolProperties = new SleepCommand(DependencyKey.EXAMPLE).getThreadpoolProperties();

    //-1 means no limit on the number of items in the queue, which uses the SynchronousBlockingQueue
    assertEquals(threadPoolProperties.maxQueueSize().get().intValue(), -1);
    assertEquals(TenacityPropertyStore.getTenacityConfiguration(DependencyKey.EXAMPLE),
            new TenacityConfiguration(new ThreadPoolConfiguration(), new CircuitBreakerConfiguration(),
                    new SemaphoreConfiguration(), 1000, HystrixCommandProperties.ExecutionIsolationStrategy.THREAD));
}
 
Example #21
Source File: HystrixPrometheusMetricsPublisherCollapser.java    From prometheus-hystrix with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize() {
    delegate.initialize();

    createCumulativeCountForEvent("count_batches", HystrixRollingNumberEvent.COLLAPSER_BATCH);
    createCumulativeCountForEvent("count_requests_batched", HystrixRollingNumberEvent.COLLAPSER_REQUEST_BATCHED);
    createCumulativeCountForEvent("count_responses_from_cache", HystrixRollingNumberEvent.RESPONSE_FROM_CACHE);

    createRollingCountForEvent("rolling_batches", HystrixRollingNumberEvent.COLLAPSER_BATCH);
    createRollingCountForEvent("rolling_requests_batched", HystrixRollingNumberEvent.COLLAPSER_REQUEST_BATCHED);
    createRollingCountForEvent("rolling_count_responses_from_cache", HystrixRollingNumberEvent.RESPONSE_FROM_CACHE);

    String batchDoc = "Collapser the batch size metric.";
    addGauge("batch_size_mean", batchDoc, new Callable<Number>() {
        @Override
        public Number call() throws Exception {
            return metrics.getBatchSizeMean();
        }
    });

    createBatchSizePercentile("batch_size_percentile_25", 25, batchDoc);
    createBatchSizePercentile("batch_size_percentile_50", 50, batchDoc);
    createBatchSizePercentile("batch_size_percentile_75", 75, batchDoc);
    createBatchSizePercentile("batch_size_percentile_90", 90, batchDoc);
    createBatchSizePercentile("batch_size_percentile_99", 99, batchDoc);
    createBatchSizePercentile("batch_size_percentile_995", 99.5, batchDoc);

    String shardDoc = "Collapser shard size metric.";
    addGauge("shard_size_mean", shardDoc, new Callable<Number>() {
        @Override
        public Number call() throws Exception {
            return metrics.getShardSizeMean();
        }
    });

    createShardSizePercentile("shard_size_percentile_25", 25, shardDoc);
    createShardSizePercentile("shard_size_percentile_50", 50, shardDoc);
    createShardSizePercentile("shard_size_percentile_75", 75, shardDoc);
    createShardSizePercentile("shard_size_percentile_90", 90, shardDoc);
    createShardSizePercentile("shard_size_percentile_99", 99, shardDoc);
    createShardSizePercentile("shard_size_percentile_995", 99.5, shardDoc);

    if (exportProperties) {
        String doc = "Configuration property partitioned by collapser_name.";

        addGauge("property_value_max_requests_in_batch", doc,
                new Callable<Number>() {
                    @Override
                    public Number call() throws Exception {
                        return properties.maxRequestsInBatch().get();
                    }
                });

        addGauge("property_value_request_cache_enabled", doc,
                new Callable<Number>() {
                    @Override
                    public Number call() throws Exception {
                        return properties.requestCacheEnabled().get() ? 1 : 0;
                    }
                });

        addGauge("property_value_timer_delay_in_milliseconds", doc,
                new Callable<Number>() {
                    @Override
                    public Number call() throws Exception {
                        return properties.timerDelayInMilliseconds().get();
                    }
                });

        addGauge("property_value_rolling_statistical_window_in_milliseconds", doc,
                new Callable<Number>() {
                    @Override
                    public Number call() throws Exception {
                        return properties.metricsRollingStatisticalWindowInMilliseconds().get();
                    }
                });
    }
}
 
Example #22
Source File: HystrixFaulttoleranceIntegrationTest.java    From astrix with Apache License 2.0 4 votes vote down vote up
private int getAppliedFaultToleranceCount(Class<?> beanType) {
	HystrixCommandKey commandKey = getFaultTolerance(context).getCommandKey(AstrixBeanKey.create(beanType));
	return getEventCountForCommand(HystrixRollingNumberEvent.SUCCESS, commandKey);
}
 
Example #23
Source File: BeanFaultToleranceMetrics.java    From astrix with Apache License 2.0 4 votes vote down vote up
@Override
public long getThreadPoolRejectedCount() {
	return getCommandMetrics().map(me -> me.getCumulativeCount(HystrixRollingNumberEvent.THREAD_POOL_REJECTED))
							  .orElse(0L);
}
 
Example #24
Source File: BeanFaultToleranceMetrics.java    From astrix with Apache License 2.0 4 votes vote down vote up
@Override
public long getTimeoutCount() {
	return getCommandMetrics().map(me -> me.getCumulativeCount(HystrixRollingNumberEvent.TIMEOUT))
							  .orElse(0L);
}
 
Example #25
Source File: BeanFaultToleranceMetrics.java    From astrix with Apache License 2.0 4 votes vote down vote up
@Override
public long getShortCircuitedCount() {
	return getCommandMetrics().map(me -> me.getCumulativeCount(HystrixRollingNumberEvent.SHORT_CIRCUITED))
							  .orElse(0L);
}
 
Example #26
Source File: BeanFaultToleranceMetrics.java    From astrix with Apache License 2.0 4 votes vote down vote up
@Override
public long getSemaphoreRejectedCount() {
	return getCommandMetrics().map(me -> me.getCumulativeCount(HystrixRollingNumberEvent.SEMAPHORE_REJECTED))
							  .orElse(0L);
}