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

feat: support gRPC over proxy #949

Closed
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
1 change: 1 addition & 0 deletions providers/flagd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Given below are the supported configurations:
| maxEventStreamRetries | FLAGD_MAX_EVENT_STREAM_RETRIES | int | 5 | rpc |
| retryBackoffMs | FLAGD_RETRY_BACKOFF_MS | int | 1000 | rpc |
| offlineFlagSourcePath | FLAGD_OFFLINE_FLAG_SOURCE_PATH | String | null | in-process |
| authority | FLAGD_AUTHORITY_OVERRIDE | String | null | rpc & in-process |

> [!NOTE]
> Some configurations are only applicable for RPC resolver.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public final class Config {
static final String OFFLINE_SOURCE_PATH = "FLAGD_OFFLINE_FLAG_SOURCE_PATH";
static final String KEEP_ALIVE_MS_ENV_VAR_NAME_OLD = "FLAGD_KEEP_ALIVE_TIME";
static final String KEEP_ALIVE_MS_ENV_VAR_NAME = "FLAGD_KEEP_ALIVE_TIME_MS";
static final String AUTHORITY_OVERRIDE = "FLAGD_AUTHORITY_OVERRIDE";

static final String RESOLVER_RPC = "rpc";
static final String RESOLVER_IN_PROCESS = "in-process";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public class FlagdOptions {
/**
* gRPC client KeepAlive in milliseconds. Disabled with 0.
* Defaults to 0 (disabled).
*
*
**/
@Builder.Default
private long keepAlive = fallBackToEnvOrDefault(Config.KEEP_ALIVE_MS_ENV_VAR_NAME,
Expand All @@ -109,6 +109,16 @@ public class FlagdOptions {
@Builder.Default
private String offlineFlagSourcePath = fallBackToEnvOrDefault(Config.OFFLINE_SOURCE_PATH, null);


/**
* gRPC authority override.
* Setting this will allow user to override the system generated authority with
* user specified string. This is useful when running flagd gRPC sync service behind
* proxy e.g. envoy, istio etc.
*/
@Builder.Default
private String authority = fallBackToEnvOrDefault(Config.AUTHORITY_OVERRIDE, null);

/**
* Inject a Custom Connector for fetching flags.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public static ManagedChannel nettyChannel(final FlagdOptions options) {
final NettyChannelBuilder builder = NettyChannelBuilder
.forAddress(options.getHost(), options.getPort())
.keepAliveTime(keepAliveMs, TimeUnit.MILLISECONDS);


if (options.getAuthority() != null) {
builder.overrideAuthority(options.getAuthority());
}

if (options.isTls()) {
SslContextBuilder sslContext = GrpcSslContexts.forClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void TestDefaults() {
assertNull(builder.getOfflineFlagSourcePath());
assertEquals(Resolver.RPC, builder.getResolverType());
assertEquals(0, builder.getKeepAlive());
assertNull(builder.getAuthority());
}

@Test
Expand All @@ -55,6 +56,7 @@ void TestBuilderOptions() {
.customConnector(connector)
.resolverType(Resolver.IN_PROCESS)
.keepAlive(1000)
.authority("test.service")
.build();

assertEquals("https://hosted-flagd", flagdOptions.getHost());
Expand All @@ -70,6 +72,7 @@ void TestBuilderOptions() {
assertEquals(connector, flagdOptions.getCustomConnector());
assertEquals(Resolver.IN_PROCESS, flagdOptions.getResolverType());
assertEquals(1000, flagdOptions.getKeepAlive());
assertEquals("test.service", flagdOptions.getAuthority());
}


Expand Down Expand Up @@ -187,4 +190,13 @@ void testRpcProviderFromEnv_portConfigured_usesConfiguredPort() {
assertThat(flagdOptions.getPort()).isEqualTo(1534);

}


@Test
@SetEnvironmentVariable(key = AUTHORITY_OVERRIDE, value = "test.service")
void testAuthorityOverrideFromEnv() {
FlagdOptions flagdOptions = FlagdOptions.builder().build();

assertThat(flagdOptions.getAuthority()).isEqualTo("test.service");
}
}