Skip to content

Commit c163766

Browse files
author
i.makarychev
committed
Feat add request id extension settings in ctp
Signed-off-by: i.makarychev <[email protected]> Signed-off-by: i.makarychev <[email protected]>
1 parent 9935819 commit c163766

File tree

11 files changed

+161
-0
lines changed

11 files changed

+161
-0
lines changed

api/v1alpha1/clienttrafficpolicy_types.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ type HeaderSettings struct {
164164
//
165165
// +optional
166166
LateResponseHeaders *HTTPHeaderFilter `json:"lateResponseHeaders,omitempty"`
167+
// RequestIDExtension defines configuration for Envoy's request ID extension.
168+
//
169+
// +optional
170+
RequestIDExtension *RequestIDExtensionSettings `json:"requestIdExtension,omitempty"`
167171
}
168172

169173
// WithUnderscoresAction configures the action to take when an HTTP header with underscores
@@ -393,6 +397,34 @@ type ProxyProtocolSettings struct {
393397
Optional *bool `json:"optional,omitempty"`
394398
}
395399

400+
// RequestIDExtension defines configuration for the UUID request ID extension.
401+
type RequestIDExtensionSettings struct {
402+
// PackTraceReason indicates whether the implementation alters the UUID
403+
// to contain the trace sampling decision as per the UuidRequestIdConfig
404+
// message documentation.
405+
//
406+
// Defaults to true. If disabled, no modification to the UUID will be
407+
// performed. Note that if disabled, stable sampling of traces, access logs,
408+
// etc. will no longer work and only random sampling will be possible.
409+
//
410+
// Corresponds to Envoy’s `pack_trace_reason`.
411+
//
412+
// +kubebuilder:default=true
413+
// +optional
414+
PackTraceReason *bool `json:"packTraceReason,omitempty"`
415+
416+
// UseRequestIDForTraceSampling sets whether to use x-request-id for
417+
// sampling decisions. Defaults to true.
418+
//
419+
// See the Envoy context propagation overview for more information.
420+
//
421+
// Corresponds to Envoy’s `use_request_id_for_trace_sampling`.
422+
//
423+
// +kubebuilder:default=true
424+
// +optional
425+
UseRequestIDForTraceSampling *bool `json:"useRequestIDForTraceSampling,omitempty"`
426+
}
427+
396428
//+kubebuilder:object:root=true
397429

398430
// ClientTrafficPolicyList contains a list of ClientTrafficPolicy resources.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/gatewayapi/clienttrafficpolicy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ func translateListenerHeaderSettings(headerSettings *egv1a1.HeaderSettings, http
644644
EnableEnvoyHeaders: ptr.Deref(headerSettings.EnableEnvoyHeaders, false),
645645
DisableRateLimitHeaders: ptr.Deref(headerSettings.DisableRateLimitHeaders, false),
646646
WithUnderscoresAction: ir.WithUnderscoresAction(ptr.Deref(headerSettings.WithUnderscoresAction, egv1a1.WithUnderscoresActionRejectRequest)),
647+
RequestIDExtension: (*ir.RequestIDExtensionSettings)(headerSettings.RequestIDExtension),
647648
}
648649
if headerSettings.RequestID != nil {
649650
httpIR.Headers.RequestID = (*ir.RequestIDAction)(headerSettings.RequestID)

internal/gatewayapi/testdata/clienttrafficpolicy-headers.in.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ clientTrafficPolicies:
3737
remove:
3838
- "my-removed-response-header"
3939
- "my-removed-response-header"
40+
requestIdExtension:
41+
packTraceReason: false
42+
useRequestIDForTraceSampling: false
4043
targetRef:
4144
group: gateway.networking.k8s.io
4245
kind: Gateway

internal/gatewayapi/testdata/clienttrafficpolicy-headers.out.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ clientTrafficPolicies:
3636
- name: my-set-response-header
3737
value: my-set-response-header-value
3838
requestID: PreserveOrGenerate
39+
requestIdExtension:
40+
packTraceReason: false
41+
useRequestIDForTraceSampling: false
3942
withUnderscoresAction: Allow
4043
targetRef:
4144
group: gateway.networking.k8s.io
@@ -203,6 +206,9 @@ xdsIR:
203206
lateRemoveResponseHeaders:
204207
- my-removed-response-header
205208
requestID: PreserveOrGenerate
209+
requestIdExtension:
210+
packTraceReason: false
211+
useRequestIDForTraceSampling: false
206212
withUnderscoresAction: Allow
207213
hostnames:
208214
- '*'
@@ -244,6 +250,9 @@ xdsIR:
244250
lateRemoveResponseHeaders:
245251
- my-removed-response-header
246252
requestID: PreserveOrGenerate
253+
requestIdExtension:
254+
packTraceReason: false
255+
useRequestIDForTraceSampling: false
247256
withUnderscoresAction: Allow
248257
hostnames:
249258
- '*'

internal/ir/xds.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,10 @@ func (c *CredentialInjection) Validate() error {
687687
// +k8s:deepcopy-gen=true
688688
type HealthCheckSettings egv1a1.HealthCheckSettings
689689

690+
// RequestIDExtension defines configuration for the UUID request ID extension.
691+
// +k8s:deepcopy-gen=true
692+
type RequestIDExtensionSettings egv1a1.RequestIDExtensionSettings
693+
690694
// HeaderSettings provides configuration related to header processing on the listener.
691695
// +k8s:deepcopy-gen=true
692696
type HeaderSettings struct {
@@ -725,6 +729,9 @@ type HeaderSettings struct {
725729

726730
// LateRemoveResponseHeaders defines headers that would be removed after envoy response processing.
727731
LateRemoveResponseHeaders []string `json:"lateRemoveResponseHeaders,omitempty" yaml:"earlyRemoveRequestHeaders,omitempty"`
732+
733+
// RequestIDExtension defines configuration for the UUID request ID extension.
734+
RequestIDExtension *RequestIDExtensionSettings `json:"requestIdExtension,omitempty" yaml:"requestIdExtension,omitempty"`
728735
}
729736

730737
// ClientTimeout sets the timeout configuration for downstream connections

internal/ir/zz_generated.deepcopy.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/xds/translator/listener.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
preservecasev3 "github.com/envoyproxy/go-control-plane/envoy/extensions/http/header_formatters/preserve_case/v3"
2626
customheaderv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/http/original_ip_detection/custom_header/v3"
2727
xffv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/http/original_ip_detection/xff/v3"
28+
uuidv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/request_id/uuid/v3"
2829
quicv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/quic/v3"
2930
tlsv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3"
3031
typev3 "github.com/envoyproxy/go-control-plane/envoy/type/v3"
@@ -371,6 +372,7 @@ func (t *Translator) addHCMToXDSListener(
371372
Tracing: hcmTracing,
372373
ForwardClientCertDetails: buildForwardClientCertDetailsAction(irListener.Headers),
373374
EarlyHeaderMutationExtensions: buildEarlyHeaderMutation(irListener.Headers),
375+
RequestIdExtension: buildRequestIDExtension(irListener.Headers),
374376
}
375377

376378
if requestID := ptr.Deref(irListener.Headers, ir.HeaderSettings{}).RequestID; requestID != nil {
@@ -1200,3 +1202,26 @@ func buildSetCurrentClientCertDetails(in *ir.HeaderSettings) *hcmv3.HttpConnecti
12001202

12011203
return clientCertDetails
12021204
}
1205+
1206+
func buildRequestIDExtension(headers *ir.HeaderSettings) *hcmv3.RequestIDExtension {
1207+
if headers == nil || headers.RequestIDExtension == nil {
1208+
return nil
1209+
}
1210+
1211+
ridExt := headers.RequestIDExtension
1212+
cfg := &uuidv3.UuidRequestIdConfig{}
1213+
1214+
if ridExt.PackTraceReason != nil {
1215+
cfg.PackTraceReason = wrapperspb.Bool(*ridExt.PackTraceReason)
1216+
}
1217+
1218+
if ridExt.UseRequestIDForTraceSampling != nil {
1219+
cfg.UseRequestIdForTraceSampling = wrapperspb.Bool(*ridExt.UseRequestIDForTraceSampling)
1220+
}
1221+
1222+
requestIDConfig, _ := proto.ToAnyWithValidation(cfg)
1223+
1224+
return &hcmv3.RequestIDExtension{
1225+
TypedConfig: requestIDConfig,
1226+
}
1227+
}

internal/xds/translator/testdata/in/xds-ir/http-late-header-mutation.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ http:
4949
lateRemoveResponseHeaders:
5050
- "some-header5"
5151
- "some-header6"
52+
requestIdExtension:
53+
packTraceReason: false
54+
useRequestIDForTraceSampling: false
5255
routes:
5356
- name: "second-route"
5457
hostname: "*"

internal/xds/translator/testdata/out/xds-ir/http-late-header-mutation.listeners.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@
9999
ads: {}
100100
resourceApiVersion: V3
101101
routeConfigName: second-listener
102+
requestIdExtension:
103+
typedConfig:
104+
'@type': type.googleapis.com/envoy.extensions.request_id.uuid.v3.UuidRequestIdConfig
105+
packTraceReason: false
106+
useRequestIdForTraceSampling: false
102107
serverHeaderTransformation: PASS_THROUGH
103108
statPrefix: http-10081
104109
useRemoteAddress: true

0 commit comments

Comments
 (0)