Skip to content

Commit

Permalink
Allow server bind address config specification
Browse files Browse the repository at this point in the history
Use cases have been presented which limit server bind address
presentation.
Partially Fixes buildfarm#1713
  • Loading branch information
werkt committed Apr 22, 2024
1 parent ce4b129 commit bf56543
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ server:
name: shard
actionCacheReadOnly: false
port: 8980
bindAddress: ""
grpcMetrics:
enabled: true
provideLatencyHistograms: true
Expand Down
1 change: 1 addition & 0 deletions src/main/java/build/buildfarm/common/config/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum INSTANCE_TYPE {
private INSTANCE_TYPE instanceType = INSTANCE_TYPE.SHARD;
private String name = "shard";
private boolean actionCacheReadOnly = false;
private String bindAddress = "";
private int port = 8980;
private GrpcMetrics grpcMetrics = new GrpcMetrics();
private int casWriteTimeout = 3600;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/build/buildfarm/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ java_library(
"@maven//:com_google_guava_guava",
"@maven//:io_grpc_grpc_api",
"@maven//:io_grpc_grpc_core",
"@maven//:io_grpc_grpc_netty",
"@maven//:io_grpc_grpc_services",
"@maven//:io_grpc_grpc_util",
"@maven//:io_prometheus_simpleclient",
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/build/buildfarm/server/BuildFarmServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@
import io.grpc.ServerBuilder;
import io.grpc.ServerInterceptor;
import io.grpc.health.v1.HealthCheckResponse.ServingStatus;
import io.grpc.netty.NettyServerBuilder;
import io.grpc.protobuf.services.HealthStatusManager;
import io.grpc.protobuf.services.ProtoReflectionService;
import io.grpc.util.TransmitStatusRuntimeExceptionInterceptor;
import io.prometheus.client.Counter;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.security.Security;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -250,13 +253,19 @@ public static void main(String[] args) throws Exception {

configs = BuildfarmConfigs.loadServerConfigs(args);

// Configure Spring
BuildFarmServer server = new BuildFarmServer();
SocketAddress socketAddress;
if (configs.getServer().getBindAddress().isEmpty()) {
socketAddress = new InetSocketAddress(configs.getServer().getPort());
} else {
socketAddress =
new InetSocketAddress(
configs.getServer().getBindAddress(), configs.getServer().getPort());
}

try {
server.start(
ServerBuilder.forPort(configs.getServer().getPort()),
configs.getServer().getPublicName());
NettyServerBuilder.forAddress(socketAddress), configs.getServer().getPublicName());
server.awaitTermination();
} catch (IOException e) {
log.severe("error: " + formatIOError(e));
Expand Down

0 comments on commit bf56543

Please sign in to comment.