From 056693d4142e2ed3ff5adb65c0993fb178d6c8b6 Mon Sep 17 00:00:00 2001 From: dimagolomozy Date: Mon, 23 Jan 2023 15:13:20 +0200 Subject: [PATCH 1/2] allow override interval Signed-off-by: dimagolomozy --- manager.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/manager.go b/manager.go index ee59796..67c293b 100644 --- a/manager.go +++ b/manager.go @@ -13,6 +13,7 @@ type LoggerManager struct { TimeDelta float64 // Time difference between local machine and Coralogix servers TimeDeltaLastUpdate int // Last time-delta update time Stopped bool // Is current logger manager stopped + SendInterval time.Duration // Send bulk logs interval LogsBuffer LogBuffer // Logs buffer Credentials // Credentials for Coralogix account Lock sync.WaitGroup // CoralogixLogger manager locker @@ -25,6 +26,7 @@ func NewLoggerManager(PrivateKey string, ApplicationName string, SubsystemName s 0, 0, false, + 0, LogBuffer{}, Credentials{ PrivateKey, @@ -138,10 +140,14 @@ func (manager *LoggerManager) Run() { manager.SendBulk(manager.SyncTime) - if manager.LogsBuffer.Size() > (MaxLogChunkSize / 2) { - NextSendInterval = FastSendSpeedInterval + if manager.SendInterval > 0 { + NextSendInterval = manager.SendInterval } else { - NextSendInterval = NormalSendSpeedInterval + if manager.LogsBuffer.Size() > (MaxLogChunkSize / 2) { + NextSendInterval = FastSendSpeedInterval + } else { + NextSendInterval = NormalSendSpeedInterval + } } DebugLogger.Printf("Next buffer check is scheduled in %.1f seconds\n", NextSendInterval) From c35e3181bcd1da0323508f86a20ad0eb3c4b2ae9 Mon Sep 17 00:00:00 2001 From: dimagolomozy Date: Mon, 23 Jan 2023 15:12:52 +0200 Subject: [PATCH 2/2] convert to time duration Signed-off-by: dimagolomozy --- constant.go | 6 ++++-- manager.go | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/constant.go b/constant.go index 2d0dc79..1edfcdb 100644 --- a/constant.go +++ b/constant.go @@ -1,5 +1,7 @@ package coralogix +import "time" + const ( // MaxLogBufferSize is maximum log buffer size (default=128MiB) MaxLogBufferSize uint64 = 128 * (1024 * 1024) @@ -8,10 +10,10 @@ const ( MaxLogChunkSize uint64 = 1.5 * (1024 * 1024) // NormalSendSpeedInterval is a bulk send interval in normal mode - NormalSendSpeedInterval float64 = 0.5 + NormalSendSpeedInterval = 1 * time.Second // FastSendSpeedInterval is a bulk send interval in fast mode - FastSendSpeedInterval float64 = 0.1 + FastSendSpeedInterval = 500 * time.Millisecond // TimeDelayTimeout is a timeout for time-delay request TimeDelayTimeout uint = 5 diff --git a/manager.go b/manager.go index 67c293b..95bf0cf 100644 --- a/manager.go +++ b/manager.go @@ -128,7 +128,7 @@ func (manager *LoggerManager) SendBulk(SyncTime bool) bool { // Run should work in separate thread and asynchronously operate with logs func (manager *LoggerManager) Run() { - var NextSendInterval float64 + var NextSendInterval time.Duration defer manager.Lock.Done() @@ -151,7 +151,7 @@ func (manager *LoggerManager) Run() { } DebugLogger.Printf("Next buffer check is scheduled in %.1f seconds\n", NextSendInterval) - time.Sleep(time.Duration(NextSendInterval) * time.Second) + time.Sleep(NextSendInterval) } }