All Products
Search
Document Center

Alibaba Cloud Service Mesh:CustomRequestId plugin

Last Updated:Nov 06, 2024

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

Configuration fields

CustomRequestId supports the following configurations:

  • Automatically generate an x-request-id header

  • Preserve the existing x-request-id header for external request

  • Set x-request-id for response headers

Name

Data type

Required

Valid value

Description

generate_request_id

String

Optional

"true"(default)

Configures whether to automatically generate an x-request-id header.

preserve_external_request_id

String

Optional

"true"(default)

Configures whether to preserve the existing x-request-id header for the external request.

always_set_request_id_in_response

String

Optional

"true"(default)

Configures whether to set x-request-id for response headers.

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 -I

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: 9ba63dbf-91eb-458a-adb4-61xxxxxxxx

The 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 -I

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

The 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: test

The result shows that the gateway preserved the externally provided x-request-id for the request, instead of generating a new one.