Skip to content

Commit fef8a88

Browse files
i.makarychevzirain
authored andcommitted
Feat add request id extension settings in ctp
Signed-off-by: i.makarychev <[email protected]> Signed-off-by: i.makarychev <[email protected]>
1 parent f65d853 commit fef8a88

File tree

15 files changed

+273
-0
lines changed

15 files changed

+273
-0
lines changed

api/v1alpha1/clienttrafficpolicy_types.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ type HeaderSettings struct {
166166
//
167167
// +optional
168168
LateResponseHeaders *HTTPHeaderFilter `json:"lateResponseHeaders,omitempty"`
169+
// RequestIDExtension defines configuration for Envoy's request ID extension.
170+
//
171+
// +optional
172+
RequestIDExtension *RequestIDExtensionSettings `json:"requestIdExtension,omitempty"`
169173
}
170174

171175
// WithUnderscoresAction configures the action to take when an HTTP header with underscores
@@ -403,6 +407,34 @@ type ProxyProtocolSettings struct {
403407
Optional *bool `json:"optional,omitempty"`
404408
}
405409

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

408440
// 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.

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_clienttrafficpolicies.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,34 @@ spec:
506506
- Generate
507507
- Disable
508508
type: string
509+
requestIdExtension:
510+
description: RequestIDExtension defines configuration for Envoy's
511+
request ID extension.
512+
properties:
513+
packTraceReason:
514+
default: true
515+
description: |-
516+
PackTraceReason indicates whether the implementation alters the UUID
517+
to contain the trace sampling decision as per the UuidRequestIdConfig
518+
message documentation.
519+
520+
Defaults to true. If disabled, no modification to the UUID will be
521+
performed. Note that if disabled, stable sampling of traces, access logs,
522+
etc. will no longer work and only random sampling will be possible.
523+
524+
Corresponds to Envoy’s `pack_trace_reason`.
525+
type: boolean
526+
useRequestIDForTraceSampling:
527+
default: true
528+
description: |-
529+
UseRequestIDForTraceSampling sets whether to use x-request-id for
530+
sampling decisions. Defaults to true.
531+
532+
See the Envoy context propagation overview for more information.
533+
534+
Corresponds to Envoy’s `use_request_id_for_trace_sampling`.
535+
type: boolean
536+
type: object
509537
withUnderscoresAction:
510538
description: |-
511539
WithUnderscoresAction configures the action to take when an HTTP header with underscores

charts/gateway-helm/crds/generated/gateway.envoyproxy.io_clienttrafficpolicies.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,34 @@ spec:
505505
- Generate
506506
- Disable
507507
type: string
508+
requestIdExtension:
509+
description: RequestIDExtension defines configuration for Envoy's
510+
request ID extension.
511+
properties:
512+
packTraceReason:
513+
default: true
514+
description: |-
515+
PackTraceReason indicates whether the implementation alters the UUID
516+
to contain the trace sampling decision as per the UuidRequestIdConfig
517+
message documentation.
518+
519+
Defaults to true. If disabled, no modification to the UUID will be
520+
performed. Note that if disabled, stable sampling of traces, access logs,
521+
etc. will no longer work and only random sampling will be possible.
522+
523+
Corresponds to Envoy’s `pack_trace_reason`.
524+
type: boolean
525+
useRequestIDForTraceSampling:
526+
default: true
527+
description: |-
528+
UseRequestIDForTraceSampling sets whether to use x-request-id for
529+
sampling decisions. Defaults to true.
530+
531+
See the Envoy context propagation overview for more information.
532+
533+
Corresponds to Envoy’s `use_request_id_for_trace_sampling`.
534+
type: boolean
535+
type: object
508536
withUnderscoresAction:
509537
description: |-
510538
WithUnderscoresAction configures the action to take when an HTTP header with underscores

internal/gatewayapi/clienttrafficpolicy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ func translateListenerHeaderSettings(headerSettings *egv1a1.HeaderSettings, http
646646
EnableEnvoyHeaders: ptr.Deref(headerSettings.EnableEnvoyHeaders, false),
647647
DisableRateLimitHeaders: ptr.Deref(headerSettings.DisableRateLimitHeaders, false),
648648
WithUnderscoresAction: ir.WithUnderscoresAction(ptr.Deref(headerSettings.WithUnderscoresAction, egv1a1.WithUnderscoresActionRejectRequest)),
649+
RequestIDExtension: (*ir.RequestIDExtensionSettings)(headerSettings.RequestIDExtension),
649650
}
650651
if headerSettings.RequestID != nil {
651652
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
@@ -41,6 +41,9 @@ clientTrafficPolicies:
4141
remove:
4242
- "my-removed-response-header"
4343
- "my-removed-response-header"
44+
requestIdExtension:
45+
packTraceReason: false
46+
useRequestIDForTraceSampling: false
4447
targetRef:
4548
group: gateway.networking.k8s.io
4649
kind: Gateway

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ clientTrafficPolicies:
4040
- name: my-multi-set-response-header
4141
value: value1,value2
4242
requestID: PreserveOrGenerate
43+
requestIdExtension:
44+
packTraceReason: false
45+
useRequestIDForTraceSampling: false
4346
withUnderscoresAction: Allow
4447
targetRef:
4548
group: gateway.networking.k8s.io
@@ -215,6 +218,9 @@ xdsIR:
215218
lateRemoveResponseHeaders:
216219
- my-removed-response-header
217220
requestID: PreserveOrGenerate
221+
requestIdExtension:
222+
packTraceReason: false
223+
useRequestIDForTraceSampling: false
218224
withUnderscoresAction: Allow
219225
hostnames:
220226
- '*'
@@ -264,6 +270,9 @@ xdsIR:
264270
lateRemoveResponseHeaders:
265271
- my-removed-response-header
266272
requestID: PreserveOrGenerate
273+
requestIdExtension:
274+
packTraceReason: false
275+
useRequestIDForTraceSampling: false
267276
withUnderscoresAction: Allow
268277
hostnames:
269278
- '*'

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 {
@@ -1203,3 +1205,26 @@ func buildSetCurrentClientCertDetails(in *ir.HeaderSettings) *hcmv3.HttpConnecti
12031205

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

0 commit comments

Comments
 (0)