Răsfoiți Sursa

initial proposal for log limiting

AjayTripathy 5 ani în urmă
părinte
comite
21b6983de7
1 a modificat fișierele cu 14 adăugiri și 1 ștergeri
  1. 14 1
      pkg/log/log.go

+ 14 - 1
pkg/log/log.go

@@ -7,8 +7,21 @@ import (
 	"k8s.io/klog"
 )
 
+var seen = make(map[string]int)
+
+const logTypeLimit = 5
+
 func Errorf(format string, a ...interface{}) {
-	klog.Errorf(fmt.Sprintf("[Error] %s", format), a...)
+	timesLogged, ok := seen[format]
+	if !ok {
+		seen[format] = 1
+	} else if timesLogged > logTypeLimit {
+		f := fmt.Sprintf("[Error] %s", format)
+		klog.Errorf("%s seen more than %d times, suppressing future logs", f, logTypeLimit)
+	} else {
+		seen[format] += 1
+		klog.Errorf(fmt.Sprintf("[Error] %s", format), a...)
+	}
 }
 
 func Warningf(format string, a ...interface{}) {