From 688f923db16daa99f21173cc00bc86c22d5ed3fa Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Mon, 7 Sep 2020 19:17:53 -0700 Subject: [PATCH] log/logheap: properly document LogHeap as performing HTTP upload (#741) LogHeap no longer logs to os.Stderr and instead uploads the heap profile by means of an HTTP POST request to the target URL endpoint. While here, also ensured that an error from pprof.WriteHeapProfile isn't ignored and will prevent the HTTP request from being made if non-nil. Signed-off-by: Emmanuel T Odeke --- log/logheap/logheap.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/log/logheap/logheap.go b/log/logheap/logheap.go index 93f018dc3..f4a30bf69 100644 --- a/log/logheap/logheap.go +++ b/log/logheap/logheap.go @@ -15,15 +15,18 @@ import ( "time" ) -// LogHeap writes a JSON logtail record with the base64 heap pprof to -// os.Stderr. +// LogHeap uploads a JSON logtail record with the base64 heap pprof by means +// of an HTTP POST request to the endpoint referred to in postURL. func LogHeap(postURL string) { if postURL == "" { return } runtime.GC() buf := new(bytes.Buffer) - pprof.WriteHeapProfile(buf) + if err := pprof.WriteHeapProfile(buf); err != nil { + log.Printf("LogHeap: %v", err) + return + } ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel()