Move creation of periodic stats task inside proxy library

This adds a new type of SnowflakeEvent. EventOnProxyStats is triggered
by the periodic task run at SummaryInterval and produces an event with a
proxy stats output string.
This commit is contained in:
Cecylia Bocovich 2023-10-28 16:04:09 -04:00
parent 83a7422fe6
commit 354cb65432
No known key found for this signature in database
GPG key ID: 009DE379FD9B7B90
4 changed files with 54 additions and 19 deletions

View file

@ -139,6 +139,14 @@ type SnowflakeProxy struct {
ProxyType string
EventDispatcher event.SnowflakeEventDispatcher
shutdown chan struct{}
// DisableStatsLogger indicates whether proxy stats will be logged periodically
DisableStatsLogger bool
// SummaryInterval is the time interval at which proxy stats will be logged
SummaryInterval time.Duration
periodicProxyStats *periodicProxyStats
bytesLogger bytesLogger
}
// Checks whether an IP address is a remote address for the client
@ -654,6 +662,10 @@ func (sf *SnowflakeProxy) Start() error {
sf.EventDispatcher = event.NewSnowflakeEventDispatcher()
}
if !sf.DisableStatsLogger {
sf.periodicProxyStats = newPeriodicProxyStats(sf.SummaryInterval, sf.EventDispatcher)
}
broker, err = newSignalingServer(sf.BrokerURL, sf.KeepLocalAddresses)
if err != nil {
return fmt.Errorf("error configuring broker: %s", err)