Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: same port (#11674)

Danny Xu66e48c64b9b0
diff --git a/backend/bin/server/cmd/profile.go b/backend/bin/server/cmd/profile.go
index 4768c5dc15..e2cfbfe23e 100644
--- a/backend/bin/server/cmd/profile.go
+++ b/backend/bin/server/cmd/profile.go
@@ -22,7 +22,7 @@ func getBaseProfile(dataDir string) config.Profile {
return config.Profile{
ExternalURL: flags.externalURL,
- GrpcPort: flags.port + 1, // Using flags.port + 1 as our gRPC server port.
+ Port: flags.port, // Using flags.port as our gRPC server port.
DatastorePort: flags.port + 2, // Using flags.port + 2 as our datastore port.
SampleDatabasePort: sampleDatabasePort,
Readonly: flags.readonly,
diff --git a/backend/bin/server/cmd/root.go b/backend/bin/server/cmd/root.go
index e6ec95a729..424342a54f 100644
--- a/backend/bin/server/cmd/root.go
+++ b/backend/bin/server/cmd/root.go
@@ -250,10 +250,6 @@ func start() {
return
}
}
- if err := checkPort(profile.GrpcPort); err != nil {
- slog.Error(fmt.Sprintf("gRPC server port %d is not available", profile.GrpcPort), log.BBError(err))
- return
- }
var s *server.Server
// Setup signal handlers.
diff --git a/backend/component/config/profile.go b/backend/component/config/profile.go
index 1a75f1d32f..a999474389 100644
--- a/backend/component/config/profile.go
+++ b/backend/component/config/profile.go
@@ -20,8 +20,8 @@ type Profile struct {
// SampleDatabasePort is the start binding port for sample database instance.
// If SampleDatabasePort is not 0, then we start 2 sample instance at SampleDatabasePort and SampleDatabasePort+1.
SampleDatabasePort int
- // GrpcPort is the binding port for gRPC server.
- GrpcPort int
+ // Port is the binding port for the server.
+ Port int
// PgUser is the user we use to connect to bytebase's Postgres database.
// The name of the database storing metadata is the same as pgUser.
PgUser string
diff --git a/backend/server/grpc_routes.go b/backend/server/grpc_routes.go
index 31862621e8..218ca30c5d 100644
--- a/backend/server/grpc_routes.go
+++ b/backend/server/grpc_routes.go
@@ -91,7 +91,7 @@ func configureGrpcRouters(
v1pb.RegisterVCSConnectorServiceServer(grpcServer, apiv1.NewVCSConnectorService(stores))
// REST gateway proxy.
- grpcEndpoint := fmt.Sprintf(":%d", profile.GrpcPort)
+ grpcEndpoint := fmt.Sprintf(":%d", profile.Port)
grpcConn, err := grpc.Dial(grpcEndpoint, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, nil, err
diff --git a/backend/server/server.go b/backend/server/server.go
index 1f5e45342a..4262f09663 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -13,6 +13,7 @@ import (
grpcruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/labstack/echo/v4"
"github.com/pkg/errors"
+ "github.com/soheilhy/cmux"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/reflection"
@@ -82,8 +83,9 @@ type Server struct {
licenseService enterprise.LicenseService
profile *config.Profile
- e *echo.Echo
+ echoServer *echo.Echo
grpcServer *grpc.Server
+ muxServer cmux.CMux
lspServer *lsp.Server
store *store.Store
dbFactory *dbfactory.DBFactory
@@ -242,7 +244,7 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {
s.dbFactory = dbfactory.New(s.mysqlBinDir, s.mongoBinDir, s.pgBinDir, profile.DataDir, s.secret)
// Configure echo server.
- s.e = echo.New()
+ s.echoServer = echo.New()
// Note: the gateway response modifier takes the token duration on server startup. If the value is changed,
// the user has to restart the server to take the latest value.
@@ -359,7 +361,7 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {
gitOpsServer := gitops.NewService(s.store, s.dbFactory, s.activityManager, s.stateCfg, s.licenseService, rolloutService, issueService)
// Configure echo server routes.
- configureEchoRouters(s.e, s.grpcServer, s.lspServer, gitOpsServer, mux, profile)
+ configureEchoRouters(s.echoServer, s.grpcServer, s.lspServer, gitOpsServer, mux, profile)
serverStarted = true
return s, nil
@@ -393,17 +395,34 @@ func (s *Server) Run(ctx context.Context, port int) error {
go s.planCheckScheduler.Run(ctx, &s.runnerWG)
}
- listen, err := net.Listen("tcp", fmt.Sprintf(":%d", port+1))
+ address := fmt.Sprintf(":%d", port)
+ listener, err := net.Listen("tcp", address)
if err != nil {
return err
}
+
+ s.muxServer = cmux.New(listener)
+ grpcListener := s.muxServer.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc"))
+ httpListener := s.muxServer.Match(cmux.HTTP1Fast(), cmux.Any())
+ s.echoServer.Listener = httpListener
+
go func() {
- if err := s.grpcServer.Serve(listen); err != nil {
+ if err := s.grpcServer.Serve(grpcListener); err != nil {
slog.Error("grpc server listen error", log.BBError(err))
}
}()
+ go func() {
+ if err := s.echoServer.Start(address); err != nil {
+ slog.Error("http server listen error", log.BBError(err))
+ }
+ }()
+ go func() {
+ if err := s.muxServer.Serve(); err != nil {
+ slog.Error("mux server listen error", log.BBError(err))
+ }
+ }()
- return s.e.Start(fmt.Sprintf(":%d", port))
+ return nil
}
// Shutdown will shut down the server.
@@ -440,12 +459,14 @@ func (s *Server) Shutdown(ctx context.Context) error {
t.Stop()
}
}
-
- if s.e != nil {
- if err := s.e.Shutdown(ctx); err != nil {
- s.e.Logger.Fatal(err)
+ if s.echoServer != nil {
+ if err := s.echoServer.Shutdown(ctx); err != nil {
+ s.echoServer.Logger.Fatal(err)
}
}
+ if s.muxServer != nil {
+ s.muxServer.Close()
+ }
// Wait for all runners to exit.
s.runnerWG.Wait()
diff --git a/backend/tests/tests.go b/backend/tests/tests.go
index 2dc810236b..aecf37512f 100644
--- a/backend/tests/tests.go
+++ b/backend/tests/tests.go
@@ -303,7 +303,7 @@ func getTestProfile(dataDir, resourceDir string, port int, readOnly bool) compon
return component.Profile{
Mode: common.ReleaseModeDev,
ExternalURL: fmt.Sprintf("http://localhost:%d", port),
- GrpcPort: port + 1,
+ Port: port,
DatastorePort: port + 2,
SampleDatabasePort: 0,
PgUser: "bbtest",
@@ -323,7 +323,7 @@ func getTestProfileWithExternalPg(dataDir, resourceDir string, port int, pgUser
return component.Profile{
Mode: common.ReleaseModeDev,
ExternalURL: fmt.Sprintf("http://localhost:%d", port),
- GrpcPort: port + 1,
+ Port: port,
SampleDatabasePort: 0,
PgUser: pgUser,
DataDir: dataDir,
@@ -375,7 +375,7 @@ func (ctl *controller) start(ctx context.Context, port int) (context.Context, er
ctl.client = &http.Client{}
// initialize grpc connection.
- grpcConn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", ctl.profile.GrpcPort), grpc.WithTransportCredentials(insecure.NewCredentials()))
+ grpcConn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", port), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, errors.Wrap(err, "failed to dial grpc")
}
@@ -433,7 +433,7 @@ func waitForVCSStart(p fake.VCSProvider, errChan <-chan error) error {
func (ctl *controller) waitForHealthz(ctx context.Context) error {
begin := time.Now()
ticker := time.NewTicker(100 * time.Millisecond)
- timer := time.NewTimer(30 * time.Second)
+ timer := time.NewTimer(10 * time.Second)
defer ticker.Stop()
defer timer.Stop()
for {
diff --git a/go.mod b/go.mod
index 5f64a759a3..4fb100a984 100644
--- a/go.mod
+++ b/go.mod
@@ -65,6 +65,7 @@ require (
github.com/shopspring/decimal v1.3.1
github.com/sijms/go-ora/v2 v2.8.10
github.com/snowflakedb/gosnowflake v1.9.0
+ github.com/soheilhy/cmux v0.1.5
github.com/sourcegraph/go-lsp v0.0.0-20240223163137-f80c5dd31dfd
github.com/sourcegraph/jsonrpc2 v0.2.0
github.com/spf13/cobra v1.8.0
diff --git a/go.sum b/go.sum
index dcd41fee9f..688acbec99 100644
--- a/go.sum
+++ b/go.sum
@@ -1007,6 +1007,8 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9
github.com/snowflakedb/gosnowflake v1.9.0 h1:s2ZdwFxFfpqwa5CqlhnzRESnLmwU3fED6zyNOJHFBQA=
github.com/snowflakedb/gosnowflake v1.9.0/go.mod h1:4ZgHxVf2OKwecx07WjfyAMr0gn8Qj4yvwAo68Og8wsU=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
+github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js=
+github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0=
github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
github.com/sourcegraph/jsonrpc2 v0.2.0 h1:KjN/dC4fP6aN9030MZCJs9WQbTOjWHhrtKVpzzSrr/U=
github.com/sourcegraph/jsonrpc2 v0.2.0/go.mod h1:ZafdZgk/axhT1cvZAPOhw+95nz2I/Ra5qMlU4gTRwIo=
@@ -1264,6 +1266,7 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
+golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
diff --git a/proto/README.md b/proto/README.md
index a51979761c..ef794d450b 100644
--- a/proto/README.md
+++ b/proto/README.md
@@ -9,5 +9,5 @@ You may have command conflict for the `buf`: https://github.com/ohmyzsh/ohmyzsh/
If so please remove the brew alias in `~/.oh-my-zsh/plugins/brew/brew.plugin.zsh`
# Clients
-- Web: grpcui -plaintext localhost:8081
-- CLI: grpcurl
\ No newline at end of file
+- Web: grpcui -plaintext localhost:8080
+- CLI: grpcurl -plaintext localhost:8080 bytebase.v1.ActuatorService.GetActuatorInfo
\ No newline at end of file