Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: de-expermentalize pick first config parsing #10531

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package io.grpc.internal;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import io.grpc.LoadBalancer;
import io.grpc.LoadBalancerProvider;
import io.grpc.NameResolver;
Expand All @@ -33,11 +31,7 @@
* down the address list and sticks to the first that works.
*/
public final class PickFirstLoadBalancerProvider extends LoadBalancerProvider {
private static final String NO_CONFIG = "no service config";
private static final String SHUFFLE_ADDRESS_LIST_KEY = "shuffleAddressList";
private static final String CONFIG_FLAG_NAME = "GRPC_EXPERIMENTAL_PICKFIRST_LB_CONFIG";
@VisibleForTesting
static boolean enablePickFirstConfig = !Strings.isNullOrEmpty(System.getenv(CONFIG_FLAG_NAME));

@Override
public boolean isAvailable() {
Expand All @@ -62,18 +56,14 @@ public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
@Override
public ConfigOrError parseLoadBalancingPolicyConfig(
Map<String, ?> rawLoadBalancingPolicyConfig) {
if (enablePickFirstConfig) {
try {
return ConfigOrError.fromConfig(
new PickFirstLoadBalancerConfig(JsonUtil.getBoolean(rawLoadBalancingPolicyConfig,
SHUFFLE_ADDRESS_LIST_KEY)));
} catch (RuntimeException e) {
return ConfigOrError.fromError(
Status.UNAVAILABLE.withCause(e).withDescription(
"Failed parsing configuration for " + getPolicyName()));
}
} else {
return ConfigOrError.fromConfig(NO_CONFIG);
try {
return ConfigOrError.fromConfig(
new PickFirstLoadBalancerConfig(JsonUtil.getBoolean(rawLoadBalancingPolicyConfig,
SHUFFLE_ADDRESS_LIST_KEY)));
} catch (RuntimeException e) {
return ConfigOrError.fromError(
Status.UNAVAILABLE.withCause(e).withDescription(
"Failed parsing configuration for " + getPolicyName()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,33 @@
import io.grpc.internal.PickFirstLoadBalancer.PickFirstLoadBalancerConfig;
import java.util.HashMap;
import java.util.Map;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class PickFirstLoadBalancerProviderTest {

@After
public void resetConfigFlag() {
PickFirstLoadBalancerProvider.enablePickFirstConfig = false;
}

@Test
public void parseWithConfigEnabled() {
PickFirstLoadBalancerProvider.enablePickFirstConfig = true;
public void parseWithConfig() {
Map<String, Object> rawConfig = new HashMap<>();
rawConfig.put("shuffleAddressList", true);
ConfigOrError parsedConfig = new PickFirstLoadBalancerProvider().parseLoadBalancingPolicyConfig(
rawConfig);
PickFirstLoadBalancerConfig config = (PickFirstLoadBalancerConfig) parsedConfig.getConfig();

assertThat(config.shuffleAddressList).isTrue();
assertThat(config.randomSeed).isNull();
}

@Test
public void parseWithConfigDisabled() {
PickFirstLoadBalancerProvider.enablePickFirstConfig = false;
public void parseWithoutConfig() {
Map<String, Object> rawConfig = new HashMap<>();
rawConfig.put("shuffleAddressList", true);
ConfigOrError parsedConfig = new PickFirstLoadBalancerProvider().parseLoadBalancingPolicyConfig(
rawConfig);
String config = (String) parsedConfig.getConfig();
PickFirstLoadBalancerConfig config = (PickFirstLoadBalancerConfig) parsedConfig.getConfig();

assertThat(config).isEqualTo("no service config");
assertThat(config.shuffleAddressList).isNull();
assertThat(config.randomSeed).isNull();
}
}