forked from TrueCloudLab/frostfs-s3-gw
[#521] Use handler to register dial events
While frostfs-node uses dial handler to udpate metric value, gateway starts with simple event logging. Signed-off-by: Alex Vanin <a.vanin@yadro.com>
This commit is contained in:
parent
94504e9746
commit
9e64304499
5 changed files with 36 additions and 3 deletions
|
@ -658,7 +658,7 @@ func newMaxClients(cfg *viper.Viper) maxClientsConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDialerSource(logger *zap.Logger, cfg *viper.Viper) *internalnet.DialerSource {
|
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 {
|
if err != nil {
|
||||||
logger.Fatal(logs.FailedToLoadMultinetConfig, zap.Error(err))
|
logger.Fatal(logs.FailedToLoadMultinetConfig, zap.Error(err))
|
||||||
}
|
}
|
||||||
|
@ -892,7 +892,7 @@ func (a *App) updateSettings() {
|
||||||
a.settings.logLevel.SetLevel(lvl)
|
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))
|
a.log.Warn(logs.MultinetConfigWontBeUpdated, zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -756,12 +756,13 @@ func fetchVHSNamespaces(v *viper.Viper, log *zap.Logger) map[string]bool {
|
||||||
return vhsNamespacesEnabled
|
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.Enabled = v.GetBool(cfgMultinetEnabled)
|
||||||
cfg.Balancer = v.GetString(cfgMultinetBalancer)
|
cfg.Balancer = v.GetString(cfgMultinetBalancer)
|
||||||
cfg.Restrict = v.GetBool(cfgMultinetRestrict)
|
cfg.Restrict = v.GetBool(cfgMultinetRestrict)
|
||||||
cfg.FallbackDelay = v.GetDuration(cfgMultinetFallbackDelay)
|
cfg.FallbackDelay = v.GetDuration(cfgMultinetFallbackDelay)
|
||||||
cfg.Subnets = make([]internalnet.Subnet, 0, 5)
|
cfg.Subnets = make([]internalnet.Subnet, 0, 5)
|
||||||
|
cfg.EventHandler = internalnet.NewLogEventHandler(logger)
|
||||||
|
|
||||||
for i := 0; ; i++ {
|
for i := 0; ; i++ {
|
||||||
key := cfgMultinetSubnets + "." + strconv.Itoa(i) + "."
|
key := cfgMultinetSubnets + "." + strconv.Itoa(i) + "."
|
||||||
|
|
|
@ -175,4 +175,6 @@ const (
|
||||||
CheckCustomAccessKeyIDUniqueness = "check custom access key id uniqueness"
|
CheckCustomAccessKeyIDUniqueness = "check custom access key id uniqueness"
|
||||||
FailedToLoadMultinetConfig = "failed to load multinet config"
|
FailedToLoadMultinetConfig = "failed to load multinet config"
|
||||||
MultinetConfigWontBeUpdated = "multinet config won't be updated"
|
MultinetConfigWontBeUpdated = "multinet config won't be updated"
|
||||||
|
MultinetDialSuccess = "multinet dial successful"
|
||||||
|
MultinetDialFail = "multinet dial failed"
|
||||||
)
|
)
|
||||||
|
|
|
@ -23,6 +23,7 @@ type Config struct {
|
||||||
Balancer string
|
Balancer string
|
||||||
Restrict bool
|
Restrict bool
|
||||||
FallbackDelay time.Duration
|
FallbackDelay time.Duration
|
||||||
|
EventHandler multinet.EventHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) toMultinetConfig() (multinet.Config, error) {
|
func (c Config) toMultinetConfig() (multinet.Config, error) {
|
||||||
|
@ -52,6 +53,7 @@ func (c Config) toMultinetConfig() (multinet.Config, error) {
|
||||||
Restrict: c.Restrict,
|
Restrict: c.Restrict,
|
||||||
FallbackDelay: c.FallbackDelay,
|
FallbackDelay: c.FallbackDelay,
|
||||||
Dialer: newDefaultDialer(),
|
Dialer: newDefaultDialer(),
|
||||||
|
EventHandler: c.EventHandler,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
28
internal/net/event_handler.go
Normal file
28
internal/net/event_handler.go
Normal file
|
@ -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, _, 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}
|
||||||
|
}
|
Loading…
Reference in a new issue