fix: logger and context.
This commit is contained in:
parent
b4c7b90c9e
commit
8e18d37b3d
52 changed files with 231 additions and 183 deletions
|
@ -27,7 +27,7 @@ func GenerateName(backendName string) string {
|
|||
_, err := hash.Write(data)
|
||||
if err != nil {
|
||||
// Impossible case
|
||||
log.Errorf("Fail to create cookie name: %v", err)
|
||||
log.WithoutContext().Errorf("Fail to create cookie name: %v", err)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("_%x", hash.Sum(nil))[:cookieNameLength]
|
||||
|
|
|
@ -203,6 +203,7 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
serviceManager := tcp.NewManager(conf)
|
||||
tlsManager := tls.NewManager()
|
||||
tlsManager.UpdateConfigs(
|
||||
context.Background(),
|
||||
map[string]tls.Store{},
|
||||
map[string]tls.Options{
|
||||
"default": {
|
||||
|
|
|
@ -270,7 +270,8 @@ func (s *Server) listenProviders(stop chan bool) {
|
|||
if configMsg.Configuration != nil {
|
||||
s.preLoadConfiguration(configMsg)
|
||||
} else {
|
||||
log.Debugf("Received nil configuration from provider %q, skipping.", configMsg.ProviderName)
|
||||
log.WithoutContext().WithField(log.ProviderName, configMsg.ProviderName).
|
||||
Debug("Received nil configuration from provider, skipping.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -285,18 +286,20 @@ func (s *Server) AddListener(listener func(dynamic.Configuration)) {
|
|||
}
|
||||
|
||||
func (s *Server) startProvider() {
|
||||
logger := log.WithoutContext()
|
||||
|
||||
jsonConf, err := json.Marshal(s.provider)
|
||||
if err != nil {
|
||||
log.WithoutContext().Debugf("Unable to marshal provider configuration %T: %v", s.provider, err)
|
||||
logger.Debugf("Unable to marshal provider configuration %T: %v", s.provider, err)
|
||||
}
|
||||
|
||||
log.WithoutContext().Infof("Starting provider %T %s", s.provider, jsonConf)
|
||||
logger.Infof("Starting provider %T %s", s.provider, jsonConf)
|
||||
currentProvider := s.provider
|
||||
|
||||
safe.Go(func() {
|
||||
err := currentProvider.Provide(s.configurationChan, s.routinesPool)
|
||||
if err != nil {
|
||||
log.WithoutContext().Errorf("Error starting provider %T: %s", s.provider, err)
|
||||
logger.Errorf("Error starting provider %T: %s", s.provider, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ func (s *Server) loadConfiguration(configMsg dynamic.Message) {
|
|||
// loadConfigurationTCP returns a new gorilla.mux Route from the specified global configuration and the dynamic
|
||||
// provider configurations.
|
||||
func (s *Server) loadConfigurationTCP(configurations dynamic.Configurations) map[string]*tcpCore.Router {
|
||||
ctx := context.TODO()
|
||||
ctx := context.Background()
|
||||
|
||||
var entryPoints []string
|
||||
for entryPointName := range s.entryPointsTCP {
|
||||
|
@ -72,7 +72,7 @@ func (s *Server) loadConfigurationTCP(configurations dynamic.Configurations) map
|
|||
|
||||
conf := mergeConfiguration(configurations)
|
||||
|
||||
s.tlsManager.UpdateConfigs(conf.TLS.Stores, conf.TLS.Options, conf.TLS.Certificates)
|
||||
s.tlsManager.UpdateConfigs(ctx, conf.TLS.Stores, conf.TLS.Options, conf.TLS.Certificates)
|
||||
|
||||
rtConf := runtime.NewConfig(conf)
|
||||
handlersNonTLS, handlersTLS := s.createHTTPHandlers(ctx, rtConf, entryPoints)
|
||||
|
|
|
@ -72,14 +72,14 @@ func NewTCPEntryPoint(ctx context.Context, configuration *static.EntryPoint) (*T
|
|||
|
||||
router := &tcp.Router{}
|
||||
|
||||
httpServer, err := createHTTPServer(listener, configuration, true)
|
||||
httpServer, err := createHTTPServer(ctx, listener, configuration, true)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error preparing httpServer: %v", err)
|
||||
}
|
||||
|
||||
router.HTTPForwarder(httpServer.Forwarder)
|
||||
|
||||
httpsServer, err := createHTTPServer(listener, configuration, false)
|
||||
httpsServer, err := createHTTPServer(ctx, listener, configuration, false)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error preparing httpsServer: %v", err)
|
||||
}
|
||||
|
@ -128,13 +128,13 @@ func writeCloser(conn net.Conn) (tcp.WriteCloser, error) {
|
|||
}
|
||||
|
||||
func (e *TCPEntryPoint) startTCP(ctx context.Context) {
|
||||
|
||||
log.FromContext(ctx).Debugf("Start TCP Server")
|
||||
logger := log.FromContext(ctx)
|
||||
logger.Debugf("Start TCP Server")
|
||||
|
||||
for {
|
||||
conn, err := e.listener.Accept()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -372,7 +372,7 @@ type httpServer struct {
|
|||
Switcher *middlewares.HTTPHandlerSwitcher
|
||||
}
|
||||
|
||||
func createHTTPServer(ln net.Listener, configuration *static.EntryPoint, withH2c bool) (*httpServer, error) {
|
||||
func createHTTPServer(ctx context.Context, ln net.Listener, configuration *static.EntryPoint, withH2c bool) (*httpServer, error) {
|
||||
httpSwitcher := middlewares.NewHandlerSwitcher(buildDefaultHTTPRouter())
|
||||
|
||||
var handler http.Handler
|
||||
|
@ -398,7 +398,7 @@ func createHTTPServer(ln net.Listener, configuration *static.EntryPoint, withH2c
|
|||
go func() {
|
||||
err := serverHTTP.Serve(listener)
|
||||
if err != nil {
|
||||
log.Errorf("Error while starting server: %v", err)
|
||||
log.FromContext(ctx).Errorf("Error while starting server: %v", err)
|
||||
}
|
||||
}()
|
||||
return &httpServer{
|
||||
|
|
|
@ -232,7 +232,7 @@ func (m *Manager) LaunchHealthCheck() {
|
|||
}
|
||||
|
||||
// FIXME metrics and context
|
||||
healthcheck.GetHealthCheck().SetBackendsConfiguration(context.TODO(), backendConfigs)
|
||||
healthcheck.GetHealthCheck().SetBackendsConfiguration(context.Background(), backendConfigs)
|
||||
}
|
||||
|
||||
func buildHealthCheckOptions(ctx context.Context, lb healthcheck.BalancerHandler, backend string, hc *dynamic.HealthCheck) *healthcheck.Options {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue