Skip to content

Commit

Permalink
log/logheap: properly document LogHeap as performing HTTP upload (tai…
Browse files Browse the repository at this point in the history
…lscale#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 <[email protected]>
  • Loading branch information
Emmanuel T Odeke authored Sep 8, 2020
1 parent 9616097 commit 688f923
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions log/logheap/logheap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 688f923

Please sign in to comment.