Skip to content

Commit

Permalink
Chore: Clean up gateway config (#790)
Browse files Browse the repository at this point in the history
Change 

```
gateway:
  externalHost: gateway.stage.beam.cloud
  externalURL: http://localhost:1994
  ....
  grpc:
  ....
  http:
  ....
```
to 
```
gateway:
  host: beta9-gateway.beta9
  ....
  grpc:
    externalHost: localhost
    externalPort: 1993
    tls: false
    ....
  http:
    externalHost: localhost
    externalPort: 1994
    tls: false
    ....
```

The ExternalURL value was less flexible
  • Loading branch information
jsun-m authored Dec 17, 2024
1 parent 4aa1bd0 commit bd864f0
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/abstractions/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func SetPublicURL(ctx context.Context, config types.AppConfig, backendRepo repos
return "", err
}

return fmt.Sprintf("%v/output/id/%v", config.GatewayService.ExternalURL, outputId), nil
return fmt.Sprintf("%v/output/id/%v", config.GatewayService.HTTP.GetExternalURL(), outputId), nil
}

func GetTaskOutputRootPath(workspaceName string, task *types.TaskWithRelated) string {
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (g *StubGroup) GetURL(ctx echo.Context) error {

// Get URL for Serves
if stub.Type.IsServe() {
invokeUrl := common.BuildServeURL(g.config.GatewayService.ExternalURL, filter.URLType, stub)
invokeUrl := common.BuildServeURL(g.config.GatewayService.HTTP.GetExternalURL(), filter.URLType, stub)
return ctx.JSON(http.StatusOK, map[string]string{"url": invokeUrl})
}

Expand All @@ -134,6 +134,6 @@ func (g *StubGroup) GetURL(ctx echo.Context) error {
return HTTPInternalServerError("Failed to lookup deployment")
}

invokeUrl := common.BuildDeploymentURL(g.config.GatewayService.ExternalURL, filter.URLType, stub, &deployment.Deployment)
invokeUrl := common.BuildDeploymentURL(g.config.GatewayService.HTTP.GetExternalURL(), filter.URLType, stub, &deployment.Deployment)
return ctx.JSON(http.StatusOK, map[string]string{"url": invokeUrl})
}
7 changes: 6 additions & 1 deletion pkg/common/config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@ storage:
bufferSize: 300
gateway:
host: beta9-gateway
externalURL: http://localhost:1994
invokeURLType: path
grpc:
externalHost: localhost
externalPort: 1993
tls: false
port: 1993
maxRecvMsgSize: 1024
maxSendMsgSize: 1024
http:
externalHost: localhost
externalPort: 1994
tls: false
port: 1994
enablePrettyLogs: true
cors:
Expand Down
2 changes: 1 addition & 1 deletion pkg/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (g *Gateway) initHttp() error {
AllowHeaders: g.Config.GatewayService.HTTP.CORS.AllowedHeaders,
AllowMethods: g.Config.GatewayService.HTTP.CORS.AllowedMethods,
}))
e.Use(gatewayMiddleware.Subdomain(g.Config.GatewayService.ExternalURL, g.BackendRepo, g.RedisClient))
e.Use(gatewayMiddleware.Subdomain(g.Config.GatewayService.HTTP.GetExternalURL(), g.BackendRepo, g.RedisClient))
e.Use(middleware.Recover())

// Accept both HTTP/2 and HTTP/1
Expand Down
6 changes: 3 additions & 3 deletions pkg/gateway/services/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (gws *GatewayService) DeployStub(ctx context.Context, in *pb.DeployStubRequ
}

// TODO: Remove this field once `pkg/api/v1/stub.go:GetURL()` is used by frontend and SDK version can be force upgraded
invokeUrl := common.BuildDeploymentURL(gws.appConfig.GatewayService.ExternalURL, common.InvokeUrlTypePath, stub, deployment)
invokeUrl := common.BuildDeploymentURL(gws.appConfig.GatewayService.HTTP.GetExternalURL(), common.InvokeUrlTypePath, stub, deployment)

go gws.eventRepo.PushDeployStubEvent(authInfo.Workspace.ExternalId, &stub.Stub)

