Skip to content

Commit

Permalink
feat(sdk): add pprof label on http client (#3435)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamin authored and bnjjj committed Oct 10, 2018
1 parent e3413a6 commit 054fef0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sdk/cdsclient/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"log"
"net/http"
"net/http/httputil"
"runtime/pprof"
"strings"

"github.com/ovh/cds/sdk"
Expand Down Expand Up @@ -160,6 +161,10 @@ func (c *client) Request(ctx context.Context, method string, path string, body i

// Stream makes an authenticated http request and return io.ReadCloser
func (c *client) Stream(ctx context.Context, method string, path string, body io.Reader, noTimeout bool, mods ...RequestModifier) (io.ReadCloser, http.Header, int, error) {
labels := pprof.Labels("user-agent", c.config.userAgent, "path", path, "method", method)
ctx = pprof.WithLabels(ctx, labels)
pprof.SetGoroutineLabels(ctx)

var savederror error

var bodyContent []byte
Expand Down
5 changes: 5 additions & 0 deletions sdk/cdsclient/http_sse.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/base64"
"io"
"net/http"
"runtime/pprof"
"strings"
)

Expand All @@ -27,6 +28,10 @@ type SSEvent struct {
// close the stream. This is blocking, and so you will likely want to call this
// in a new goroutine (via `go c.RequestSSEGet(..)`)
func (c *client) RequestSSEGet(ctx context.Context, path string, evCh chan<- SSEvent, mods ...RequestModifier) error {
labels := pprof.Labels("user-agent", c.config.userAgent, "path", path, "method", "GET")
ctx = pprof.WithLabels(ctx, labels)
pprof.SetGoroutineLabels(ctx)

uri := c.config.Host + path
if strings.HasPrefix(path, "http") {
uri = path
Expand Down

0 comments on commit 054fef0

Please sign in to comment.