patch dendrite microservices with bind config (#795)
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.
This commit is contained in:
parent
3e2bb8bf2f
commit
7d77538ca4
12 changed files with 52 additions and 10 deletions
|
@ -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))
|
||||
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue