feat: add listener policy calculator

This commit is contained in:
Stavros
2026-05-11 18:47:37 +03:00
parent 35cd3b9ce5
commit b8b0e45ec4
2 changed files with 38 additions and 15 deletions
+1 -15
View File
@@ -255,21 +255,7 @@ func (app *BootstrapApp) Setup() error {
} }
// setup listeners // setup listeners
runUnix := app.config.Server.SocketPath != "" app.listeners = app.calculateListenerPolicy()
runHTTP := app.config.Server.SocketPath == "" || app.config.Server.ConcurrentListenersEnabled
runTailscale := app.services.tailscaleService != nil
if runHTTP {
app.listeners = append(app.listeners, ListenerHTTP)
}
if runUnix {
app.listeners = append(app.listeners, ListenerUnix)
}
if runTailscale {
app.listeners = append(app.listeners, ListenerTailscale)
}
if app.config.Server.ConcurrentListenersEnabled { if app.config.Server.ConcurrentListenersEnabled {
app.log.App.Info().Msg("Concurrent listeners enabled, will run on all available listeners") app.log.App.Info().Msg("Concurrent listeners enabled, will run on all available listeners")
+37
View File
@@ -85,6 +85,43 @@ func (app *BootstrapApp) runListeners() (chan error, error) {
return lec, nil return lec, nil
} }
// The way we calculate listeners is as follows:
// If concurrent listeners are disabled, we pick the first available listener, so:
// 1. If tailscale is enabled, we use tailscale
// 2. If socket path is configured, we use unix socket
// 3. Finally if none is configured we use http
// If concurrent listeners are enabled, we add all available listeners in the following order
func (app *BootstrapApp) calculateListenerPolicy() []Listener {
l := []Listener{}
if !app.config.Server.ConcurrentListenersEnabled {
if app.config.Tailscale.Enabled {
l = append(l, ListenerTailscale)
return l
}
if app.config.Server.SocketPath != "" {
l = append(l, ListenerUnix)
return l
}
l = append(l, ListenerHTTP)
return l
}
if app.config.Server.SocketPath != "" {
l = append(l, ListenerUnix)
}
if app.config.Tailscale.Enabled {
l = append(l, ListenerTailscale)
}
l = append(l, ListenerHTTP)
return l
}
func (app *BootstrapApp) listenerFromType(listenerType Listener) (func() error, error) { func (app *BootstrapApp) listenerFromType(listenerType Listener) (func() error, error) {
switch listenerType { switch listenerType {
case ListenerHTTP: case ListenerHTTP: