The sidecar proxy and gateway identify a request based on the x-request-id header. The sidecar proxy and gateway automatically generate an x-request-id header for requests that are not included in the ASM cluster. If a request already has an x-request-id header, the original request header is cleared by default. The sidecar proxy and gateway automatically generate an x-request-id header for requests within the ASM cluster that do not have this header.
Prerequisites
An ingress gateway is deployed. For more information, see Create an ingress gateway.
The HTTPBin service is deployed in the data plane cluster. For more information, see Deploy the HTTPBin application.
Configuration fields
CustomRequestId supports the following configurations:
Automatically generate an
x-request-idheaderPreserve the existing
x-request-idheader for external requestSet
x-request-idfor response headers
Name | Data type | Required | Valid value | Description |
generate_request_id | String | Optional | "true"(default) | Configures whether to automatically generate an |
preserve_external_request_id | String | Optional | "true"(default) | Configures whether to preserve the existing |
always_set_request_id_in_response | String | Optional | "true"(default) | Configures whether to set |
Sample configurations
Configure to return x-request-id in response headers
Go to the Configure Plug-in tab, enable the CustomRequestId plug-in, set the Plug-in Effective Scope to Gateway Scope, and click Add ASM Gateway to effective scope below to select the gateway where the plug-in takes effect. Configure the plug-in as follows:
generate_request_id: 'true'
preserve_external_request_id: 'false'
always_set_request_id_in_response: 'true'Run the following command to view the response header:
curl {ASM gateway ip}/get -IExpected output:
HTTP/1.1 200 OK
server: istio-envoy
date: Thu, xx xxx 202x 0x:3x:3x GMT
content-type: application/json
content-length: 524
access-control-allow-origin: *
access-control-allow-credentials: true
x-envoy-upstream-service-time: 1
x-request-id: 9ba63dbf-91eb-458a-adb4-61xxxxxxxxThe result shows the automatically generated x-request-id in the response header. This feature can be used to locate abnormal requests during debugging.
Configure to stop automatically generating x-request-id
Configure the plug-in as follows:
generate_request_id: 'false'
preserve_external_request_id: 'false'
always_set_request_id_in_response: 'true'Run the following command to view the response header:
curl {ASM gateway ip}/get -IExpected output:
HTTP/1.1 200 OK
server: istio-envoy
date: Thu, xx xxx 202x 0x:3x:3x GMT
content-type: application/json
content-length: 524
access-control-allow-origin: *
access-control-allow-credentials: true
x-envoy-upstream-service-time: 1The result shows that the gateway no longer automatically generates an x-request-id header for the request.
Configure to preserve the x-request-id in external requests
Configure the plug-in as follows:
generate_request_id: 'true'
preserve_external_request_id: 'true'
always_set_request_id_in_response: 'true'Run the following command to view the response header:
curl {ASM gateway ip}/get -I -H "x-request-id:test"Expected output:
HTTP/1.1 200 OK
server: istio-envoy
date: Thu, xx xxx 202x 0x:3x:3x GMT
content-type: application/json
content-length: 524
access-control-allow-origin: *
access-control-allow-credentials: true
x-envoy-upstream-service-time: 1
x-request-id: testThe result shows that the gateway preserved the externally provided x-request-id for the request, instead of generating a new one.