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 <emmanuel@orijtech.com>
This commit is contained in:
Emmanuel T Odeke 2020-09-07 19:17:53 -07:00 committed by GitHub
parent 96160973ce
commit 688f923db1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -15,15 +15,18 @@ import (
"time" "time"
) )
// LogHeap writes a JSON logtail record with the base64 heap pprof to // LogHeap uploads a JSON logtail record with the base64 heap pprof by means
// os.Stderr. // of an HTTP POST request to the endpoint referred to in postURL.
func LogHeap(postURL string) { func LogHeap(postURL string) {
if postURL == "" { if postURL == "" {
return return
} }
runtime.GC() runtime.GC()
buf := new(bytes.Buffer) 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) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()