Set full URL path to request header (#1266)
This commit is contained in:
@@ -27,13 +27,9 @@ import (
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fission/fission/pkg/types"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/satori/go.uuid"
|
||||
"go.opencensus.io/plugin/ochttp"
|
||||
"go.uber.org/zap"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -45,6 +41,7 @@ import (
|
||||
executorClient "github.com/fission/fission/pkg/executor/client"
|
||||
"github.com/fission/fission/pkg/redis"
|
||||
"github.com/fission/fission/pkg/throttler"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -290,6 +287,8 @@ func (roundTripper RetryingRoundTripper) RoundTrip(req *http.Request) (*http.Res
|
||||
|
||||
overhead := time.Since(startTime)
|
||||
|
||||
roundTripper.logger.Debug("request headers", zap.Any("headers", req.Header))
|
||||
|
||||
// forward the request to the function service
|
||||
resp, err = ocRoundTripper.RoundTrip(req)
|
||||
if err == nil {
|
||||
@@ -407,25 +406,13 @@ func (fh *functionHandler) tapService(serviceUrl *url.URL) {
|
||||
}
|
||||
|
||||
func (fh functionHandler) handler(responseWriter http.ResponseWriter, request *http.Request) {
|
||||
// retrieve url params and add them to request header
|
||||
vars := mux.Vars(request)
|
||||
for k, v := range vars {
|
||||
request.Header.Set(fmt.Sprintf("X-Fission-Params-%v", k), v)
|
||||
}
|
||||
|
||||
var reqUID string
|
||||
if len(fh.recorderName) > 0 {
|
||||
UID := strings.ToLower(uuid.NewV4().String())
|
||||
reqUID = "REQ" + UID
|
||||
request.Header.Set("X-Fission-ReqUID", reqUID)
|
||||
fh.logger.Debug("record request", zap.String("request_id", reqUID))
|
||||
}
|
||||
|
||||
if fh.httpTrigger != nil && fh.httpTrigger.Spec.FunctionReference.Type == types.FunctionReferenceTypeFunctionWeights {
|
||||
// canary deployment. need to determine the function to send request to now
|
||||
fnMetadata := getCanaryBackend(fh.functionMetadataMap, fh.fnWeightDistributionList)
|
||||
if fnMetadata == nil {
|
||||
fh.logger.Error("could not get canary backend", zap.String("request_id", reqUID))
|
||||
fh.logger.Error("could not get canary backend",
|
||||
zap.Any("metadataMap", fh.functionMetadataMap),
|
||||
zap.Any("distributionList", fh.fnWeightDistributionList))
|
||||
// TODO : write error to responseWrite and return response
|
||||
return
|
||||
}
|
||||
@@ -433,8 +420,14 @@ func (fh functionHandler) handler(responseWriter http.ResponseWriter, request *h
|
||||
fh.logger.Debug("chosen function backend's metadata", zap.Any("metadata", fh.function))
|
||||
}
|
||||
|
||||
// set record id
|
||||
setRecordRequestIDHeader(fh.recorderName, request)
|
||||
|
||||
// url path
|
||||
setPathInfoToHeader(request)
|
||||
|
||||
// system params
|
||||
MetadataToHeaders(HEADERS_FISSION_FUNCTION_PREFIX, fh.function, request)
|
||||
setFunctionMetadataToHeader(fh.function, request)
|
||||
|
||||
director := func(req *http.Request) {
|
||||
if _, ok := req.Header["User-Agent"]; !ok {
|
||||
|
||||
Reference in New Issue
Block a user