Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: PreserveExternalRequestID on ClientTrafficPolicy #3225

Merged
merged 2 commits into from May 20, 2024

Conversation

ardikabs
Copy link
Contributor

@ardikabs ardikabs commented Apr 20, 2024

What type of PR is this?
Adds configuration to ClientTrafficPolicy for Headers to support preserving External Request ID (x-request-id).

What this PR does / why we need it:
When it is enabled on Envoy, it will improve the observability experience. This allows users to set their request ID from front-facing applications without being overwritten by Envoy, which is the default behavior.

More reference about the field and its behavior: https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/network/http_connection_manager/v3/http_connection_manager.proto, keyword preserve_external_request_id.

@ardikabs ardikabs requested a review from a team as a code owner April 20, 2024 14:33
@ardikabs ardikabs force-pushed the feat-preserve-external-request-id branch from 5506342 to 20dbafd Compare April 20, 2024 14:39
@zirain
Copy link
Contributor

zirain commented Apr 21, 2024

When it is enabled on Envoy, it will improve the observability experience.

what will happen it will enable this by default?

@ardikabs
Copy link
Contributor Author

what will happen it will enable this by default?

@zirain
I have no idea yet the implication if we enable it by default. One thing for sure, user able to preserve the x-request-id from app or during load balancer stacking.

Reference from Envoy, envoyproxy/envoy#7140.

@zirain
Copy link
Contributor

zirain commented Apr 21, 2024

Whether the connection manager will keep the x-request-id header if passed for a request that is edge (Edge request is the request from external clients to front Envoy) and not reset it, which is the current Envoy behaviour.

so in what user case, we should set it to true?

@ardikabs
Copy link
Contributor Author

@zirain when users intend to manage their own x-request-id from the front (either apps or edge LB). Envoy's current behavior of always overwriting it can be problematic, especially when users intend to utilize the x-request-id header for correlation tracking purposes.

Please also check similar intentions on Istio, about preserving external request id on the Istio gateway, issue istio/istio#10875.

@zirain
Copy link
Contributor

zirain commented Apr 21, 2024

I assume current behavior worked as excepted? What I missed?

curl -v 172.18.255.201  -H "x-request-id: 7fb3693f-4061-4070-95d4-3889aa8a22a5"
*   Trying 172.18.255.201:80...
* Connected to 172.18.255.201 (172.18.255.201) port 80
> GET / HTTP/1.1
> Host: 172.18.255.201
> User-Agent: curl/8.4.0
> Accept: */*
> x-request-id: 7fb3693f-4061-4070-95d4-3889aa8a22a5
>
< HTTP/1.1 200 OK
< content-type: application/json
< x-content-type-options: nosniff
< date: Sun, 21 Apr 2024 03:15:37 GMT
< content-length: 448
<
{
 "path": "/",
 "host": "172.18.255.201",
 "method": "GET",
 "proto": "HTTP/1.1",
 "headers": {
  "Accept": [
   "*/*"
  ],
  "User-Agent": [
   "curl/8.4.0"
  ],
  "X-Envoy-Internal": [
   "true"
  ],
  "X-Forwarded-For": [
   "172.18.0.1"
  ],
  "X-Forwarded-Proto": [
   "http"
  ],
  "X-Request-Id": [
   "7fb3693f-4061-4070-95d4-3889aa8a22a5"
  ]
 },
 "namespace": "default",
 "ingress": "",
 "service": "",
 "pod": "backend-96f75bbf-rzb79"
* Connection #0 to host 172.18.255.201 left intact
}

@ardikabs
Copy link
Contributor Author

ardikabs commented Apr 21, 2024

@zirain i assume you were accessing directly to the envoy proxy, but that's not exactly how it looks, suppose you add an edge LB and then an arbitrary number of proxies in front of your envoy proxy, it might look like the diagram below:

User -> Edge LB (cloudflare) --> (an arbitrary number of proxies before envoy) -> Envoy Proxy

Envoy proxy will overwrite x-request-id if any, check this also envoyproxy/envoy#6050.

@zirain
Copy link
Contributor

zirain commented Apr 21, 2024

