Skip to content

Commit

Permalink
Issue ReactiveX#72: Created a resilience4j-metrics module for Dropwiz…
Browse files Browse the repository at this point in the history
…ard metri… (ReactiveX#80)

Issue ReactiveX#72: Created a resilience4j-metrics module for Dropwizard metrics and moved the Stopwatch class into a new resilience4j-core module.
  • Loading branch information
RobWin authored Mar 30, 2017
1 parent debb93f commit e84a012
Show file tree
Hide file tree
Showing 16 changed files with 569 additions and 23 deletions.
11 changes: 7 additions & 4 deletions libraries.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,26 @@ ext {
powermock_api_mockito: "org.powermock:powermock-api-mockito:${powermockVersion}",
powermock_module_junit4: "org.powermock:powermock-module-junit4:${powermockVersion}",
awaitility: "com.jayway.awaitility:awaitility:${awaitilityVersion}",
// vert.x addon

// Vert.x addon
vertx: "io.vertx:vertx-core:${vertxVersion}",
vertx_unit: "io.vertx:vertx-unit:${vertxVersion}",

// spring boot addon
// Spring Boot addon
spring_boot_aop: "org.springframework.boot:spring-boot-starter-aop:${springBootVersion}",
spring_boot_actuator: "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}",
spring_boot_web: "org.springframework.boot:spring-boot-starter-web:${springBootVersion}",
spring_boot_test: "org.springframework.boot:spring-boot-starter-test:${springBootVersion}",

// retrofit addon
// Retrofit addon
retrofit: "com.squareup.retrofit2:retrofit:${retrofitVersion}",
retrofit_test: "com.squareup.retrofit2:converter-scalars:${retrofitVersion}",
retrofit_wiremock: "com.github.tomakehurst:wiremock:1.58",

// circuitbreaker documentation
// Metrics addon
metrics: "io.dropwizard.metrics:metrics-core:${metricsVersion}",

// CircuitBreaker documentation
metrics_healthcheck: "io.dropwizard.metrics:metrics-healthchecks:${metricsVersion}"
]
}
2 changes: 1 addition & 1 deletion resilience4j-all/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'me.champeau.gradle.jmh'

dependencies {
compile project(':resilience4j-core')
compile project(':resilience4j-ratelimiter')
compile project(':resilience4j-circularbuffer')
compile project(':resilience4j-circuitbreaker')
compile project(':resilience4j-retry')
compile project(':resilience4j-metrics')
compile project(':resilience4j-consumer')
compile project(':resilience4j-cache')
testCompile project(':resilience4j-test')
Expand Down
2 changes: 1 addition & 1 deletion resilience4j-circuitbreaker/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'jcstress'

dependencies {
compile project(':resilience4j-metrics')
compile project(':resilience4j-core')
compile ( libraries.rxjava2)
testCompile project(':resilience4j-test')
testCompile ( libraries.metrics_healthcheck)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright 2016 Robert Winkler
* Copyright 2017: Robert Winkler
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,7 @@
import io.github.resilience4j.circuitbreaker.event.CircuitBreakerEvent;
import io.github.resilience4j.circuitbreaker.internal.CircuitBreakerStateMachine;
import io.github.resilience4j.circuitbreaker.utils.CircuitBreakerUtils;
import io.github.resilience4j.metrics.StopWatch;
import io.github.resilience4j.core.StopWatch;
import io.reactivex.Flowable;
import javaslang.control.Try;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright 2016 Robert Winkler
* Copyright 2017: Robert Winkler
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,7 +28,7 @@

import io.github.resilience4j.circuitbreaker.CircuitBreaker;
import io.github.resilience4j.circuitbreaker.CircuitBreakerOpenException;
import io.github.resilience4j.metrics.StopWatch;
import io.github.resilience4j.core.StopWatch;
import io.reactivex.FlowableOperator;
import io.reactivex.ObservableOperator;
import io.reactivex.Observer;
Expand Down
Empty file added resilience4j-core/build.gradle
Empty file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright 2016 Robert Winkler
* Copyright 2017: Robert Winkler
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,7 @@
*
*
*/
package io.github.resilience4j.metrics;
package io.github.resilience4j.core;

import java.time.Duration;

Expand All @@ -26,7 +26,7 @@
public class StopWatch {

private final String id;
private long startTime;
private final long startTime;
private long elapsedTime;

private StopWatch(String id){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright 2016 Robert Winkler
* Copyright 2017: Robert Winkler
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,7 @@
*
*
*/
package io.github.resilience4j.metrics;
package io.github.resilience4j.core;

import org.assertj.core.api.Assertions;
import org.junit.Test;
Expand Down
4 changes: 4 additions & 0 deletions resilience4j-metrics/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
compile (libraries.metrics)
testCompile project(':resilience4j-test')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
*
* Copyright 2017: Robert Winkler
*
* 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 io.github.resilience4j.metrics;

import com.codahale.metrics.Timer;

import java.util.function.Function;
import java.util.function.Supplier;

import javaslang.control.Try;

public interface Metrics {

/**
* Creates a timed checked supplier.
* @param timer the timer to use
* @param supplier the original supplier
* @return a timed supplier
*/
static <T> Try.CheckedSupplier<T> decorateCheckedSupplier(Timer timer, Try.CheckedSupplier<T> supplier){
return () -> {
try (Timer.Context context = timer.time()) {
return supplier.get();
}
};
}

/**
* Creates a timed runnable.
* @param timer the timer to use
* @param runnable the original runnable
* @return a timed runnable
*/
static Try.CheckedRunnable decorateCheckedRunnable(Timer timer, Try.CheckedRunnable runnable){
return () -> {
try (Timer.Context context = timer.time()) {
runnable.run();
}
};
}

/**
* Creates a timed checked supplier.
* @param timer the timer to use
* @param supplier the original supplier
* @return a timed supplier
*/
static <T> Supplier<T> decorateSupplier(Timer timer, Supplier<T> supplier){
return () -> {
try (Timer.Context context = timer.time()) {
return supplier.get();
}
};
}

/**
* Creates a timed runnable.
* @param timer the timer to use
* @param runnable the original runnable
* @return a timed runnable
*/
static Runnable decorateRunnable(Timer timer, Runnable runnable){
return () -> {
try (Timer.Context context = timer.time()) {
runnable.run();
}
};
}


/**
* Creates a timed function.
* @param timer the timer to use
* @param function the original function
* @return a timed function
*/
static <T, R> Function<T, R> decorateFunction(Timer timer, Function<T, R> function){
return (T t) -> {
try (Timer.Context context = timer.time()) {
return function.apply(t);
}
};
}

/**
* Creates a timed function.
* @param timer the timer to use
* @param function the original function
* @return a timed function
*/
static <T, R> Try.CheckedFunction<T, R> decorateCheckedFunction(Timer timer, Try.CheckedFunction<T, R> function){
return (T t) -> {
try (Timer.Context context = timer.time()) {
return function.apply(t);
}
};
}
}
Loading

0 comments on commit e84a012

Please sign in to comment.