Merge pull request #3918 from levertonai/request-id-for-default-backend-too
Set `X-Request-ID` for the `default-backend`, too.
This commit is contained in:
commit
421411538d
4 changed files with 20 additions and 11 deletions
|
@ -3,15 +3,16 @@
|
|||
When the [`custom-http-errors`][cm-custom-http-errors] option is enabled, the Ingress controller configures NGINX so
|
||||
that it passes several HTTP headers down to its `default-backend` in case of error:
|
||||
|
||||
| Header | Value |
|
||||
| ---------------- | ------------------------------------------------ |
|
||||
| `X-Code` | HTTP status code retuned by the request |
|
||||
| `X-Format` | Value of the `Accept` header sent by the client |
|
||||
| `X-Original-URI` | URI that caused the error |
|
||||
| `X-Namespace` | Namespace where the backend Service is located |
|
||||
| `X-Ingress-Name` | Name of the Ingress where the backend is defined |
|
||||
| `X-Service-Name` | Name of the Service backing the backend |
|
||||
| `X-Service-Port` | Port number of the Service backing the backend |
|
||||
| Header | Value |
|
||||
| ---------------- | ------------------------------------------------------------------- |
|
||||
| `X-Code` | HTTP status code retuned by the request |
|
||||
| `X-Format` | Value of the `Accept` header sent by the client |
|
||||
| `X-Original-URI` | URI that caused the error |
|
||||
| `X-Namespace` | Namespace where the backend Service is located |
|
||||
| `X-Ingress-Name` | Name of the Ingress where the backend is defined |
|
||||
| `X-Service-Name` | Name of the Service backing the backend |
|
||||
| `X-Service-Port` | Port number of the Service backing the backend |
|
||||
| `X-Request-ID` | Unique ID that identifies the request - same as for backend service |
|
||||
|
||||
A custom error backend can use this information to return the best possible representation of an error page. For
|
||||
example, if the value of the `Accept` header send by the client was `application/json`, a carefully crafted backend
|
||||
|
|
|
@ -34,7 +34,7 @@ const (
|
|||
// FormatHeader name of the header used to extract the format
|
||||
FormatHeader = "X-Format"
|
||||
|
||||
// CodeHeader name of the header used as source of the HTTP statu code to return
|
||||
// CodeHeader name of the header used as source of the HTTP status code to return
|
||||
CodeHeader = "X-Code"
|
||||
|
||||
// ContentType name of the header that defines the format of the reply
|
||||
|
@ -55,6 +55,9 @@ const (
|
|||
// ServicePort name of the header that contains the matched Service port in the Ingress
|
||||
ServicePort = "X-Service-Port"
|
||||
|
||||
// RequestId is a unique ID that identifies the request - same as for backend service
|
||||
RequestId = "X-Request-ID"
|
||||
|
||||
// ErrFilesPathVar is the name of the environment variable indicating
|
||||
// the location on disk of files served by the handler.
|
||||
ErrFilesPathVar = "ERROR_FILES_PATH"
|
||||
|
@ -91,6 +94,7 @@ func errorHandler(path string) func(http.ResponseWriter, *http.Request) {
|
|||
w.Header().Set(IngressName, r.Header.Get(IngressName))
|
||||
w.Header().Set(ServiceName, r.Header.Get(ServiceName))
|
||||
w.Header().Set(ServicePort, r.Header.Get(ServicePort))
|
||||
w.Header().Set(RequestId, r.Header.Get(RequestId))
|
||||
}
|
||||
|
||||
format := r.Header.Get(FormatHeader)
|
||||
|
|
|
@ -815,6 +815,7 @@ stream {
|
|||
proxy_set_header X-Ingress-Name $ingress_name;
|
||||
proxy_set_header X-Service-Name $service_name;
|
||||
proxy_set_header X-Service-Port $service_port;
|
||||
proxy_set_header X-Request-ID $req_id;
|
||||
proxy_set_header Host $best_http_host;
|
||||
|
||||
set $proxy_upstream_name {{ $upstreamName }};
|
||||
|
@ -1318,6 +1319,7 @@ stream {
|
|||
proxy_set_header X-Ingress-Name $ingress_name;
|
||||
proxy_set_header X-Service-Name $service_name;
|
||||
proxy_set_header X-Service-Port $service_port;
|
||||
proxy_set_header X-Request-ID $req_id;
|
||||
{{ end }}
|
||||
|
||||
{{ if $location.Satisfy }}
|
||||
|
|
|
@ -53,9 +53,11 @@ var _ = framework.IngressNginxDescribe("Annotations - custom default-backend", f
|
|||
})
|
||||
|
||||
uri := "/alma/armud"
|
||||
requestId := "something-unique"
|
||||
resp, body, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)+uri).
|
||||
Set("Host", host).
|
||||
Set("x-request-id", requestId).
|
||||
End()
|
||||
|
||||
Expect(errs).Should(BeEmpty())
|
||||
|
@ -64,7 +66,7 @@ var _ = framework.IngressNginxDescribe("Annotations - custom default-backend", f
|
|||
Expect(body).To(ContainSubstring("x-code=503"))
|
||||
Expect(body).To(ContainSubstring(fmt.Sprintf("x-ingress-name=%s", host)))
|
||||
Expect(body).To(ContainSubstring("x-service-name=invalid"))
|
||||
Expect(body).To(ContainSubstring(fmt.Sprintf("x-original-uri=%s", uri)))
|
||||
Expect(body).To(ContainSubstring(fmt.Sprintf("x-request-id=%s", requestId)))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue