Skip to content

Commit

Permalink
Merge branch '2.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
spencergibb committed Oct 5, 2018
2 parents a55470b + e814cda commit 8ac4137
Show file tree
Hide file tree
Showing 20 changed files with 271 additions and 43 deletions.
34 changes: 33 additions & 1 deletion docs/src/main/asciidoc/spring-cloud-netflix.adoc
Expand Up @@ -453,6 +453,38 @@ In fact, the `eureka.instance.hostname` is not needed if you are running on a ma
You can add multiple peers to a system, and, as long as they are all connected to each other by at least one edge, they synchronize
the registrations amongst themselves.
If the peers are physically separated (inside a data center or between multiple data centers), then the system can, in principle, survive "`split-brain`" type failures.
You can add multiple peers to a system, and as long as they are all
directly connected to each other, they will synchronize
the registrations amongst themselves.

.application.yml (Three Peer Aware Eureka Servers)
----
eureka:
client:
serviceUrl:
defaultZone: http://peer1/eureka/,http://peer2/eureka/,http://peer3/eureka/
---
spring:
profiles: peer1
eureka:
instance:
hostname: peer1
---
spring:
profiles: peer2
eureka:
instance:
hostname: peer2
---
spring:
profiles: peer3
eureka:
instance:
hostname: peer3
----

[[spring-cloud-eureka-server-prefer-ip-address]]
=== When to Prefer IP Address
Expand Down Expand Up @@ -1925,7 +1957,7 @@ It should return a JSON document that resembles the following:
}
----

HThe following application.yml example shows sample configuration for a Sidecar application:
The following application.yml example shows sample configuration for a Sidecar application:

.application.yml
[source,yaml]
Expand Down
@@ -0,0 +1,10 @@
{
"properties": [
{
"defaultValue": "true",
"name": "archaius.propagate.environmentChangedEvent",
"description": "Propagates EnvironmentChanged events to Archaius ConfigurationManager.",
"type": "java.lang.Boolean"
}
]
}
Expand Up @@ -48,7 +48,7 @@ public static class PublisherBuilder<T> {
private final Publisher<T> publisher;
private String commandName;
private String groupName;
private Publisher<T> fallback;
private Function<Throwable, Publisher<T>> fallback;
private Setter setter;
private HystrixCommandProperties.Setter commandProperties;
private boolean eager = false;
Expand All @@ -69,6 +69,11 @@ public PublisherBuilder<T> groupName(String groupName) {
}

public PublisherBuilder<T> fallback(Publisher<T> fallback) {
this.fallback = throwable -> fallback;
return this;
}

public PublisherBuilder<T> fallback(Function<Throwable, Publisher<T>> fallback) {
this.fallback = fallback;
return this;
}
Expand Down Expand Up @@ -166,10 +171,10 @@ public Mono<T> toMono() {
private static class PublisherHystrixCommand<T> extends HystrixObservableCommand<T> {

private Publisher<T> publisher;
private Publisher<T> fallback;
private Function<Throwable, Publisher<T>> fallback;

protected PublisherHystrixCommand(Setter setter, Publisher<T> publisher,
Publisher<T> fallback) {
Function<Throwable, Publisher<T>> fallback) {
super(setter);
this.publisher = publisher;
this.fallback = fallback;
Expand All @@ -183,7 +188,8 @@ protected Observable<T> construct() {
@Override
protected Observable<T> resumeWithFallback() {
if (this.fallback != null) {
return RxReactiveStreams.toObservable(this.fallback);
Publisher<T> fallbackPublisher = fallback.apply(getExecutionException());
return RxReactiveStreams.toObservable(fallbackPublisher);
}
return super.resumeWithFallback();
}
Expand Down
@@ -0,0 +1,16 @@
{
"properties": [
{
"defaultValue": "true",
"name": "management.metrics.binders.hystrix.enabled",
"description": "Enables creation of OK Http Client factory beans.",
"type": "java.lang.Boolean"
},
{
"defaultValue": false,
"name": "hystrix.shareSecurityContext",
"description": "Enables auto-configuration of the Hystrix concurrency strategy plugin hook who will transfer the `SecurityContext` from your main thread to the one used by the Hystrix command.",
"type": "java.lang.Boolean"
}
]
}
Expand Up @@ -66,6 +66,21 @@ public void monoFallbackWorks() {
.verifyComplete();
}

@Test
public void monoFallbackWithExceptionWorks() {
StepVerifier.create(HystrixCommands.from(Mono.<String>error(new IllegalStateException()))
.commandName("failcmd")
.fallback(throwable -> {
if (throwable instanceof IllegalStateException) {
return Mono.just("specificfallback");
}
return Mono.just("genericfallback");
})
.toMono())
.expectNext("specificfallback")
.verifyComplete();
}

@Test
public void fluxWorks() {
StepVerifier.create(HystrixCommands.from( Flux.just("1", "2"))
Expand Down
@@ -0,0 +1,16 @@
{
"properties": [
{
"defaultValue": true,
"name": "eureka.client.healthcheck.enabled",
"description": "Enables the Eureka health check handler.",
"type": "java.lang.Boolean"
},
{
"defaultValue": true,
"name": "ribbon.eureka.enabled",
"description": "Enables the use of Eureka with Ribbon.",
"type": "java.lang.Boolean"
}
]
}
@@ -0,0 +1,28 @@
{
"properties": [
{
"defaultValue": true,
"name": "eureka.client.healthcheck.enabled",
"description": "Enables the Eureka health check handler.",
"type": "java.lang.Boolean"
},
{
"defaultValue": false,
"name": "ribbon.restclient.enabled",
"description": "Enables the use of the deprecated Ribbon RestClient.",
"type": "java.lang.Boolean"
},
{
"defaultValue": false,
"name": "ribbon.http.client.enabled",
"description": "Deprecated property to enable Ribbon RestClient.",
"type": "java.lang.Boolean"
},
{
"defaultValue": false,
"name": "ribbon.okhttp.enabled",
"description": "Enables the use of the OK HTTP Client with Ribbon.",
"type": "java.lang.Boolean"
}
]
}
Expand Up @@ -142,9 +142,7 @@ protected static class NoActuatorConfiguration {

@Bean
public ProxyRequestHelper proxyRequestHelper(ZuulProperties zuulProperties) {
ProxyRequestHelper helper = new ProxyRequestHelper();
helper.setIgnoredHeaders(zuulProperties.getIgnoredHeaders());
helper.setTraceRequestBody(zuulProperties.isTraceRequestBody());
ProxyRequestHelper helper = new ProxyRequestHelper(zuulProperties);
return helper;
}

Expand Down Expand Up @@ -172,12 +170,10 @@ public FiltersEndpoint filtersEndpoint() {

@Bean
public ProxyRequestHelper proxyRequestHelper(ZuulProperties zuulProperties) {
TraceProxyRequestHelper helper = new TraceProxyRequestHelper();
TraceProxyRequestHelper helper = new TraceProxyRequestHelper(zuulProperties);
if (this.traces != null) {
helper.setTraces(this.traces);
}
helper.setIgnoredHeaders(zuulProperties.getIgnoredHeaders());
helper.setTraceRequestBody(zuulProperties.isTraceRequestBody());
return helper;
}
}
Expand Down
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -63,6 +64,10 @@ public class ProxyRequestHelper {
*/
public static final String IGNORED_HEADERS = "ignoredHeaders";

public static final Pattern FORM_FEED_PATTERN = Pattern.compile("\f");

public static final Pattern COLON_PATTERN = Pattern.compile(":");

private Set<String> ignoredHeaders = new LinkedHashSet<>();

private Set<String> sensitiveHeaders = new LinkedHashSet<>();
Expand All @@ -71,6 +76,18 @@ public class ProxyRequestHelper {

private boolean traceRequestBody = true;

private boolean addHostHeader = false;

@Deprecated
//TODO Remove in 2.1.x
public ProxyRequestHelper() {}

public ProxyRequestHelper(ZuulProperties zuulProperties) {
this.ignoredHeaders.addAll(zuulProperties.getIgnoredHeaders());
this.traceRequestBody = zuulProperties.isTraceRequestBody();
this.addHostHeader = zuulProperties.isAddHostHeader();
}

public void setWhitelistHosts(Set<String> whitelistHosts) {
this.whitelistHosts.addAll(whitelistHosts);
}
Expand All @@ -79,10 +96,14 @@ public void setSensitiveHeaders(Set<String> sensitiveHeaders) {
this.sensitiveHeaders.addAll(sensitiveHeaders);
}

@Deprecated
//TODO Remove in 2.1.x
public void setIgnoredHeaders(Set<String> ignoredHeaders) {
this.ignoredHeaders.addAll(ignoredHeaders);
}

@Deprecated
//TODO Remove in 2.1.x
public void setTraceRequestBody(boolean traceRequestBody) {
this.traceRequestBody = traceRequestBody;
}
Expand Down Expand Up @@ -208,6 +229,9 @@ public boolean isIncludedHeader(String headerName) {
}
switch (name) {
case "host":
if(addHostHeader) {
return true;
}
case "connection":
case "content-length":
case "server":
Expand Down Expand Up @@ -264,11 +288,11 @@ public String getQueryString(MultiValueMap<String, String> params) {
// if form feed is already part of param name double
// since form feed is used as the colon replacement below
if (key.contains("\f")) {
key = (key.replaceAll("\f", "\f\f"));
key = (FORM_FEED_PATTERN.matcher(key).replaceAll("\f\f"));
}
// colon is special to UriTemplate
if (key.contains(":")) {
key = key.replaceAll(":", "\f");
key = COLON_PATTERN.matcher(key).replaceAll("\f");
}
key = key + i;
singles.put(key, value);
Expand Down
Expand Up @@ -48,6 +48,15 @@
public class TraceProxyRequestHelper extends ProxyRequestHelper {

private HttpTraceRepository traces;

@Deprecated
//TODO Remove in 2.1.x
public TraceProxyRequestHelper(){}

public TraceProxyRequestHelper(ZuulProperties zuulProperties) {
super(zuulProperties);
}

private final HttpExchangeTracer tracer = new HttpExchangeTracer(
Include.defaultIncludes());

Expand Down
Expand Up @@ -21,6 +21,8 @@
*/
public class PatternServiceRouteMapper implements ServiceRouteMapper {

private static final Pattern MULTIPLE_SLASH_PATTERN = Pattern.compile("/{2,}");

/**
* A RegExp Pattern that extract needed information from a service ID. Ex :
* "(?<name>.*)-(?<version>v.*$)"
Expand Down Expand Up @@ -60,7 +62,7 @@ public String apply(String serviceId) {
* @return
*/
private String cleanRoute(final String route) {
String routeToClean = route.replaceAll("/{2,}", "/");
String routeToClean = MULTIPLE_SLASH_PATTERN.matcher(route).replaceAll("/");
if (routeToClean.startsWith("/")) {
routeToClean = routeToClean.substring(1);
}
Expand Down
Expand Up @@ -18,6 +18,7 @@

import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

Expand Down Expand Up @@ -70,6 +71,8 @@ public class PreDecorationFilter extends ZuulFilter {
@Deprecated
public static final int FILTER_ORDER = PRE_DECORATION_FILTER_ORDER;

public static final Pattern DOUBLE_SLASH = Pattern.compile("//");

private RouteLocator routeLocator;

private String dispatcherServletPath;
Expand Down Expand Up @@ -185,7 +188,7 @@ else if (!xforwardedfor.contains(remoteAddr)) { // Prevent duplicates
fallBackUri = "/" + fallBackUri;
}
String forwardURI = fallbackPrefix + fallBackUri;
forwardURI = forwardURI.replaceAll("//", "/");
forwardURI = DOUBLE_SLASH.matcher(forwardURI).replaceAll("/");
ctx.set(FORWARD_TO_KEY, forwardURI);
}
return null;
Expand Down
Expand Up @@ -78,6 +78,8 @@ public RibbonRoutingFilter(ProxyRequestHelper helper,
}
}

@Deprecated
//TODO Remove in 2.1.x
public RibbonRoutingFilter(RibbonCommandFactory<?> ribbonCommandFactory) {
this(new ProxyRequestHelper(), ribbonCommandFactory, null);
}
Expand Down
Expand Up @@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.Timer;
import java.util.TimerTask;

Expand Down Expand Up @@ -85,6 +86,8 @@ public class SimpleHostRoutingFilter extends ZuulFilter implements ApplicationLi

private static final Log log = LogFactory.getLog(SimpleHostRoutingFilter.class);

private static final Pattern MULTIPLE_SLASH_PATTERN = Pattern.compile("/{2,}");

private final Timer connectionManagerTimer = new Timer(
"SimpleHostRoutingFilter.connectionManagerTimer", true);

Expand Down Expand Up @@ -292,7 +295,7 @@ private CloseableHttpResponse forward(CloseableHttpClient httpclient, String ver
requestEntity);
URL host = RequestContext.getCurrentContext().getRouteHost();
HttpHost httpHost = getHttpHost(host);
uri = StringUtils.cleanPath((host.getPath() + uri).replaceAll("/{2,}", "/"));
uri = StringUtils.cleanPath(MULTIPLE_SLASH_PATTERN.matcher(host.getPath() + uri).replaceAll("/"));
long contentLength = getContentLength(request);

ContentType contentType = null;
Expand Down Expand Up @@ -455,4 +458,4 @@ protected long getContentLength(HttpServletRequest request) {
}
return request.getContentLength();
}
}
}

0 comments on commit 8ac4137

Please sign in to comment.