Skip to content

Commit

Permalink
Outlier detection load balancer (#9447)
Browse files Browse the repository at this point in the history
New outlier detection load balancer.

Tracks all RPC results to the addresses it is configured with and periodically attempts
to detect outlier. It wraps a child load balancer from which it hides any addresses that
are deemed outliers.

As specified in gRFC A50: gRPC xDS Outlier Detection Support:
https://github.com/grpc/proposal/blob/master/A50-xds-outlier-detection.md
  • Loading branch information
temawi committed Aug 22, 2022
1 parent 0cd1ccb commit c7307ec
Show file tree
Hide file tree
Showing 8 changed files with 2,505 additions and 3 deletions.
32 changes: 32 additions & 0 deletions api/src/main/java/io/grpc/SynchronizationContext.java
Expand Up @@ -163,6 +163,38 @@ public String toString() {
return new ScheduledHandle(runnable, future);
}

/**
* Schedules a task to be added and run via {@link #execute} after an inital delay and then
* repeated after the delay until cancelled.
*
* @param task the task being scheduled
* @param initialDelay the delay before the first run
* @param delay the delay after the first run.
* @param unit the time unit for the delay
* @param timerService the {@code ScheduledExecutorService} that provides delayed execution
*
* @return an object for checking the status and/or cancel the scheduled task
*/
public final ScheduledHandle scheduleWithFixedDelay(
final Runnable task, long initialDelay, long delay, TimeUnit unit,
ScheduledExecutorService timerService) {
final ManagedRunnable runnable = new ManagedRunnable(task);
ScheduledFuture<?> future = timerService.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
execute(runnable);
}

@Override
public String toString() {
return task.toString() + "(scheduled in SynchronizationContext with delay of " + delay
+ ")";
}
}, initialDelay, delay, unit);
return new ScheduledHandle(runnable, future);
}


private static class ManagedRunnable implements Runnable {
final Runnable task;
boolean isCancelled;
Expand Down
8 changes: 7 additions & 1 deletion api/src/test/java/io/grpc/LoadBalancerRegistryTest.java
Expand Up @@ -41,7 +41,7 @@ public void getClassesViaHardcoded_classesPresent() throws Exception {
@Test
public void stockProviders() {
LoadBalancerRegistry defaultRegistry = LoadBalancerRegistry.getDefaultRegistry();
assertThat(defaultRegistry.providers()).hasSize(3);
assertThat(defaultRegistry.providers()).hasSize(4);

LoadBalancerProvider pickFirst = defaultRegistry.getProvider("pick_first");
assertThat(pickFirst).isInstanceOf(PickFirstLoadBalancerProvider.class);
Expand All @@ -52,6 +52,12 @@ public void stockProviders() {
"io.grpc.util.SecretRoundRobinLoadBalancerProvider$Provider");
assertThat(roundRobin.getPriority()).isEqualTo(5);

LoadBalancerProvider outlierDetection = defaultRegistry.getProvider(
"outlier_detection_experimental");
assertThat(outlierDetection.getClass().getName()).isEqualTo(
"io.grpc.util.OutlierDetectionLoadBalancerProvider");
assertThat(roundRobin.getPriority()).isEqualTo(5);

LoadBalancerProvider grpclb = defaultRegistry.getProvider("grpclb");
assertThat(grpclb).isInstanceOf(GrpclbLoadBalancerProvider.class);
assertThat(grpclb.getPriority()).isEqualTo(5);
Expand Down

0 comments on commit c7307ec

Please sign in to comment.