Detect if header injected request_id before creating one

This commit is contained in:
Giancarlo Rubio 2018-04-17 14:32:43 +02:00
parent 4bc943a77d
commit c60ed24f4b
5 changed files with 11 additions and 4 deletions

View file

@ -4,7 +4,7 @@ metadata:
name: nginx-configuration-snippet
annotations:
nginx.ingress.kubernetes.io/configuration-snippet: |
more_set_headers "Request-Id: $request_id";
more_set_headers "Request-Id: $req_id";
spec:
rules:

View file

@ -207,7 +207,7 @@ Using this annotation you can add additional configuration to the NGINX location
```yaml
nginx.ingress.kubernetes.io/configuration-snippet: |
more_set_headers "Request-Id: $request_id";
more_set_headers "Request-Id: $req_id";
```
### Default Backend

View file

@ -332,7 +332,7 @@ Example for json output:
```console
log-format-upstream: '{ "time": "$time_iso8601", "remote_addr": "$proxy_protocol_addr",
"x-forward-for": "$proxy_add_x_forwarded_for", "request_id": "$request_id", "remote_user":
"x-forward-for": "$proxy_add_x_forwarded_for", "request_id": "$req_id", "remote_user":
"$remote_user", "bytes_sent": $bytes_sent, "request_time": $request_time, "status":
$status, "vhost": "$host", "request_proto": "$server_protocol", "path": "$uri",
"request_query": "$args", "request_length": $request_length, "duration": $request_time,

File diff suppressed because one or more lines are too long

View file

@ -273,6 +273,13 @@ http {
'' $this_host;
}
# Reverse proxies can detect if a client provides a X-Request-ID header, and pass it on to the backend server.
# If no such header is provided, it can provide a random value.
map $http_x_request_id $req_id {
default $http_x_request_id;
"" $request_id;
}
{{ if $cfg.ComputeFullForwardedFor }}
# We can't use $proxy_add_x_forwarded_for because the realip module
# replaces the remote_addr too soon