use of com.linkedin.d2.DarkClusterConfigMap in project rest.li by linkedin.
the class SimpleLoadBalancerTest method testClusterInfoProviderGetDarkClusters.
@Test
public void testClusterInfoProviderGetDarkClusters() throws InterruptedException, ExecutionException, ServiceUnavailableException {
int numHttp = 3;
int numHttps = 4;
int partitionIdForAdd = 0;
MockStore<ServiceProperties> serviceRegistry = new MockStore<>();
MockStore<ClusterProperties> clusterRegistry = new MockStore<>();
MockStore<UriProperties> uriRegistry = new MockStore<>();
SimpleLoadBalancer loadBalancer = setupLoadBalancer(null, serviceRegistry, clusterRegistry, uriRegistry);
DarkClusterConfig darkClusterConfig = new DarkClusterConfig().setMultiplier(1.0f).setDispatcherOutboundTargetRate(1).setDispatcherMaxRequestsToBuffer(1).setDispatcherBufferedRequestExpiryInSeconds(1);
DarkClusterConfigMap darkClusterConfigMap = new DarkClusterConfigMap();
darkClusterConfigMap.put(DARK_CLUSTER1_NAME, darkClusterConfig);
clusterRegistry.put(CLUSTER1_NAME, new ClusterProperties(CLUSTER1_NAME, Collections.emptyList(), Collections.emptyMap(), Collections.emptySet(), NullPartitionProperties.getInstance(), Collections.emptyList(), DarkClustersConverter.toProperties(darkClusterConfigMap), false));
populateUriRegistry(numHttp, numHttps, partitionIdForAdd, uriRegistry);
loadBalancer.getDarkClusterConfigMap(CLUSTER1_NAME, new Callback<DarkClusterConfigMap>() {
@Override
public void onError(Throwable e) {
Assert.fail("getDarkClusterConfigMap threw exception", e);
}
@Override
public void onSuccess(DarkClusterConfigMap returnedDarkClusterConfigMap) {
Assert.assertEquals(returnedDarkClusterConfigMap, darkClusterConfigMap, "dark cluster configs should be equal");
Assert.assertEquals(returnedDarkClusterConfigMap.get(DARK_CLUSTER1_NAME).getMultiplier(), 1.0f, "multiplier should match");
}
});
}
use of com.linkedin.d2.DarkClusterConfigMap in project rest.li by linkedin.
the class DarkClusterManagerImpl method handleDarkRequest.
@Override
public boolean handleDarkRequest(RestRequest originalRequest, RequestContext originalRequestContext) {
String uri = originalRequest.getURI().toString();
boolean darkRequestSent = false;
try {
final boolean whiteListed = _whiteListRegEx != null && _whiteListRegEx.matcher(uri).matches();
final boolean blackedListed = _blackListRegEx != null && _blackListRegEx.matcher(uri).matches();
// 4) custom dark gatekeeper returns true for the given request and requestContext
if ((isSafe(originalRequest) || whiteListed) && !blackedListed) {
// the request is already immutable, and a new requestContext will be created in BaseDarkClusterDispatcher.
// We don't need to copy them here, but doing it just for safety.
RestRequest reqCopy = originalRequest.builder().build();
RequestContext newRequestContext = new RequestContext(originalRequestContext);
DarkClusterConfigMap configMap = _facilities.getClusterInfoProvider().getDarkClusterConfigMap(_sourceClusterName);
for (String darkClusterName : configMap.keySet()) {
if (_darkGateKeeper.shouldDispatchToDark(originalRequest, originalRequestContext, darkClusterName)) {
RestRequest newD2Request = rewriteRequest(reqCopy, darkClusterName);
// now find the strategy appropriate for each dark cluster
DarkClusterStrategy strategy = _darkClusterStrategyFactory.get(darkClusterName);
darkRequestSent = strategy.handleRequest(reqCopy, newD2Request, newRequestContext);
}
}
}
} catch (Throwable e) {
_notifier.notify(() -> new RuntimeException("DarkCanaryDispatcherFilter failed to send request: " + uri, e));
}
return darkRequestSent;
}
use of com.linkedin.d2.DarkClusterConfigMap in project rest.li by linkedin.
the class MockClusterInfoProvider method removeDarkClusterConfig.
void removeDarkClusterConfig(String sourceClusterName, String darkClusterName) {
DarkClusterConfigMap darkClusterConfigMap = (lookupMap.containsKey(sourceClusterName)) ? lookupMap.get(sourceClusterName) : new DarkClusterConfigMap();
darkClusterConfigMap.remove(darkClusterName);
lookupMap.put(sourceClusterName, darkClusterConfigMap);
}
use of com.linkedin.d2.DarkClusterConfigMap in project rest.li by linkedin.
the class SimpleLoadBalancerTest method testClusterInfoProviderGetDarkClustersNoUris.
@Test
public void testClusterInfoProviderGetDarkClustersNoUris() throws InterruptedException, ExecutionException, ServiceUnavailableException {
MockStore<ServiceProperties> serviceRegistry = new MockStore<>();
MockStore<ClusterProperties> clusterRegistry = new MockStore<>();
MockStore<UriProperties> uriRegistry = new MockStore<>();
SimpleLoadBalancer loadBalancer = setupLoadBalancer(null, serviceRegistry, clusterRegistry, uriRegistry);
DarkClusterConfig darkClusterConfig = new DarkClusterConfig().setMultiplier(1.0f).setDispatcherOutboundTargetRate(1).setDispatcherMaxRequestsToBuffer(1).setDispatcherBufferedRequestExpiryInSeconds(1);
DarkClusterConfigMap darkClusterConfigMap = new DarkClusterConfigMap();
darkClusterConfigMap.put(DARK_CLUSTER1_NAME, darkClusterConfig);
clusterRegistry.put(CLUSTER1_NAME, new ClusterProperties(CLUSTER1_NAME, Collections.emptyList(), Collections.emptyMap(), Collections.emptySet(), NullPartitionProperties.getInstance(), Collections.emptyList(), DarkClustersConverter.toProperties(darkClusterConfigMap), false));
loadBalancer.getDarkClusterConfigMap(CLUSTER1_NAME, new Callback<DarkClusterConfigMap>() {
@Override
public void onError(Throwable e) {
Assert.fail("getDarkClusterConfigMap threw exception", e);
}
@Override
public void onSuccess(DarkClusterConfigMap returnedDarkClusterConfigMap) {
Assert.assertEquals(returnedDarkClusterConfigMap, darkClusterConfigMap, "dark cluster configs should be equal");
Assert.assertEquals(returnedDarkClusterConfigMap.get(DARK_CLUSTER1_NAME).getMultiplier(), 1.0f, "multiplier should match");
}
});
}
use of com.linkedin.d2.DarkClusterConfigMap in project rest.li by linkedin.
the class MockClusterInfoProvider method addDarkClusterConfig.
/**
* add the ability to add a dark cluster to a source cluster's darkClusterConfigMap
*/
void addDarkClusterConfig(String sourceClusterName, String darkClusterName, DarkClusterConfig darkClusterConfig) {
DarkClusterConfigMap darkClusterConfigMap = (lookupMap.containsKey(sourceClusterName)) ? lookupMap.get(sourceClusterName) : new DarkClusterConfigMap();
darkClusterConfigMap.put(darkClusterName, darkClusterConfig);
lookupMap.put(sourceClusterName, darkClusterConfigMap);
}
Aggregations