mirror of
https://github.com/itzg/mc-router.git
synced 2024-11-21 11:25:41 +01:00
Improved logging of registered mappings (#96)
This commit is contained in:
parent
9163ae66d4
commit
1a873cb58a
@ -78,8 +78,7 @@ func TestK8sWatcherImpl_handleAddThenUpdate(t *testing.T) {
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
// reset the routes
|
||||
Routes.RegisterAll(map[string]string{})
|
||||
Routes.Reset()
|
||||
|
||||
watcher := &k8sWatcherImpl{}
|
||||
initialSvc := v1.Service{}
|
||||
@ -150,8 +149,7 @@ func TestK8sWatcherImpl_handleAddThenDelete(t *testing.T) {
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
// reset the routes
|
||||
Routes.RegisterAll(map[string]string{})
|
||||
Routes.Reset()
|
||||
|
||||
watcher := &k8sWatcherImpl{}
|
||||
initialSvc := v1.Service{}
|
||||
|
@ -86,6 +86,7 @@ func routesSetDefault(writer http.ResponseWriter, request *http.Request) {
|
||||
}
|
||||
|
||||
type IRoutes interface {
|
||||
Reset()
|
||||
RegisterAll(mappings map[string]string)
|
||||
// FindBackendForServerAddress returns the host:port for the external server address, if registered.
|
||||
// Otherwise, an empty string is returned. Also returns the normalized version of the given serverAddress.
|
||||
@ -98,7 +99,7 @@ type IRoutes interface {
|
||||
SimplifySRV(srvEnabled bool)
|
||||
}
|
||||
|
||||
var Routes IRoutes = &routesImpl{}
|
||||
var Routes = NewRoutes()
|
||||
|
||||
func NewRoutes() IRoutes {
|
||||
r := &routesImpl{
|
||||
@ -109,12 +110,8 @@ func NewRoutes() IRoutes {
|
||||
}
|
||||
|
||||
func (r *routesImpl) RegisterAll(mappings map[string]string) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
|
||||
r.mappings = make(map[string]mapping)
|
||||
for k, v := range mappings {
|
||||
r.mappings[k] = mapping{backend: v, waker: func(ctx context.Context) error { return nil }}
|
||||
r.CreateMapping(k, v, func(ctx context.Context) error { return nil })
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,6 +127,10 @@ type routesImpl struct {
|
||||
simplifySRV bool
|
||||
}
|
||||
|
||||
func (r *routesImpl) Reset() {
|
||||
r.mappings = make(map[string]mapping)
|
||||
}
|
||||
|
||||
func (r *routesImpl) SetDefaultRoute(backend string) {
|
||||
r.defaultRoute = backend
|
||||
|
||||
@ -146,6 +147,10 @@ func (r *routesImpl) FindBackendForServerAddress(ctx context.Context, serverAddr
|
||||
r.RLock()
|
||||
defer r.RUnlock()
|
||||
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"serverAddress": serverAddress,
|
||||
}).Debug("Finding backend for server address")
|
||||
|
||||
if r.simplifySRV {
|
||||
serverAddress = strings.TrimSuffix(serverAddress, ".")
|
||||
parts := strings.Split(serverAddress, ".")
|
||||
@ -208,6 +213,6 @@ func (r *routesImpl) CreateMapping(serverAddress string, backend string, waker f
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"serverAddress": serverAddress,
|
||||
"backend": backend,
|
||||
}).Info("Creating route")
|
||||
}).Info("Created route mapping")
|
||||
r.mappings[serverAddress] = mapping{backend: backend, waker: waker}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user