Search in sources :

Example 1 with HttpMethod

use of com.linkedin.d2.HttpMethod in project rest.li by linkedin.

the class RelativeStrategyPropertiesConverterTest method testRelativeStrategyPropertiesConverter.

@Test
public void testRelativeStrategyPropertiesConverter() {
    double upStep = 0.2;
    double downStep = 0.1;
    double relativeLatencyHighThresholdFactor = 1.5;
    double relativeLatencyLowThresholdFactor = 1.2;
    double highErrorRate = 0.2;
    double lowErrorRate = 0.1;
    int minCallCount = 1000;
    long updateIntervalMs = 5000;
    double initialHealthScore = 0.0;
    double slowStartThreshold = 0.32;
    HttpStatusCodeRangeArray errorStatusRange = new HttpStatusCodeRangeArray(new HttpStatusCodeRange().setLowerBound(500).setUpperBound(599));
    int emittingIntervalMs = 5000;
    double quarantineMaxPercent = 0.1;
    HttpMethod quarantineMethod = HttpMethod.OPTIONS;
    String healthCheckPath = "";
    int pointsPerWeight = 100;
    HashMethod hashMethod = HashMethod.URI_REGEX;
    StringArray regexes = new StringArray("+231{w+)");
    boolean failOnNoMatch = false;
    boolean warnOnNoMatch = true;
    double hashringPointCleanupRate = 0.2;
    ConsistentHashAlgorithm consistentHashAlgorithm = ConsistentHashAlgorithm.POINT_BASED;
    int numberOfProbes = 1024;
    int numberOfPointsPerHost = 1;
    double boundedLoadBalancingFactor = 1.5;
    D2QuarantineProperties quarantineProperties = new D2QuarantineProperties().setQuarantineMaxPercent(quarantineMaxPercent).setHealthCheckMethod(quarantineMethod).setHealthCheckPath(healthCheckPath);
    HashConfig hashConfig = new HashConfig().setFailOnNoMatch(failOnNoMatch).setUriRegexes(regexes).setWarnOnNoMatch(warnOnNoMatch);
    D2RingProperties ringProperties = new D2RingProperties().setHashRingPointCleanupRate(hashringPointCleanupRate).setBoundedLoadBalancingFactor(boundedLoadBalancingFactor).setConsistentHashAlgorithm(consistentHashAlgorithm).setHashConfig(hashConfig).setHashMethod(hashMethod).setPointsPerWeight(pointsPerWeight).setNumberOfProbes(numberOfProbes).setNumberOfPointsPerHost(numberOfPointsPerHost);
    D2RelativeStrategyProperties properties = new D2RelativeStrategyProperties().setQuarantineProperties(quarantineProperties).setRingProperties(ringProperties).setUpStep(upStep).setDownStep(downStep).setRelativeLatencyHighThresholdFactor(relativeLatencyHighThresholdFactor).setRelativeLatencyLowThresholdFactor(relativeLatencyLowThresholdFactor).setHighErrorRate(highErrorRate).setLowErrorRate(lowErrorRate).setMinCallCount(minCallCount).setUpdateIntervalMs(updateIntervalMs).setInitialHealthScore(initialHealthScore).setSlowStartThreshold(slowStartThreshold).setErrorStatusFilter(errorStatusRange).setEmittingIntervalMs(emittingIntervalMs);
    Map<String, Object> propertyMap = new HashMap<>();
    Map<String, Object> ringPropertyMap = new HashMap<>();
    Map<String, Object> quarantinePropertyMap = new HashMap<>();
    Map<String, Object> hashConfigMap = new HashMap<>();
    Map<String, String> errorStatusRangeMap = new HashMap<>();
    quarantinePropertyMap.put(PropertyKeys.QUARANTINE_MAX_PERCENT, String.valueOf(quarantineMaxPercent));
    quarantinePropertyMap.put(PropertyKeys.QUARANTINE_HEALTH_CHECK_METHOD, quarantineMethod.toString());
    quarantinePropertyMap.put(PropertyKeys.QUARANTINE_HEALTH_CHECK_PATH, healthCheckPath);
    hashConfigMap.put(URIRegexHash.KEY_REGEXES, new ArrayList<>(regexes));
    hashConfigMap.put(URIRegexHash.KEY_WARN_ON_NO_MATCH, String.valueOf(warnOnNoMatch));
    hashConfigMap.put(URIRegexHash.KEY_FAIL_ON_NO_MATCH, String.valueOf(failOnNoMatch));
    ringPropertyMap.put(PropertyKeys.RING_HASH_RING_POINT_CLEANUP_RATE, String.valueOf(hashringPointCleanupRate));
    ringPropertyMap.put(PropertyKeys.RING_BOUNDED_LOAD_BALANCING_FACTOR, String.valueOf(boundedLoadBalancingFactor));
    ringPropertyMap.put(PropertyKeys.RING_CONSISTENT_HASH_ALGORITHM, DelegatingRingFactory.POINT_BASED_CONSISTENT_HASH);
    ringPropertyMap.put(PropertyKeys.RING_HASH_CONFIG, hashConfigMap);
    ringPropertyMap.put(PropertyKeys.RING_HASH_METHOD, RelativeLoadBalancerStrategy.HASH_METHOD_URI_REGEX);
    ringPropertyMap.put(PropertyKeys.RING_POINTS_PER_WEIGHT, String.valueOf(pointsPerWeight));
    ringPropertyMap.put(PropertyKeys.RING_NUMBER_OF_PROBES, String.valueOf(numberOfProbes));
    ringPropertyMap.put(PropertyKeys.RING_NUMBER_OF_POINTS_PER_HOST, String.valueOf(numberOfPointsPerHost));
    errorStatusRangeMap.put(PropertyKeys.ERROR_STATUS_UPPER_BOUND, String.valueOf(errorStatusRange.get(0).getUpperBound()));
    errorStatusRangeMap.put(PropertyKeys.ERROR_STATUS_LOWER_BOUND, String.valueOf(errorStatusRange.get(0).getLowerBound()));
    propertyMap.put(PropertyKeys.QUARANTINE_PROPERTIES, quarantinePropertyMap);
    propertyMap.put(PropertyKeys.RING_PROPERTIES, ringPropertyMap);
    propertyMap.put(PropertyKeys.UP_STEP, String.valueOf(upStep));
    propertyMap.put(PropertyKeys.DOWN_STEP, String.valueOf(downStep));
    propertyMap.put(PropertyKeys.RELATIVE_LATENCY_HIGH_THRESHOLD_FACTOR, String.valueOf(relativeLatencyHighThresholdFactor));
    propertyMap.put(PropertyKeys.RELATIVE_LATENCY_LOW_THRESHOLD_FACTOR, String.valueOf(relativeLatencyLowThresholdFactor));
    propertyMap.put(PropertyKeys.HIGH_ERROR_RATE, String.valueOf(highErrorRate));
    propertyMap.put(PropertyKeys.LOW_ERROR_RATE, String.valueOf(lowErrorRate));
    propertyMap.put(PropertyKeys.MIN_CALL_COUNT, String.valueOf(minCallCount));
    propertyMap.put(PropertyKeys.UPDATE_INTERVAL_MS, String.valueOf(updateIntervalMs));
    propertyMap.put(PropertyKeys.INITIAL_HEALTH_SCORE, String.valueOf(initialHealthScore));
    propertyMap.put(PropertyKeys.SLOW_START_THRESHOLD, String.valueOf(slowStartThreshold));
    propertyMap.put(PropertyKeys.ERROR_STATUS_FILTER, Arrays.asList(errorStatusRangeMap));
    propertyMap.put(PropertyKeys.EMITTING_INTERVAL_MS, String.valueOf(emittingIntervalMs));
    Assert.assertEquals(RelativeStrategyPropertiesConverter.toMap(properties), propertyMap);
    Assert.assertEquals(RelativeStrategyPropertiesConverter.toProperties(propertyMap), properties);
}
Also used : HashMethod(com.linkedin.d2.HashMethod) HashMap(java.util.HashMap) HttpStatusCodeRange(com.linkedin.d2.HttpStatusCodeRange) HttpStatusCodeRangeArray(com.linkedin.d2.HttpStatusCodeRangeArray) D2RingProperties(com.linkedin.d2.D2RingProperties) D2QuarantineProperties(com.linkedin.d2.D2QuarantineProperties) StringArray(com.linkedin.data.template.StringArray) ConsistentHashAlgorithm(com.linkedin.d2.ConsistentHashAlgorithm) HashConfig(com.linkedin.d2.HashConfig) HttpMethod(com.linkedin.d2.HttpMethod) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties) Test(org.testng.annotations.Test)

