From 2388222e98462fdbbe44f3e091b2b79d80956a9a Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Mon, 24 Jun 2019 21:29:31 +0200 Subject: update dependencies Ran a `go get -u` and bumped K8s deps to 1.15.0. Signed-off-by: Valentin Rothberg --- .../apimachinery/pkg/util/runtime/runtime.go | 47 +++++++++++----------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'vendor/k8s.io/apimachinery/pkg/util/runtime') diff --git a/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go b/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go index 1e7d3ce0b..3c886f46c 100644 --- a/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go +++ b/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go @@ -22,7 +22,7 @@ import ( "sync" "time" - "github.com/golang/glog" + "k8s.io/klog" ) var ( @@ -62,27 +62,18 @@ func HandleCrash(additionalHandlers ...func(interface{})) { // logPanic logs the caller tree when a panic occurs. func logPanic(r interface{}) { - callers := getCallers(r) + // Same as stdlib http server code. Manually allocate stack trace buffer size + // to prevent excessively large logs + const size = 64 << 10 + stacktrace := make([]byte, size) + stacktrace = stacktrace[:runtime.Stack(stacktrace, false)] if _, ok := r.(string); ok { - glog.Errorf("Observed a panic: %s\n%v", r, callers) + klog.Errorf("Observed a panic: %s\n%s", r, stacktrace) } else { - glog.Errorf("Observed a panic: %#v (%v)\n%v", r, r, callers) + klog.Errorf("Observed a panic: %#v (%v)\n%s", r, r, stacktrace) } } -func getCallers(r interface{}) string { - callers := "" - for i := 0; true; i++ { - _, file, line, ok := runtime.Caller(i) - if !ok { - break - } - callers = callers + fmt.Sprintf("%v:%v\n", file, line) - } - - return callers -} - // ErrorHandlers is a list of functions which will be invoked when an unreturnable // error occurs. // TODO(lavalamp): for testability, this and the below HandleError function @@ -115,7 +106,7 @@ func HandleError(err error) { // logError prints an error with the call stack of the location it was reported func logError(err error) { - glog.ErrorDepth(2, err) + klog.ErrorDepth(2, err) } type rudimentaryErrorBackoff struct { @@ -132,9 +123,8 @@ func (r *rudimentaryErrorBackoff) OnError(error) { r.lastErrorTimeLock.Lock() defer r.lastErrorTimeLock.Unlock() d := time.Since(r.lastErrorTime) - if d < r.minPeriod && d >= 0 { + if d < r.minPeriod { // If the time moves backwards for any reason, do nothing - // TODO: remove check "d >= 0" after go 1.8 is no longer supported time.Sleep(r.minPeriod - d) } r.lastErrorTime = time.Now() @@ -156,12 +146,23 @@ func GetCaller() string { // handlers to handle errors and panics the same way. func RecoverFromPanic(err *error) { if r := recover(); r != nil { - callers := getCallers(r) + // Same as stdlib http server code. Manually allocate stack trace buffer size + // to prevent excessively large logs + const size = 64 << 10 + stacktrace := make([]byte, size) + stacktrace = stacktrace[:runtime.Stack(stacktrace, false)] *err = fmt.Errorf( - "recovered from panic %q. (err=%v) Call stack:\n%v", + "recovered from panic %q. (err=%v) Call stack:\n%s", r, *err, - callers) + stacktrace) + } +} + +// Must panics on non-nil errors. Useful to handling programmer level errors. +func Must(err error) { + if err != nil { + panic(err) } } -- cgit v1.2.3-54-g00ecf