use of com.linkedin.d2.D2QuarantineProperties in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testQuarantineRecovery.
@Test(dataProvider = "strategy")
public void testQuarantineRecovery(loadBalancerStrategyType type) {
Map<String, Object> strategyPropertiesWithQuarantineEnabled = new HashMap<>();
D2RelativeStrategyProperties relativePropertiesWithQuarantineEnabled = new D2RelativeStrategyProperties();
D2QuarantineProperties quarantineProperties = new D2QuarantineProperties().setQuarantineMaxPercent(DEFAULT_QUARANTINE_PERCENTAGE);
strategyPropertiesWithQuarantineEnabled.put(PropertyKeys.HTTP_LB_QUARANTINE_MAX_PERCENT, String.valueOf(DEFAULT_QUARANTINE_PERCENTAGE));
relativePropertiesWithQuarantineEnabled.setQuarantineProperties(quarantineProperties);
LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setConstantRequestCount(1000).setNumIntervals(40).setDynamicLatency(Arrays.asList(HOST_RECOVERING_TO_HEALTHY_LATENCY, HEALTHY_HOST_LATENCY_CORRELATION, HEALTHY_HOST_LATENCY_CORRELATION, HEALTHY_HOST_LATENCY_CORRELATION, HEALTHY_HOST_LATENCY_CORRELATION));
LoadBalancerStrategyTestRunner testRunner = type == loadBalancerStrategyType.DEGRADER ? builder.setDegraderStrategies(strategyPropertiesWithQuarantineEnabled, new HashMap<>()).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithQuarantineEnabled).build();
testRunner.runWait();
List<Integer> pointHistory = testRunner.getPointHistory().get(testRunner.getUri(0));
assertEquals(getLowestPoints(pointHistory), QUARANTINED_POINTS);
assertEquals(pointHistory.get(39).intValue(), HEALTHY_POINTS);
}
use of com.linkedin.d2.D2QuarantineProperties in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testStayQuarantined.
@Test(dataProvider = "strategy")
public void testStayQuarantined(loadBalancerStrategyType type) {
Map<String, Object> strategyPropertiesWithQuarantineEnabled = new HashMap<>();
D2RelativeStrategyProperties relativePropertiesWithQuarantineEnabled = new D2RelativeStrategyProperties();
D2QuarantineProperties quarantineProperties = new D2QuarantineProperties().setQuarantineMaxPercent(DEFAULT_QUARANTINE_PERCENTAGE);
strategyPropertiesWithQuarantineEnabled.put(PropertyKeys.HTTP_LB_QUARANTINE_MAX_PERCENT, String.valueOf(DEFAULT_QUARANTINE_PERCENTAGE));
relativePropertiesWithQuarantineEnabled.setQuarantineProperties(quarantineProperties);
LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setConstantRequestCount(1000).setNumIntervals(10).setConstantLatency(Arrays.asList(UNHEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY));
LoadBalancerStrategyTestRunner testRunner = type == loadBalancerStrategyType.DEGRADER ? builder.setDegraderStrategies(strategyPropertiesWithQuarantineEnabled, new HashMap<>()).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithQuarantineEnabled).build();
testRunner.runWait();
List<Integer> pointHistory = testRunner.getPointHistory().get(testRunner.getUri(0));
assertEquals(pointHistory.get(9).intValue(), QUARANTINED_POINTS);
}
use of com.linkedin.d2.D2QuarantineProperties in project rest.li by linkedin.
the class RelativeLoadBalancerStrategyFactory method putDefaultValues.
static D2RelativeStrategyProperties putDefaultValues(D2RelativeStrategyProperties properties) {
properties.setUpStep(getOrDefault(properties.getUpStep(), DEFAULT_UP_STEP));
properties.setDownStep(getOrDefault(properties.getDownStep(), DEFAULT_DOWN_STEP));
properties.setHighErrorRate(getOrDefault(properties.getHighErrorRate(), DEFAULT_HIGH_ERROR_RATE));
properties.setLowErrorRate(getOrDefault(properties.getLowErrorRate(), DEFAULT_LOW_ERROR_RATE));
properties.setRelativeLatencyHighThresholdFactor(getOrDefault(properties.getRelativeLatencyHighThresholdFactor(), DEFAULT_RELATIVE_LATENCY_HIGH_THRESHOLD_FACTOR));
properties.setRelativeLatencyLowThresholdFactor(getOrDefault(properties.getRelativeLatencyLowThresholdFactor(), DEFAULT_RELATIVE_LATENCY_LOW_THRESHOLD_FACTOR));
properties.setMinCallCount(getOrDefault(properties.getMinCallCount(), DEFAULT_MIN_CALL_COUNT));
properties.setUpdateIntervalMs(getOrDefault(properties.getUpdateIntervalMs(), DEFAULT_UPDATE_INTERVAL_MS));
properties.setInitialHealthScore(getOrDefault(properties.getInitialHealthScore(), DEFAULT_INITIAL_HEALTH_SCORE));
properties.setSlowStartThreshold(getOrDefault(properties.getSlowStartThreshold(), DEFAULT_SLOW_START_THRESHOLD));
properties.setErrorStatusFilter(getOrDefault(properties.getErrorStatusFilter(), DEFAULT_ERROR_STATUS_FILTER));
properties.setEmittingIntervalMs(getOrDefault(properties.getEmittingIntervalMs(), DEFAULT_EMITTING_INTERVAL_MS));
properties.setEnableFastRecovery(getOrDefault(properties.isEnableFastRecovery(), DEFAULT_ENABLE_FAST_RECOVERY));
D2QuarantineProperties quarantineProperties = properties.hasQuarantineProperties() ? properties.getQuarantineProperties() : new D2QuarantineProperties();
quarantineProperties.setQuarantineMaxPercent(getOrDefault(quarantineProperties.getQuarantineMaxPercent(), DEFAULT_QUARANTINE_MAX_PERCENT));
quarantineProperties.setHealthCheckMethod(getOrDefault(quarantineProperties.getHealthCheckMethod(), DEFAULT_HTTP_METHOD));
properties.setQuarantineProperties(quarantineProperties);
// Most ring properties are initialized in {@link DelegatingRingFactory}
D2RingProperties ringProperties = properties.hasRingProperties() ? properties.getRingProperties() : new D2RingProperties();
ringProperties.setPointsPerWeight(getOrDefault(ringProperties.getPointsPerWeight(), DEFAULT_POINTS_PER_WEIGHT));
properties.setRingProperties(ringProperties);
return properties;
}
use of com.linkedin.d2.D2QuarantineProperties in project rest.li by linkedin.
the class RelativeStrategyPropertiesConverter method toMap.
/**
* Convert {@link D2RelativeStrategyProperties} to Map
*
* @param properties relative strategy properties
* @return The converted key-value map
*/
public static Map<String, Object> toMap(D2RelativeStrategyProperties properties) {
if (properties == null) {
return Collections.emptyMap();
}
Map<String, Object> map = new HashMap<>();
if (properties.hasUpStep()) {
map.put(PropertyKeys.UP_STEP, properties.getUpStep().toString());
}
if (properties.hasDownStep()) {
map.put(PropertyKeys.DOWN_STEP, properties.getDownStep().toString());
}
if (properties.hasRelativeLatencyHighThresholdFactor()) {
map.put(PropertyKeys.RELATIVE_LATENCY_HIGH_THRESHOLD_FACTOR, properties.getRelativeLatencyHighThresholdFactor().toString());
}
if (properties.hasRelativeLatencyLowThresholdFactor()) {
map.put(PropertyKeys.RELATIVE_LATENCY_LOW_THRESHOLD_FACTOR, properties.getRelativeLatencyLowThresholdFactor().toString());
}
if (properties.hasHighErrorRate()) {
map.put(PropertyKeys.HIGH_ERROR_RATE, properties.getHighErrorRate().toString());
}
if (properties.hasLowErrorRate()) {
map.put(PropertyKeys.LOW_ERROR_RATE, properties.getLowErrorRate().toString());
}
if (properties.hasMinCallCount()) {
map.put(PropertyKeys.MIN_CALL_COUNT, properties.getMinCallCount().toString());
}
if (properties.hasUpdateIntervalMs()) {
map.put(PropertyKeys.UPDATE_INTERVAL_MS, properties.getUpdateIntervalMs().toString());
}
if (properties.hasInitialHealthScore()) {
map.put(PropertyKeys.INITIAL_HEALTH_SCORE, properties.getInitialHealthScore().toString());
}
if (properties.hasSlowStartThreshold()) {
map.put(PropertyKeys.SLOW_START_THRESHOLD, properties.getSlowStartThreshold().toString());
}
if (properties.hasEmittingIntervalMs()) {
map.put(PropertyKeys.EMITTING_INTERVAL_MS, properties.getEmittingIntervalMs().toString());
}
if (properties.hasEnableFastRecovery()) {
map.put(PropertyKeys.ENABLE_FAST_RECOVERY, properties.isEnableFastRecovery().toString());
}
if (properties.hasErrorStatusFilter()) {
List<Map<String, Object>> errorStatusFilterList = new ArrayList<>();
for (HttpStatusCodeRange errorStatusRange : properties.getErrorStatusFilter()) {
Map<String, Object> errorStatusFilterMap = new HashMap<>();
errorStatusFilterMap.put(PropertyKeys.ERROR_STATUS_LOWER_BOUND, errorStatusRange.getLowerBound().toString());
errorStatusFilterMap.put(PropertyKeys.ERROR_STATUS_UPPER_BOUND, errorStatusRange.getUpperBound().toString());
errorStatusFilterList.add(errorStatusFilterMap);
}
map.put(PropertyKeys.ERROR_STATUS_FILTER, errorStatusFilterList);
}
if (properties.hasQuarantineProperties()) {
D2QuarantineProperties quarantineProperties = properties.getQuarantineProperties();
Map<String, Object> quarantinePropertyMap = toQuarantinePropertyMap(quarantineProperties);
map.put(PropertyKeys.QUARANTINE_PROPERTIES, quarantinePropertyMap);
}
if (properties.hasRingProperties()) {
D2RingProperties ringProperties = properties.getRingProperties();
Map<String, Object> ringPropertyMap = toRingPropertyMap(ringProperties);
map.put(PropertyKeys.RING_PROPERTIES, ringPropertyMap);
}
return map;
}
Aggregations