Example 2 with HttpMethod

use of com.linkedin.d2.HttpMethod in project rest.li by linkedin.

the class ServicePropertiesSerializerTest method createRelativeStrategyProperties.

private D2RelativeStrategyProperties createRelativeStrategyProperties() {
    double upStep = 0.2;
    double downStep = 0.1;
    double relativeLatencyHighThresholdFactor = 1.5;
    double relativeLatencyLowThresholdFactor = 1.2;
    double highErrorRate = 0.2;
    double lowErrorRate = 0.1;
    int minCallCount = 1000;
    long updateIntervalMs = 5000;
    double initialHealthScore = 0.0;
    double slowStartThreshold = 0.32;
    HttpStatusCodeRangeArray errorStatusRange = new HttpStatusCodeRangeArray(new HttpStatusCodeRange().setLowerBound(500).setUpperBound(599));
    double quarantineMaxPercent = 0.1;
    HttpMethod quarantineMethod = HttpMethod.OPTIONS;
    String healthCheckPath = "";
    ConsistentHashAlgorithm consistentHashAlgorithm = ConsistentHashAlgorithm.POINT_BASED;
    D2QuarantineProperties quarantineProperties = new D2QuarantineProperties().setQuarantineMaxPercent(quarantineMaxPercent).setHealthCheckMethod(quarantineMethod).setHealthCheckPath(healthCheckPath);
    D2RingProperties ringProperties = new D2RingProperties().setConsistentHashAlgorithm(consistentHashAlgorithm);
    return new D2RelativeStrategyProperties().setQuarantineProperties(quarantineProperties).setRingProperties(ringProperties).setUpStep(upStep).setDownStep(downStep).setRelativeLatencyHighThresholdFactor(relativeLatencyHighThresholdFactor).setRelativeLatencyLowThresholdFactor(relativeLatencyLowThresholdFactor).setHighErrorRate(highErrorRate).setLowErrorRate(lowErrorRate).setMinCallCount(minCallCount).setUpdateIntervalMs(updateIntervalMs).setInitialHealthScore(initialHealthScore).setSlowStartThreshold(slowStartThreshold).setErrorStatusFilter(errorStatusRange);
}
Also used : D2QuarantineProperties(com.linkedin.d2.D2QuarantineProperties) ConsistentHashAlgorithm(com.linkedin.d2.ConsistentHashAlgorithm) HttpStatusCodeRange(com.linkedin.d2.HttpStatusCodeRange) HttpStatusCodeRangeArray(com.linkedin.d2.HttpStatusCodeRangeArray) D2RingProperties(com.linkedin.d2.D2RingProperties) HttpMethod(com.linkedin.d2.HttpMethod) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties)

Example 3 with HttpMethod

use of com.linkedin.d2.HttpMethod in project rest.li by linkedin.

the class TestDarkClusterManager method testBasic.

@Test(dataProvider = "provideKeys")
public void testBasic(String whitelist, String blacklist, String httpMethod, DarkGateKeeper darkGateKeeper, int expectedWhiteCount, int expectedBlackCount) {
    MockClusterInfoProvider clusterInfoProvider = new MockClusterInfoProvider();
    Facilities facilities = new MockFacilities(clusterInfoProvider);
    MockStrategyFactory strategyFactory = new MockStrategyFactory();
    DarkClusterManager darkClusterManager = new DarkClusterManagerImpl(SOURCE_CLUSTER_NAME, facilities, strategyFactory, whitelist, blacklist, new DoNothingNotifier(), darkGateKeeper);
    strategyFactory.start();
    // This configuration will choose the RelativeTrafficMultiplierDarkClusterStrategy
    DarkClusterConfig darkClusterConfig = createRelativeTrafficMultiplierConfig(1.0f);
    clusterInfoProvider.addDarkClusterConfig(SOURCE_CLUSTER_NAME, DARK_CLUSTER_NAME, darkClusterConfig);
    RestRequest restRequest1 = new RestRequestBuilder(URI.create("/white")).setMethod(httpMethod).build();
    boolean whiteStatus = darkClusterManager.handleDarkRequest(restRequest1, new RequestContext());
    RestRequest restRequest2 = new RestRequestBuilder(URI.create("/black")).setMethod(httpMethod).build();
    boolean blackStatus = darkClusterManager.handleDarkRequest(restRequest2, new RequestContext());
    Assert.assertEquals(whiteStatus, expectedWhiteCount > 0, "white uri requests not as expected");
    Assert.assertEquals(blackStatus, expectedBlackCount > 0, "black uri requests not as expected");
    Assert.assertEquals(strategyFactory.strategyGetOrCreateCount, expectedWhiteCount + expectedBlackCount, "unexpected strategy GetOrCreateCount");
}
Also used : RestRequest(com.linkedin.r2.message.rest.RestRequest) DarkClusterConfig(com.linkedin.d2.DarkClusterConfig) DarkClusterManagerImpl(com.linkedin.darkcluster.impl.DarkClusterManagerImpl) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext) DarkClusterManager(com.linkedin.darkcluster.api.DarkClusterManager) Facilities(com.linkedin.d2.balancer.Facilities) Test(org.testng.annotations.Test)

Aggregations

ConsistentHashAlgorithm (com.linkedin.d2.ConsistentHashAlgorithm)2 D2QuarantineProperties (com.linkedin.d2.D2QuarantineProperties)2 D2RelativeStrategyProperties (com.linkedin.d2.D2RelativeStrategyProperties)2 D2RingProperties (com.linkedin.d2.D2RingProperties)2 HttpMethod (com.linkedin.d2.HttpMethod)2 HttpStatusCodeRange (com.linkedin.d2.HttpStatusCodeRange)2 HttpStatusCodeRangeArray (com.linkedin.d2.HttpStatusCodeRangeArray)2 Test (org.testng.annotations.Test)2 DarkClusterConfig (com.linkedin.d2.DarkClusterConfig)1 HashConfig (com.linkedin.d2.HashConfig)1 HashMethod (com.linkedin.d2.HashMethod)1 Facilities (com.linkedin.d2.balancer.Facilities)1 DarkClusterManager (com.linkedin.darkcluster.api.DarkClusterManager)1 DarkClusterManagerImpl (com.linkedin.darkcluster.impl.DarkClusterManagerImpl)1 StringArray (com.linkedin.data.template.StringArray)1 RequestContext (com.linkedin.r2.message.RequestContext)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)1 HashMap (java.util.HashMap)1