Expand Down Expand Up @@ -257,7 +257,7 @@ func (gws *GatewayService) GetURL(ctx context.Context, in *pb.GetURLRequest) (*p

// Get URL for Serves
if stub.Type.IsServe() {
invokeUrl := common.BuildServeURL(gws.appConfig.GatewayService.ExternalURL, in.UrlType, stub)
invokeUrl := common.BuildServeURL(gws.appConfig.GatewayService.HTTP.GetExternalURL(), in.UrlType, stub)
return &pb.GetURLResponse{
Ok: true,
Url: invokeUrl,
Expand All @@ -280,7 +280,7 @@ func (gws *GatewayService) GetURL(ctx context.Context, in *pb.GetURLRequest) (*p
}, nil
}

invokeUrl := common.BuildDeploymentURL(gws.appConfig.GatewayService.ExternalURL, in.UrlType, stub, &deployment.Deployment)
invokeUrl := common.BuildDeploymentURL(gws.appConfig.GatewayService.HTTP.GetExternalURL(), in.UrlType, stub, &deployment.Deployment)
return &pb.GetURLResponse{
Ok: true,
Url: invokeUrl,
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/pool_external.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func (wpc *ExternalWorkerPoolController) getWorkerEnvironment(workerId, machineI
},
{
Name: "BETA9_GATEWAY_HOST",
Value: wpc.config.GatewayService.ExternalHost,
Value: wpc.config.GatewayService.GRPC.ExternalHost,
},
{
Name: "BETA9_GATEWAY_PORT",
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/pool_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func (wpc *LocalKubernetesWorkerPoolController) getWorkerEnvironment(workerId st
envVars = append(envVars, []corev1.EnvVar{
{
Name: "BETA9_GATEWAY_HOST",
Value: wpc.config.GatewayService.ExternalHost,
Value: wpc.config.GatewayService.GRPC.ExternalHost,
},
{
Name: "BETA9_GATEWAY_PORT",
Expand Down
31 changes: 25 additions & 6 deletions pkg/types/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"fmt"
"time"

blobcache "github.com/beam-cloud/blobcache-v2/pkg"
Expand Down Expand Up @@ -69,15 +70,35 @@ type PostgresConfig struct {
}

type GRPCConfig struct {
Port int `key:"port" json:"port"`
MaxRecvMsgSize int `key:"maxRecvMsgSize" json:"max_recv_msg_size"`
MaxSendMsgSize int `key:"maxSendMsgSize" json:"max_send_msg_size"`
ExternalPort int `key:"externalPort" json:"external_port"`
ExternalHost string `key:"externalHost" json:"external_host"`
TLS bool `key:"tls" json:"tls"`
Port int `key:"port" json:"port"`
MaxRecvMsgSize int `key:"maxRecvMsgSize" json:"max_recv_msg_size"`
MaxSendMsgSize int `key:"maxSendMsgSize" json:"max_send_msg_size"`
}

type HTTPConfig struct {
ExternalPort int `key:"externalPort" json:"external_port"`
ExternalHost string `key:"externalHost" json:"external_host"`
TLS bool `key:"tls" json:"tls"`
Port int `key:"port" json:"port"`
EnablePrettyLogs bool `key:"enablePrettyLogs" json:"enable_pretty_logs"`
CORS CORSConfig `key:"cors" json:"cors"`
Port int `key:"port" json:"port"`
}

func (h *HTTPConfig) GetExternalURL() string {
baseUrl := "http"
if h.TLS {
baseUrl += "s"
}
baseUrl += "://" + h.ExternalHost

if h.Port != 80 && h.Port != 443 {
baseUrl += fmt.Sprintf(":%d", h.Port)
}

return baseUrl
}

type CORSConfig struct {
Expand All @@ -94,8 +115,6 @@ type StubLimits struct {

type GatewayServiceConfig struct {
Host string `key:"host" json:"host"`
ExternalHost string `key:"externalHost" json:"external_host"`
ExternalURL string `key:"externalURL" json:"external_url"`
InvokeURLType string `key:"invokeURLType" json:"invoke_url_type"`
GRPC GRPCConfig `key:"grpc" json:"grpc"`
HTTP HTTPConfig `key:"http" json:"http"`
Expand Down

0 comments on commit bd864f0

Please sign in to comment.