Skip to content
Snippets Groups Projects
Commit b1e92f6b authored by Alex Ellis's avatar Alex Ellis
Browse files

Add call-id via middleware


Signed-off-by: default avatarAlex Ellis <alexellis2@gmail.com>
parent e6eec64c
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,23 @@ The gateway will scale functions according to demand by altering the service rep
Swagger docs: https://github.com/openfaas/faas/tree/master/api-docs
**Environmental overrides:**
## Logs
Logs are available at the function level and can be accessed through Swarm or Kubernetes using native tooling. You can also install a Docker logging driver to aggregate your logs. By default functions will not write the request and response bodies to stdout. You can toggle this behaviour by setting `read_debug` for the request and `write_debug` for the response.
## Tracing
An "X-Call-Id" header is applied to every incoming call through the gateway and is usable for tracing and monitoring calls. We use a UUID for this string.
Header:
```
X-Call-Id
```
Within a function this is available as `Http_X_Call_Id`.
## Environmental overrides
The gateway can be configured through the following environment variables:
| Option | Usage |
......
package handlers
import (
"fmt"
"net/http"
"time"
"github.com/docker/distribution/uuid"
)
// MakeCallIDMiddleware middleware tags a request with a uid
func MakeCallIDMiddleware(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
callID := uuid.Generate().String()
r.Header.Add("X-Call-Id", callID)
w.Header().Add("X-Call-Id", callID)
r.Header.Add("X-Start-Time", fmt.Sprintf("%d", start.UTC().UnixNano()))
w.Header().Add("X-Start-Time", fmt.Sprintf("%d", start.UTC().UnixNano()))
next(w, r)
}
}
......@@ -108,7 +108,7 @@ func main() {
prometheusQuery := metrics.NewPrometheusQuery(config.PrometheusHost, config.PrometheusPort, &http.Client{})
listFunctions := metrics.AddMetricsHandler(faasHandlers.ListFunctions, prometheusQuery)
faasHandlers.Proxy = internalHandlers.MakeCallIDMiddleware(faasHandlers.Proxy)
r := mux.NewRouter()
// r.StrictSlash(false) // This didn't work, so register routes twice.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment