Skip to content

Commit

Permalink
Merge pull request Netflix#1586 from mattrjacobs/fix-codahale-metrics
Browse files Browse the repository at this point in the history
Get CodaHale metrics working by starting up the stream consumers
  • Loading branch information
mattrjacobs authored May 16, 2017
2 parents 338aadc + 2ad586b commit a7b66ca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@

import com.codahale.metrics.Gauge;
import com.codahale.metrics.MetricRegistry;
import com.netflix.hystrix.HystrixCircuitBreaker;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandKey;
import com.netflix.hystrix.HystrixCommandMetrics;
import com.netflix.hystrix.HystrixCommandProperties;
import com.netflix.hystrix.*;
import com.netflix.hystrix.metric.consumer.*;
import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisherCommand;
import com.netflix.hystrix.util.HystrixRollingNumberEvent;
import org.slf4j.Logger;
Expand Down Expand Up @@ -488,6 +485,12 @@ public Number getValue() {
return properties.fallbackIsolationSemaphoreMaxConcurrentRequests().get();
}
});

RollingCommandEventCounterStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted();
CumulativeCommandEventCounterStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted();
RollingCommandLatencyDistributionStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted();
RollingCommandUserLatencyDistributionStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted();
RollingCommandMaxConcurrencyStream.getInstance(key, properties).startCachingStreamValuesIfUnstarted();
}

protected String createMetricName(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

import java.util.Map;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class HystrixCodaHaleMetricsPublisherCommandTest {
private final MetricRegistry metricRegistry = new MetricRegistry();

Expand All @@ -20,27 +23,28 @@ public void setup() {
HystrixPlugins.getInstance().registerMetricsPublisher(new HystrixCodaHaleMetricsPublisher(metricRegistry));
}

@After
public void teardown() {
HystrixPlugins.reset();
@Test
public void testCommandSuccess() throws InterruptedException {
Command command = new Command();
command.execute();

Thread.sleep(1000);

assertThat((Long) metricRegistry.getGauges().get("test.test.countSuccess").getValue(), is(1L));

}

@Test
public void commandMaxActiveGauge() {
final HystrixCommandKey hystrixCommandKey = HystrixCommandKey.Factory.asKey("test");
final HystrixCommandGroupKey hystrixCommandGroupKey = HystrixCommandGroupKey.Factory.asKey("test");

new HystrixCommand<Void>(HystrixCommand.Setter
.withGroupKey(hystrixCommandGroupKey)
.andCommandKey(hystrixCommandKey)) {
@Override
protected Void run() throws Exception {
return null;
}
}.execute();

for (Map.Entry<String, Gauge> entry : metricRegistry.getGauges().entrySet()) {
entry.getValue().getValue();
private static class Command extends HystrixCommand<Void> {
final static HystrixCommandKey hystrixCommandKey = HystrixCommandKey.Factory.asKey("test");
final static HystrixCommandGroupKey hystrixCommandGroupKey = HystrixCommandGroupKey.Factory.asKey("test");

Command() {
super(Setter.withGroupKey(hystrixCommandGroupKey).andCommandKey(hystrixCommandKey));
}

@Override
protected Void run() throws Exception {
return null;
}
}
}

0 comments on commit a7b66ca

Please sign in to comment.