Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to metrics library v3.0.1 #193

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ apply plugin: 'idea'
dependencies {
compile project(':hystrix-core')
compile 'com.yammer.metrics:metrics-core:2.2.0'
compile 'com.codahale.metrics:metrics-core:3.0.1'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okay to have both versions imported in the same project? Are they namespaced separately?

Or do we need a completely new submodule 'hystrix-yammer-metrics3-publisher'?

And what is the "official" GroupID since there is both 'com.yammer' and 'com.codahale'. Version 2 was 'com.yammer', this adds version 3 using 'com.codahale'. Both are available on Maven Central: http://search.maven.org/#search%7Cga%7C1%7Cmetrics-core

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In version 3 they changed the namespace from com.yammer to com.codahale to allow side-by-side, so there is no problem with having them both in the same project. No need for a separate sub-module.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that does mean we are forcing people to pull in both dependencies, version 2 and version 3.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can exclude the one you don't need in your pom so it won't bring it.
Not good enough?

On Tue, Nov 12, 2013 at 9:41 PM, Ben Christensen
[email protected]:

In hystrix-contrib/hystrix-yammer-metrics-publisher/build.gradle:

@@ -5,6 +5,7 @@ apply plugin: 'idea'
dependencies {
compile project(':hystrix-core')
compile 'com.yammer.metrics:metrics-core:2.2.0'

  • compile 'com.codahale.metrics:metrics-core:3.0.1'

But that does mean we are forcing people to pull in both dependencies,
version 2 and version 3.


Reply to this email directly or view it on GitHubhttps://github.com//pull/193/files#r7604061
.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's rather awkward to require people to manually exclude libraries they don't want to pull in.

Especially since it's a new namespace, how about a new module 'hystrix-codahale-metrics3-publisher'?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds decent :-)

On Tue, Nov 12, 2013 at 9:59 PM, Ben Christensen
[email protected]:

In hystrix-contrib/hystrix-yammer-metrics-publisher/build.gradle:

@@ -5,6 +5,7 @@ apply plugin: 'idea'
dependencies {
compile project(':hystrix-core')
compile 'com.yammer.metrics:metrics-core:2.2.0'

  • compile 'com.codahale.metrics:metrics-core:3.0.1'

That's rather awkward to require people to manually exclude libraries they
don't want to pull in.

Especially since it's a new namespace, how about a new module
'hystrix-codahale-metrics3-publisher'?


Reply to this email directly or view it on GitHubhttps://github.com//pull/193/files#r7604748
.

}

eclipse {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.hystrix.contrib.yammermetricspublisherv3;

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.HystrixThreadPoolKey;
import com.netflix.hystrix.HystrixThreadPoolMetrics;
import com.netflix.hystrix.HystrixThreadPoolProperties;
import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisher;
import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisherCommand;
import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisherThreadPool;

/**
* Yammer Metrics (https://github.com/codahale/metrics) implementation of {@link HystrixMetricsPublisher}.
*/
public class HystrixYammerMetricsPublisher extends HystrixMetricsPublisher {
private final MetricRegistry metricsRegistry;

public HystrixYammerMetricsPublisher() {
this(new MetricRegistry());
}

public HystrixYammerMetricsPublisher(MetricRegistry metricsRegistry) {
this.metricsRegistry = metricsRegistry;
}

@Override
public HystrixMetricsPublisherCommand getMetricsPublisherForCommand(HystrixCommandKey commandKey, HystrixCommandGroupKey commandGroupKey, HystrixCommandMetrics metrics, HystrixCircuitBreaker circuitBreaker, HystrixCommandProperties properties) {
return new HystrixYammerMetricsPublisherCommand(commandKey, commandGroupKey, metrics, circuitBreaker, properties, metricsRegistry);
}

@Override
public HystrixMetricsPublisherThreadPool getMetricsPublisherForThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, HystrixThreadPoolProperties properties) {
return new HystrixYammerMetricsPublisherThreadPool(threadPoolKey, metrics, properties, metricsRegistry);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,320 @@
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.hystrix.contrib.yammermetricspublisherv3;

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.strategy.metrics.HystrixMetricsPublisherCommand;
import com.netflix.hystrix.util.HystrixRollingNumberEvent;

/**
* Implementation of {@link HystrixMetricsPublisherCommand} using Yammer Metrics (https://github.com/codahale/metrics)
*/
public class HystrixYammerMetricsPublisherCommand implements HystrixMetricsPublisherCommand {
private final HystrixCommandKey key;
private final HystrixCommandGroupKey commandGroupKey;
private final HystrixCommandMetrics metrics;
private final HystrixCircuitBreaker circuitBreaker;
private final HystrixCommandProperties properties;
private final MetricRegistry metricsRegistry;
private final String metricGroup;
private final String metricType;

public HystrixYammerMetricsPublisherCommand(HystrixCommandKey commandKey, HystrixCommandGroupKey commandGroupKey, HystrixCommandMetrics metrics, HystrixCircuitBreaker circuitBreaker, HystrixCommandProperties properties, MetricRegistry metricsRegistry) {
this.key = commandKey;
this.commandGroupKey = commandGroupKey;
this.metrics = metrics;
this.circuitBreaker = circuitBreaker;
this.properties = properties;
this.metricsRegistry = metricsRegistry;
this.metricGroup = "HystrixCommand";
this.metricType = key.name();
}

@Override
public void initialize() {
metricsRegistry.register(createMetricName("isCircuitBreakerOpen"), new Gauge<Boolean>() {
@Override
public Boolean getValue() {
return circuitBreaker.isOpen();
}
});

// allow monitor to know exactly at what point in time these stats are for so they can be plotted accurately
metricsRegistry.register(createMetricName("currentTime"), new Gauge<Long>() {
@Override
public Long getValue() {
return System.currentTimeMillis();
}
});

// cumulative counts
createCumulativeCountForEvent("countCollapsedRequests", HystrixRollingNumberEvent.COLLAPSED);
createCumulativeCountForEvent("countExceptionsThrown", HystrixRollingNumberEvent.EXCEPTION_THROWN);
createCumulativeCountForEvent("countFailure", HystrixRollingNumberEvent.FAILURE);
createCumulativeCountForEvent("countFallbackFailure", HystrixRollingNumberEvent.FALLBACK_FAILURE);
createCumulativeCountForEvent("countFallbackRejection", HystrixRollingNumberEvent.FALLBACK_REJECTION);
createCumulativeCountForEvent("countFallbackSuccess", HystrixRollingNumberEvent.FALLBACK_SUCCESS);
createCumulativeCountForEvent("countResponsesFromCache", HystrixRollingNumberEvent.RESPONSE_FROM_CACHE);
createCumulativeCountForEvent("countSemaphoreRejected", HystrixRollingNumberEvent.SEMAPHORE_REJECTED);
createCumulativeCountForEvent("countShortCircuited", HystrixRollingNumberEvent.SHORT_CIRCUITED);
createCumulativeCountForEvent("countSuccess", HystrixRollingNumberEvent.SUCCESS);
createCumulativeCountForEvent("countThreadPoolRejected", HystrixRollingNumberEvent.THREAD_POOL_REJECTED);
createCumulativeCountForEvent("countTimeout", HystrixRollingNumberEvent.TIMEOUT);

// rolling counts
createRollingCountForEvent("rollingCountCollapsedRequests", HystrixRollingNumberEvent.COLLAPSED);
createRollingCountForEvent("rollingCountExceptionsThrown", HystrixRollingNumberEvent.EXCEPTION_THROWN);
createRollingCountForEvent("rollingCountFailure", HystrixRollingNumberEvent.FAILURE);
createRollingCountForEvent("rollingCountFallbackFailure", HystrixRollingNumberEvent.FALLBACK_FAILURE);
createRollingCountForEvent("rollingCountFallbackRejection", HystrixRollingNumberEvent.FALLBACK_REJECTION);
createRollingCountForEvent("rollingCountFallbackSuccess", HystrixRollingNumberEvent.FALLBACK_SUCCESS);
createRollingCountForEvent("rollingCountResponsesFromCache", HystrixRollingNumberEvent.RESPONSE_FROM_CACHE);
createRollingCountForEvent("rollingCountSemaphoreRejected", HystrixRollingNumberEvent.SEMAPHORE_REJECTED);
createRollingCountForEvent("rollingCountShortCircuited", HystrixRollingNumberEvent.SHORT_CIRCUITED);
createRollingCountForEvent("rollingCountSuccess", HystrixRollingNumberEvent.SUCCESS);
createRollingCountForEvent("rollingCountThreadPoolRejected", HystrixRollingNumberEvent.THREAD_POOL_REJECTED);
createRollingCountForEvent("rollingCountTimeout", HystrixRollingNumberEvent.TIMEOUT);

// the number of executionSemaphorePermits in use right now
metricsRegistry.register(createMetricName("executionSemaphorePermitsInUse"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getCurrentConcurrentExecutionCount();
}
});

// error percentage derived from current metrics
metricsRegistry.register(createMetricName("errorPercentage"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getHealthCounts().getErrorPercentage();
}
});

// latency metrics
metricsRegistry.register(createMetricName("latencyExecute_mean"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getExecutionTimeMean();
}
});
metricsRegistry.register(createMetricName("latencyExecute_percentile_5"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getExecutionTimePercentile(5);
}
});
metricsRegistry.register(createMetricName("latencyExecute_percentile_25"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getExecutionTimePercentile(25);
}
});
metricsRegistry.register(createMetricName("latencyExecute_percentile_50"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getExecutionTimePercentile(50);
}
});
metricsRegistry.register(createMetricName("latencyExecute_percentile_75"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getExecutionTimePercentile(75);
}
});
metricsRegistry.register(createMetricName("latencyExecute_percentile_90"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getExecutionTimePercentile(90);
}
});
metricsRegistry.register(createMetricName("latencyExecute_percentile_99"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getExecutionTimePercentile(99);
}
});
metricsRegistry.register(createMetricName("latencyExecute_percentile_995"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getExecutionTimePercentile(99.5);
}
});

metricsRegistry.register(createMetricName("latencyTotal_mean"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getTotalTimeMean();
}
});
metricsRegistry.register(createMetricName("latencyTotal_percentile_5"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getTotalTimePercentile(5);
}
});
metricsRegistry.register(createMetricName("latencyTotal_percentile_25"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getTotalTimePercentile(25);
}
});
metricsRegistry.register(createMetricName("latencyTotal_percentile_50"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getTotalTimePercentile(50);
}
});
metricsRegistry.register(createMetricName("latencyTotal_percentile_75"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getTotalTimePercentile(75);
}
});
metricsRegistry.register(createMetricName("latencyTotal_percentile_90"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getTotalTimePercentile(90);
}
});
metricsRegistry.register(createMetricName("latencyTotal_percentile_99"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getTotalTimePercentile(99);
}
});
metricsRegistry.register(createMetricName("latencyTotal_percentile_995"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return metrics.getTotalTimePercentile(99.5);
}
});

// group
metricsRegistry.register(createMetricName("commandGroup"), new Gauge<String>() {
@Override
public String getValue() {
return commandGroupKey != null ? commandGroupKey.name() : null;
}
});

// properties (so the values can be inspected and monitored)
metricsRegistry.register(createMetricName("propertyValue_rollingStatisticalWindowInMilliseconds"), new Gauge<Number>() {
@Override
public Number getValue() {
return properties.metricsRollingStatisticalWindowInMilliseconds().get();
}
});
metricsRegistry.register(createMetricName("propertyValue_circuitBreakerRequestVolumeThreshold"), new Gauge<Number>() {
@Override
public Number getValue() {
return properties.circuitBreakerRequestVolumeThreshold().get();
}
});
metricsRegistry.register(createMetricName("propertyValue_circuitBreakerSleepWindowInMilliseconds"), new Gauge<Number>() {
@Override
public Number getValue() {
return properties.circuitBreakerSleepWindowInMilliseconds().get();
}
});
metricsRegistry.register(createMetricName("propertyValue_circuitBreakerErrorThresholdPercentage"), new Gauge<Number>() {
@Override
public Number getValue() {
return properties.circuitBreakerErrorThresholdPercentage().get();
}
});
metricsRegistry.register(createMetricName("propertyValue_circuitBreakerForceOpen"), new Gauge<Boolean>() {
@Override
public Boolean getValue() {
return properties.circuitBreakerForceOpen().get();
}
});
metricsRegistry.register(createMetricName("propertyValue_circuitBreakerForceClosed"), new Gauge<Boolean>() {
@Override
public Boolean getValue() {
return properties.circuitBreakerForceClosed().get();
}
});
metricsRegistry.register(createMetricName("propertyValue_executionIsolationThreadTimeoutInMilliseconds"), new Gauge<Number>() {
@Override
public Number getValue() {
return properties.executionIsolationThreadTimeoutInMilliseconds().get();
}
});
metricsRegistry.register(createMetricName("propertyValue_executionIsolationStrategy"), new Gauge<String>() {
@Override
public String getValue() {
return properties.executionIsolationStrategy().get().name();
}
});
metricsRegistry.register(createMetricName("propertyValue_metricsRollingPercentileEnabled"), new Gauge<Boolean>() {
@Override
public Boolean getValue() {
return properties.metricsRollingPercentileEnabled().get();
}
});
metricsRegistry.register(createMetricName("propertyValue_requestCacheEnabled"), new Gauge<Boolean>() {
@Override
public Boolean getValue() {
return properties.requestCacheEnabled().get();
}
});
metricsRegistry.register(createMetricName("propertyValue_requestLogEnabled"), new Gauge<Boolean>() {
@Override
public Boolean getValue() {
return properties.requestLogEnabled().get();
}
});
metricsRegistry.register(createMetricName("propertyValue_executionIsolationSemaphoreMaxConcurrentRequests"), new Gauge<Number>() {
@Override
public Number getValue() {
return properties.executionIsolationSemaphoreMaxConcurrentRequests().get();
}
});
metricsRegistry.register(createMetricName("propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests"), new Gauge<Number>() {
@Override
public Number getValue() {
return properties.fallbackIsolationSemaphoreMaxConcurrentRequests().get();
}
});
}

protected String createMetricName(String name) {
return MetricRegistry.name(metricGroup, metricType, name);
}

protected void createCumulativeCountForEvent(String name, final HystrixRollingNumberEvent event) {
metricsRegistry.register(createMetricName(name), new Gauge<Long>() {
@Override
public Long getValue() {
return metrics.getCumulativeCount(event);
}
});
}

protected void createRollingCountForEvent(String name, final HystrixRollingNumberEvent event) {
metricsRegistry.register(createMetricName(name), new Gauge<Long>() {
@Override
public Long getValue() {
return metrics.getRollingCount(event);
}
});
}
}
Loading