mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 20:37:12 +01:00
34fdc8881b
* vmagent: add error log for skipped data block when rejected by receiving side Previously, rejected data blocks were silently dropped - only metrics were update. From operational perspective, having an additional logging for such cases is preferable. https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1911 Signed-off-by: hagen1778 <roman@victoriametrics.com> * vmagent: throttle log messages about skipped blocks The new type of logger was added to logger pacakge. This new type supposed to control number of logged messages by time. Signed-off-by: hagen1778 <roman@victoriametrics.com> * lib/logger: make LogThrottler public, so its methods can be inspected by external packages Co-authored-by: Aliaksandr Valialkin <valyala@victoriametrics.com>
41 lines
852 B
Go
41 lines
852 B
Go
package logger
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestLoggerWithThrottler(t *testing.T) {
|
|
lName := "test"
|
|
lThrottle := 50 * time.Millisecond
|
|
|
|
lt := WithThrottler(lName, lThrottle)
|
|
var i int
|
|
lt.warnF = func(format string, args ...interface{}) {
|
|
i++
|
|
}
|
|
|
|
lt.Warnf("")
|
|
lt.Warnf("")
|
|
lt.Warnf("")
|
|
|
|
if i != 1 {
|
|
t.Fatalf("expected logger will be throttled to 1; got %d instead", i)
|
|
}
|
|
|
|
time.Sleep(lThrottle * 2) // wait to throttle to fade off
|
|
// the same logger supposed to be return for the same name
|
|
WithThrottler(lName, lThrottle).Warnf("")
|
|
if i != 2 {
|
|
t.Fatalf("expected logger to have 2 iterations; got %d instead", i)
|
|
}
|
|
|
|
logThrottlerRegistryMu.Lock()
|
|
registeredN := len(logThrottlerRegistry)
|
|
logThrottlerRegistryMu.Unlock()
|
|
|
|
if registeredN != 1 {
|
|
t.Fatalf("expected only 1 logger to be registered; got %d", registeredN)
|
|
}
|
|
}
|