mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
add pprof endpoints, additional spans (#770)
i would split this commit in two if i were a good dev. the pprof stuff is really useful and this only samples when called. this is pretty standard go service stuff. expvar is cool, too. the additional spannos have turned up some interesting tid bits... gonna slide em in
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/fnproject/fn/api/models"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
)
|
||||
|
||||
// HTTPProtocol converts stdin/stdout streams into HTTP/1.1 compliant
|
||||
@@ -22,6 +23,9 @@ type HTTPProtocol struct {
|
||||
func (p *HTTPProtocol) IsStreamable() bool { return true }
|
||||
|
||||
func (h *HTTPProtocol) Dispatch(ctx context.Context, ci CallInfo, w io.Writer) error {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "dispatch_http")
|
||||
defer span.Finish()
|
||||
|
||||
req := ci.Request()
|
||||
|
||||
req.RequestURI = ci.RequestURL() // force set to this, for req.Write to use (TODO? still?)
|
||||
@@ -32,18 +36,25 @@ func (h *HTTPProtocol) Dispatch(ctx context.Context, ci CallInfo, w io.Writer) e
|
||||
req.Header.Set("FN_REQUEST_URL", ci.RequestURL())
|
||||
req.Header.Set("FN_CALL_ID", ci.CallID())
|
||||
|
||||
span, _ = opentracing.StartSpanFromContext(ctx, "dispatch_http_write_request")
|
||||
// req.Write handles if the user does not specify content length
|
||||
err := req.Write(h.in)
|
||||
span.Finish()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
span, _ = opentracing.StartSpanFromContext(ctx, "dispatch_http_read_response")
|
||||
resp, err := http.ReadResponse(bufio.NewReader(h.out), ci.Request())
|
||||
span.Finish()
|
||||
if err != nil {
|
||||
return models.NewAPIError(http.StatusBadGateway, fmt.Errorf("invalid http response from function err: %v", err))
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
span, _ = opentracing.StartSpanFromContext(ctx, "dispatch_http_write_response")
|
||||
defer span.Finish()
|
||||
|
||||
rw, ok := w.(http.ResponseWriter)
|
||||
if !ok {
|
||||
// async / [some] tests go through here. write a full http request to the writer
|
||||
|
||||
Reference in New Issue
Block a user