-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unifying circuit breaker abstractions (#553)
* setup resilience4j * specifying circuit breaker strategy name * creating agnostic interface to support multiple circuit breaker strategy types * fixme * sppliting circuit breaker factory * refactoring is done * test is passing * test is passing * test is passing * refactoring package * [Gradle Release Plugin] - new version commit: '3.25.11-snapshot'. * release notes * [Gradle Release Plugin] - new version commit: '3.25.12-snapshot'. * release notes * fixme note * fixme note * refactoring to support multiple delegates * refactoring name * refactoring * implementing non resilient strategy * refactoring and test * removing unnecessary test * refactoring and fixing test * release notes * [Gradle Release Plugin] - new version commit: '3.25.13-snapshot'.
- Loading branch information
Showing
30 changed files
with
299 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version=3.25.12-snapshot | ||
version=3.25.13-snapshot |
11 changes: 0 additions & 11 deletions
11
src/main/java/com/mageddo/dnsproxyserver/config/CircuitBreakerStrategy.java
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
src/main/java/com/mageddo/dnsproxyserver/config/CircuitBreakerStrategyConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.mageddo.dnsproxyserver.config; | ||
|
||
import com.mageddo.dnsproxyserver.solver.remote.circuitbreaker.application.CircuitBreakerDelegateNonResilient; | ||
import com.mageddo.dnsproxyserver.solver.remote.circuitbreaker.application.CircuitBreakerDelegateStaticThresholdFailsafe; | ||
|
||
public interface CircuitBreakerStrategyConfig { | ||
|
||
Name name(); | ||
|
||
enum Name { | ||
/** | ||
* @see CircuitBreakerDelegateStaticThresholdFailsafe | ||
*/ | ||
STATIC_THRESHOLD, | ||
|
||
CANARY_RATE_THRESHOLD, | ||
|
||
/** | ||
* @see CircuitBreakerDelegateNonResilient | ||
*/ | ||
NON_RESILIENT, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...main/java/com/mageddo/dnsproxyserver/config/NonResilientCircuitBreakerStrategyConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.mageddo.dnsproxyserver.config; | ||
|
||
public class NonResilientCircuitBreakerStrategyConfig implements CircuitBreakerStrategyConfig { | ||
@Override | ||
public Name name() { | ||
return Name.NON_RESILIENT; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/java/com/mageddo/dnsproxyserver/config/validator/CircuitBreakerValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
...m/mageddo/dnsproxyserver/solver/remote/application/CircuitBreakerNonResilientService.java
This file was deleted.
Oops, something went wrong.
43 changes: 38 additions & 5 deletions
43
...main/java/com/mageddo/dnsproxyserver/solver/remote/application/CircuitBreakerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,49 @@ | ||
package com.mageddo.dnsproxyserver.solver.remote.application; | ||
|
||
import com.mageddo.commons.circuitbreaker.CircuitCheckException; | ||
import com.mageddo.commons.circuitbreaker.CircuitIsOpenException; | ||
import com.mageddo.dnsproxyserver.solver.remote.CircuitStatus; | ||
import com.mageddo.dnsproxyserver.solver.remote.Result; | ||
import com.mageddo.dnsproxyserver.solver.remote.application.failsafe.CircuitBreakerFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.ClassUtils; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import java.net.InetSocketAddress; | ||
import java.util.function.Supplier; | ||
|
||
public interface CircuitBreakerService { | ||
|
||
// fixme #533 esse padrão de strategy não é mais necessário aqui, foi movido para CircuitBreakerDelegate | ||
// onde tem mais chances de reduzir duplicação | ||
Result safeHandle(final InetSocketAddress resolverAddress, Supplier<Result> sup); | ||
@Slf4j | ||
@Singleton | ||
@RequiredArgsConstructor(onConstructor = @__({@Inject})) | ||
public class CircuitBreakerService { | ||
|
||
CircuitStatus findCircuitStatus(InetSocketAddress resolverAddress); | ||
private final CircuitBreakerFactory circuitBreakerFactory; | ||
|
||
private String status; | ||
|
||
public Result safeHandle(InetSocketAddress resolverAddress, Supplier<Result> sup) { | ||
try { | ||
return this.handle(resolverAddress, sup); | ||
} catch (CircuitCheckException | CircuitIsOpenException e) { | ||
final var clazz = ClassUtils.getSimpleName(e); | ||
log.debug("status=circuitEvent, server={}, type={}", resolverAddress, clazz); | ||
this.status = String.format("%s for %s", clazz, resolverAddress); | ||
return Result.empty(); | ||
} | ||
} | ||
|
||
private Result handle(InetSocketAddress resolverAddress, Supplier<Result> sup) { | ||
return this.circuitBreakerFactory.check(resolverAddress, sup); | ||
} | ||
|
||
public String getStatus() { | ||
return this.status; | ||
} | ||
|
||
public CircuitStatus findCircuitStatus(InetSocketAddress resolverAddress) { | ||
return this.circuitBreakerFactory.findStatus(resolverAddress); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.