@zirain i assume you were accessing directly to the envoy proxy, but that's not exactly how it looks, suppose you add an edge LB and then an arbitrary number of proxies in front of your envoy proxy, it might look like the diagram below:

User -> Edge LB (cloudflare) --> (an arbitrary number of proxies before envoy) -> Envoy Proxy

Envoy proxy will overwrite x-request-id if any, check this also envoyproxy/envoy#6050.

Oh, I got your point.

@zirain i assume you were accessing directly to the envoy proxy, but that's not exactly how it looks, suppose you add an edge LB and then an arbitrary number of proxies in front of your envoy proxy, it might look like the diagram below:

User -> Edge LB (cloudflare) --> (an arbitrary number of proxies before envoy) -> Envoy Proxy

Envoy proxy will overwrite x-request-id if any, check this also envoyproxy/envoy#6050.

Oh, I got your point, seems XffNumTrustedHops didn't help.

@zirain
Copy link
Contributor

zirain commented Apr 21, 2024

I'm thinking about should EG make it default true?

@ardikabs
Copy link
Contributor Author

ardikabs commented Apr 21, 2024

I'm thinking about should EG make it default true?

I voted yes, although I have no idea yet about the implication if it is enabled by default.

@zirain
Copy link
Contributor

zirain commented Apr 21, 2024

cc @envoyproxy/gateway-maintainers PTAL

@ardikabs ardikabs force-pushed the feat-preserve-external-request-id branch from 6e5976b to 0279811 Compare April 21, 2024 14:11
@guydc
Copy link
Contributor

guydc commented Apr 22, 2024

I'm thinking about should EG make it default true?

I'm not familiar with an accepted standard for this header. However, some projects make the following distinctions:

  • X-Request-Id: unique identifier for a each request/response. In this interpretation, sanitizing the header can be seen as the correct behavior.
  • X-Correlation-Id: unique identifier that is stable throughout the entire transactions (chain of requests and responses).

Currently, X-Request-Id can always be used for correlating envoy and backend logs for a specific request/response sequence. If this header is preserved by default and clients generate bad x-request-id (e.g., always have the same value for all requests), this header will not be as useful for troubleshooting envoy <> backend issues.

So, I think that preservation should be an opt-in option for applications that trust their clients to generate meaningful and well-formed x-request-id values that are reliable for troubleshooting issues that occur on envoy <> backend side of things.

@ardikabs ardikabs force-pushed the feat-preserve-external-request-id branch 2 times, most recently from b83313b to e708e9d Compare April 25, 2024 03:23
@ardikabs
Copy link
Contributor Author

/retest

// It defaults to false.
//
// +optional
PreserveExternalRequestID *bool `json:"preserveExternalRequestID,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoughts on PreserveXRequestID ?

the comments highlight the fact that this is opt in and needed when client is external / envoy is edge
cc @envoyproxy/gateway-maintainers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, my initial plan was to use that naming, but I'm trying to mimic Envoy's naming conventions. i have changed just now to PreserveXRequestID

Signed-off-by: Ardika Bagus <me@ardikabs.com>
Signed-off-by: Ardika Bagus <me@ardikabs.com>
@ardikabs ardikabs force-pushed the feat-preserve-external-request-id branch from e708e9d to 984b20e Compare May 15, 2024 02:03
Copy link
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks !

@arkodg arkodg requested review from a team May 15, 2024 02:11
@arkodg
Copy link
Contributor

arkodg commented May 15, 2024

other reviewers, please weigh in on PreserveExternalRequestID vs PreserveXRequestID , is it valuable to keep the envoy naming to reduce confusion ?

@zhaohuabing
Copy link
Member

Prefer PreserveXRequestID as it's clearer. "External" seems somewhat vague to me.

Copy link
Member

@zhaohuabing zhaohuabing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

@zirain
Copy link
Contributor

zirain commented May 18, 2024

+1 on PreserveXRequestID

Copy link
Member

@AliceProxy AliceProxy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@arkodg arkodg merged commit 711d545 into envoyproxy:main May 20, 2024
23 checks passed
@ardikabs ardikabs deleted the feat-preserve-external-request-id branch May 20, 2024 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants