Skip to content

Commit

Permalink
patch dendrite microservices with bind config (#795)
Browse files Browse the repository at this point in the history

This PR adds a block in the dendrite config for the services to bind to. The microservices should bind to the addresses in the bind block, and will be contacted at the address in the listen block.

This fixes an issue with the microservices and kubernetes services.
  • Loading branch information
aditsachde authored and anoadragon453 committed Oct 2, 2019
1 parent 3e2bb8b commit 7d77538
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 10 deletions.
3 changes: 2 additions & 1 deletion cmd/dendrite-appservice-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ func main() {
base, accountDB, deviceDB, federation, alias, query, cache,
)

base.SetupAndServeHTTP(string(base.Cfg.Listen.FederationSender))
base.SetupAndServeHTTP(string(base.Cfg.Bind.AppServiceAPI), string(base.Cfg.Listen.AppServiceAPI))

}
3 changes: 2 additions & 1 deletion cmd/dendrite-client-api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ func main() {
alias, input, query, typingInputAPI, asQuery, transactions.New(), fedSenderAPI,
)

base.SetupAndServeHTTP(string(base.Cfg.Listen.ClientAPI))
base.SetupAndServeHTTP(string(base.Cfg.Bind.ClientAPI), string(base.Cfg.Listen.ClientAPI))

}
3 changes: 2 additions & 1 deletion cmd/dendrite-federation-api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ func main() {
alias, input, query, asQuery,
)

base.SetupAndServeHTTP(string(base.Cfg.Listen.FederationAPI))
base.SetupAndServeHTTP(string(base.Cfg.Bind.FederationAPI), string(base.Cfg.Listen.FederationAPI))

}
3 changes: 2 additions & 1 deletion cmd/dendrite-federation-sender-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ func main() {
base, federation, query,
)

base.SetupAndServeHTTP(string(base.Cfg.Listen.FederationSender))
base.SetupAndServeHTTP(string(base.Cfg.Bind.FederationSender), string(base.Cfg.Listen.FederationSender))

}
3 changes: 2 additions & 1 deletion cmd/dendrite-media-api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ func main() {

mediaapi.SetupMediaAPIComponent(base, deviceDB)

base.SetupAndServeHTTP(string(base.Cfg.Listen.MediaAPI))
base.SetupAndServeHTTP(string(base.Cfg.Bind.MediaAPI), string(base.Cfg.Listen.MediaAPI))

}
3 changes: 2 additions & 1 deletion cmd/dendrite-public-rooms-api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ func main() {

publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB)

base.SetupAndServeHTTP(string(base.Cfg.Listen.PublicRoomsAPI))
base.SetupAndServeHTTP(string(base.Cfg.Bind.PublicRoomsAPI), string(base.Cfg.Listen.PublicRoomsAPI))

}
3 changes: 2 additions & 1 deletion cmd/dendrite-room-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ func main() {

roomserver.SetupRoomServerComponent(base)

base.SetupAndServeHTTP(string(base.Cfg.Listen.RoomServer))
base.SetupAndServeHTTP(string(base.Cfg.Bind.RoomServer), string(base.Cfg.Listen.RoomServer))

}
3 changes: 2 additions & 1 deletion cmd/dendrite-sync-api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ func main() {

syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, query)

base.SetupAndServeHTTP(string(base.Cfg.Listen.SyncAPI))
base.SetupAndServeHTTP(string(base.Cfg.Bind.SyncAPI), string(base.Cfg.Listen.SyncAPI))

}
3 changes: 2 additions & 1 deletion cmd/dendrite-typing-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ func main() {

typingserver.SetupTypingServerComponent(base, cache.NewTypingCache())

base.SetupAndServeHTTP(string(base.Cfg.Listen.TypingServer))
base.SetupAndServeHTTP(string(base.Cfg.Bind.TypingServer), string(base.Cfg.Listen.TypingServer))

}
11 changes: 10 additions & 1 deletion common/basecomponent/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,16 @@ func (b *BaseDendrite) CreateFederationClient() *gomatrixserverlib.FederationCli

// SetupAndServeHTTP sets up the HTTP server to serve endpoints registered on
// ApiMux under /api/ and adds a prometheus handler under /metrics.
func (b *BaseDendrite) SetupAndServeHTTP(addr string) {
func (b *BaseDendrite) SetupAndServeHTTP(bindaddr string, listenaddr string) {
// If a separate bind address is defined, listen on that. Otherwise use
// the listen address
var addr string
if bindaddr != "" {
addr = bindaddr
} else {
addr = listenaddr
}

common.SetupHTTPAPI(http.DefaultServeMux, common.WrapHandlerInCORS(b.APIMux))
logrus.Infof("Starting %s server on %s", b.componentName, addr)

Expand Down
14 changes: 14 additions & 0 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,20 @@ type Dendrite struct {

// The internal addresses the components will listen on.
// These should not be exposed externally as they expose metrics and debugging APIs.
// Falls back to addresses listed in Listen if not specified
Bind struct {
MediaAPI Address `yaml:"media_api"`
ClientAPI Address `yaml:"client_api"`
FederationAPI Address `yaml:"federation_api"`
AppServiceAPI Address `yaml:"appservice_api"`
SyncAPI Address `yaml:"sync_api"`
RoomServer Address `yaml:"room_server"`
FederationSender Address `yaml:"federation_sender"`
PublicRoomsAPI Address `yaml:"public_rooms_api"`
TypingServer Address `yaml:"typing_server"`
} `yaml:"bind"`

// The addresses for talking to other microservices.
Listen struct {
MediaAPI Address `yaml:"media_api"`
ClientAPI Address `yaml:"client_api"`
Expand Down
10 changes: 10 additions & 0 deletions common/test/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ func MakeConfig(configDir, kafkaURI, database, host string, startPort int) (*con
cfg.Listen.PublicRoomsAPI = assignAddress()
cfg.Listen.TypingServer = assignAddress()

// Bind to the same address as the listen address
// All microservices are run on the same host in testing
cfg.Bind.ClientAPI = cfg.Listen.ClientAPI
cfg.Bind.FederationAPI = cfg.Listen.FederationAPI
cfg.Bind.MediaAPI = cfg.Listen.MediaAPI
cfg.Bind.RoomServer = cfg.Listen.RoomServer
cfg.Bind.SyncAPI = cfg.Listen.SyncAPI
cfg.Bind.PublicRoomsAPI = cfg.Listen.PublicRoomsAPI
cfg.Bind.TypingServer = cfg.Listen.TypingServer

return &cfg, port, nil
}

Expand Down

0 comments on commit 7d77538

Please sign in to comment.