diff --git a/cmd/s3-gw/app.go b/cmd/s3-gw/app.go index 083af25..b392465 100644 --- a/cmd/s3-gw/app.go +++ b/cmd/s3-gw/app.go @@ -632,7 +632,7 @@ func newMaxClients(cfg *viper.Viper) maxClientsConfig { } func getDialerSource(logger *zap.Logger, cfg *viper.Viper) *internalnet.DialerSource { - source, err := internalnet.NewDialerSource(fetchMultinetConfig(cfg)) + source, err := internalnet.NewDialerSource(fetchMultinetConfig(cfg, logger)) if err != nil { logger.Fatal(logs.FailedToLoadMultinetConfig, zap.Error(err)) } @@ -871,7 +871,7 @@ func (a *App) updateSettings() { a.settings.logLevel.SetLevel(lvl) } - if err := a.settings.dialerSource.Update(fetchMultinetConfig(a.cfg)); err != nil { + if err := a.settings.dialerSource.Update(fetchMultinetConfig(a.cfg, a.log)); err != nil { a.log.Warn(logs.MultinetConfigWontBeUpdated, zap.Error(err)) } diff --git a/cmd/s3-gw/app_settings.go b/cmd/s3-gw/app_settings.go index 0cecad5..6e8cbba 100644 --- a/cmd/s3-gw/app_settings.go +++ b/cmd/s3-gw/app_settings.go @@ -755,12 +755,13 @@ func fetchVHSNamespaces(v *viper.Viper, log *zap.Logger) map[string]bool { return vhsNamespacesEnabled } -func fetchMultinetConfig(v *viper.Viper) (cfg internalnet.Config) { +func fetchMultinetConfig(v *viper.Viper, logger *zap.Logger) (cfg internalnet.Config) { cfg.Enabled = v.GetBool(cfgMultinetEnabled) cfg.Balancer = v.GetString(cfgMultinetBalancer) cfg.Restrict = v.GetBool(cfgMultinetRestrict) cfg.FallbackDelay = v.GetDuration(cfgMultinetFallbackDelay) cfg.Subnets = make([]internalnet.Subnet, 0, 5) + cfg.EventHandler = internalnet.NewLogEventHandler(logger) for i := 0; ; i++ { key := cfgMultinetSubnets + "." + strconv.Itoa(i) + "." diff --git a/internal/logs/logs.go b/internal/logs/logs.go index b4eef3c..fb30bdf 100644 --- a/internal/logs/logs.go +++ b/internal/logs/logs.go @@ -173,4 +173,6 @@ const ( NotSupported = "not supported" FailedToLoadMultinetConfig = "failed to load multinet config" MultinetConfigWontBeUpdated = "multinet config won't be updated" + MultinetDialSuccess = "multinet dial successful" + MultinetDialFail = "multinet dial failed" ) diff --git a/internal/net/config.go b/internal/net/config.go index 10450db..ec502da 100644 --- a/internal/net/config.go +++ b/internal/net/config.go @@ -23,6 +23,7 @@ type Config struct { Balancer string Restrict bool FallbackDelay time.Duration + EventHandler multinet.EventHandler } func (c Config) toMultinetConfig() (multinet.Config, error) { @@ -52,6 +53,7 @@ func (c Config) toMultinetConfig() (multinet.Config, error) { Restrict: c.Restrict, FallbackDelay: c.FallbackDelay, Dialer: newDefaulDialer(), + EventHandler: c.EventHandler, }, nil } diff --git a/internal/net/event_handler.go b/internal/net/event_handler.go new file mode 100644 index 0000000..725f068 --- /dev/null +++ b/internal/net/event_handler.go @@ -0,0 +1,28 @@ +package net + +import ( + "net" + + "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/logs" + "go.uber.org/zap" +) + +type LogEventHandler struct { + logger *zap.Logger +} + +func (l LogEventHandler) DialPerformed(sourceIP net.Addr, network, address string, err error) { + sourceIPString := "undefined" + if sourceIP != nil { + sourceIPString = sourceIP.Network() + "://" + sourceIP.String() + } + if err == nil { + l.logger.Debug(logs.MultinetDialSuccess, zap.String("source", sourceIPString), zap.String("destination", address)) + } else { + l.logger.Debug(logs.MultinetDialFail, zap.String("source", sourceIPString), zap.String("destination", address), zap.Error(err)) + } +} + +func NewLogEventHandler(logger *zap.Logger) LogEventHandler { + return LogEventHandler{logger: logger} +}