Skip to content

Commit c4b0557

Browse files
committed
feat: support client and overall tracing sampling
1 parent 4eed2f8 commit c4b0557

28 files changed

Lines changed: 894 additions & 59 deletions

api/v1alpha1/envoyproxy_tracing_types.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
99

1010
// ProxyTracing defines the tracing configuration for a proxy.
1111
// +kubebuilder:validation:XValidation:message="only one of SamplingRate or SamplingFraction can be specified",rule="!(has(self.samplingRate) && has(self.samplingFraction))"
12+
// +kubebuilder:validation:XValidation:message="only one of ClientSamplingRate or ClientSamplingFraction can be specified",rule="!(has(self.clientSamplingRate) && has(self.clientSamplingFraction))"
13+
// +kubebuilder:validation:XValidation:message="only one of OverallSamplingRate or OverallSamplingFraction can be specified",rule="!(has(self.overallSamplingRate) && has(self.overallSamplingFraction))"
1214
type ProxyTracing struct {
1315
Tracing `json:",inline"`
1416
// SamplingRate controls the rate at which traffic will be
@@ -22,6 +24,28 @@ type ProxyTracing struct {
2224
// +kubebuilder:validation:Maximum=100
2325
// +optional
2426
SamplingRate *uint32 `json:"samplingRate,omitempty"`
27+
// ClientSamplingRate controls the rate at which traffic will be
28+
// selected for tracing when requested by the client.
29+
// Defaults to 100, valid values [0-100]. 100 indicates 100% sampling.
30+
//
31+
// Only one of ClientSamplingRate or ClientSamplingFraction may be specified.
32+
// If neither field is specified, all client requests will be sampled.
33+
//
34+
// +kubebuilder:validation:Minimum=0
35+
// +kubebuilder:validation:Maximum=100
36+
// +optional
37+
ClientSamplingRate *uint32 `json:"clientSamplingRate,omitempty"`
38+
// OverallSamplingRate controls the rate at which traffic will be
39+
// selected for tracing after all other sampling checks have been applied.
40+
// Defaults to 100, valid values [0-100]. 100 indicates 100% sampling.
41+
//
42+
// Only one of OverallSamplingRate or OverallSamplingFraction may be specified.
43+
// If neither field is specified, all requests will be sampled.
44+
//
45+
// +kubebuilder:validation:Minimum=0
46+
// +kubebuilder:validation:Maximum=100
47+
// +optional
48+
OverallSamplingRate *uint32 `json:"overallSamplingRate,omitempty"`
2549
// Provider defines the tracing provider.
2650
Provider TracingProvider `json:"provider"`
2751
}

api/v1alpha1/shared_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,16 @@ type Tracing struct {
941941
//
942942
// +optional
943943
SamplingFraction *gwapiv1.Fraction `json:"samplingFraction,omitempty"`
944+
// ClientSamplingFraction represents the fraction of requests that should be
945+
// selected for tracing when requested by the client.
946+
//
947+
// +optional
948+
ClientSamplingFraction *gwapiv1.Fraction `json:"clientSamplingFraction,omitempty"`
949+
// OverallSamplingFraction represents the fraction of requests that should be
950+
// selected for tracing after all other sampling checks have been applied.
951+
//
952+
// +optional
953+
OverallSamplingFraction *gwapiv1.Fraction `json:"overallSamplingFraction,omitempty"`
944954
// CustomTags defines the custom tags to add to each span.
945955
// If provider is kubernetes, pod name and namespace are added by default.
946956
//

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 20 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_backendtrafficpolicies.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3152,6 +3152,26 @@ spec:
31523152
31533153
This takes precedence over EnvoyProxy tracing when set.
31543154
properties:
3155+
clientSamplingFraction:
3156+
description: |-
3157+
ClientSamplingFraction represents the fraction of requests that should be
3158+
selected for tracing when requested by the client.
3159+
properties:
3160+
denominator:
3161+
default: 100
3162+
format: int32
3163+
minimum: 1
3164+
type: integer
3165+
numerator:
3166+
format: int32
3167+
minimum: 0
3168+
type: integer
3169+
required:
3170+
- numerator
3171+
type: object
3172+
x-kubernetes-validations:
3173+
- message: numerator must be less than or equal to denominator
3174+
rule: self.numerator <= self.denominator
31553175
customTags:
31563176
additionalProperties:
31573177
properties:
@@ -3216,6 +3236,26 @@ spec:
32163236
32173237
Deprecated: Use Tags instead.
32183238
type: object
3239+
overallSamplingFraction:
3240+
description: |-
3241+
OverallSamplingFraction represents the fraction of requests that should be
3242+
selected for tracing after all other sampling checks have been applied.
3243+
properties:
3244+
denominator:
3245+
default: 100
3246+
format: int32
3247+
minimum: 1
3248+
type: integer
3249+
numerator:
3250+
format: int32
3251+
minimum: 0
3252+
type: integer
3253+
required:
3254+
- numerator
3255+
type: object
3256+
x-kubernetes-validations:
3257+
- message: numerator must be less than or equal to denominator
3258+
rule: self.numerator <= self.denominator
32193259
samplingFraction:
32203260
description: |-
32213261
SamplingFraction represents the fraction of requests that should be

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16327,6 +16327,38 @@ spec:
1632716327
Tracing defines tracing configuration for managed proxies.
1632816328
If unspecified, will not send tracing data.
1632916329
properties:
16330+
clientSamplingFraction:
16331+
description: |-
16332+
ClientSamplingFraction represents the fraction of requests that should be
16333+
selected for tracing when requested by the client.
16334+
properties:
16335+
denominator:
16336+
default: 100
16337+
format: int32
16338+
minimum: 1
16339+
type: integer
16340+
numerator:
16341+
format: int32
16342+
minimum: 0
16343+
type: integer
16344+
required:
16345+
- numerator
16346+
type: object
16347+
x-kubernetes-validations:
16348+
- message: numerator must be less than or equal to denominator
16349+
rule: self.numerator <= self.denominator
16350+
clientSamplingRate:
16351+
description: |-
16352+
ClientSamplingRate controls the rate at which traffic will be
16353+
selected for tracing when requested by the client.
16354+
Defaults to 100, valid values [0-100]. 100 indicates 100% sampling.
16355+
16356+
Only one of ClientSamplingRate or ClientSamplingFraction may be specified.
16357+
If neither field is specified, all client requests will be sampled.
16358+
format: int32
16359+
maximum: 100
16360+
minimum: 0
16361+
type: integer
1633016362
customTags:
1633116363
additionalProperties:
1633216364
properties:
@@ -16391,6 +16423,38 @@ spec:
1639116423

1639216424
Deprecated: Use Tags instead.
1639316425
type: object
16426+
overallSamplingFraction:
16427+
description: |-
16428+
OverallSamplingFraction represents the fraction of requests that should be
16429+
selected for tracing after all other sampling checks have been applied.
16430+
properties:
16431+
denominator:
16432+
default: 100
16433+
format: int32
16434+
minimum: 1
16435+
type: integer
16436+
numerator:
16437+
format: int32
16438+
minimum: 0
16439+
type: integer
16440+
required:
16441+
- numerator
16442+
type: object
16443+
x-kubernetes-validations:
16444+
- message: numerator must be less than or equal to denominator
16445+
rule: self.numerator <= self.denominator
16446+
overallSamplingRate:
16447+
description: |-
16448+
OverallSamplingRate controls the rate at which traffic will be
16449+
selected for tracing after all other sampling checks have been applied.
16450+
Defaults to 100, valid values [0-100]. 100 indicates 100% sampling.
16451+
16452+
Only one of OverallSamplingRate or OverallSamplingFraction may be specified.
16453+
If neither field is specified, all requests will be sampled.
16454+
format: int32
16455+
maximum: 100
16456+
minimum: 0
16457+
type: integer
1639416458
provider:
1639516459
description: Provider defines the tracing provider.
1639616460
properties:
@@ -18066,6 +18130,12 @@ spec:
1806618130
- message: only one of SamplingRate or SamplingFraction can be
1806718131
specified
1806818132
rule: '!(has(self.samplingRate) && has(self.samplingFraction))'
18133+
- message: only one of ClientSamplingRate or ClientSamplingFraction
18134+
can be specified
18135+
rule: '!(has(self.clientSamplingRate) && has(self.clientSamplingFraction))'
18136+
- message: only one of OverallSamplingRate or OverallSamplingFraction
18137+
can be specified
18138+
rule: '!(has(self.overallSamplingRate) && has(self.overallSamplingFraction))'
1806918139
type: object
1807018140
type: object
1807118141
status:

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3151,6 +3151,26 @@ spec:
31513151
31523152
This takes precedence over EnvoyProxy tracing when set.
31533153
properties:
3154+
clientSamplingFraction:
3155+
description: |-
3156+
ClientSamplingFraction represents the fraction of requests that should be
3157+
selected for tracing when requested by the client.
3158+
properties:
3159+
denominator:
3160+
default: 100
3161+
format: int32
3162+
minimum: 1
3163+
type: integer
3164+
numerator:
3165+
format: int32
3166+
minimum: 0
3167+
type: integer
3168+
required:
3169+
- numerator
3170+
type: object
3171+
x-kubernetes-validations:
3172+
- message: numerator must be less than or equal to denominator
3173+
rule: self.numerator <= self.denominator
31543174
customTags:
31553175
additionalProperties:
31563176
properties:
@@ -3215,6 +3235,26 @@ spec:
32153235
32163236
Deprecated: Use Tags instead.
32173237
type: object
3238+
overallSamplingFraction:
3239+
description: |-
3240+
OverallSamplingFraction represents the fraction of requests that should be
3241+
selected for tracing after all other sampling checks have been applied.
3242+
properties:
3243+
denominator:
3244+
default: 100
3245+
format: int32
3246+
minimum: 1
3247+
type: integer
3248+
numerator:
3249+
format: int32
3250+
minimum: 0
3251+
type: integer
3252+
required:
3253+
- numerator
3254+
type: object
3255+
x-kubernetes-validations:
3256+
- message: numerator must be less than or equal to denominator
3257+
rule: self.numerator <= self.denominator
32183258
samplingFraction:
32193259
description: |-
32203260
SamplingFraction represents the fraction of requests that should be

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16326,6 +16326,38 @@ spec:
1632616326
Tracing defines tracing configuration for managed proxies.
1632716327
If unspecified, will not send tracing data.
1632816328
properties:
16329+
clientSamplingFraction:
16330+
description: |-
16331+
ClientSamplingFraction represents the fraction of requests that should be
16332+
selected for tracing when requested by the client.
16333+
properties:
16334+
denominator:
16335+
default: 100
16336+
format: int32
16337+
minimum: 1
16338+
type: integer
16339+
numerator:
16340+
format: int32
16341+
minimum: 0
16342+
type: integer
16343+
required:
16344+
- numerator
16345+
type: object
16346+
x-kubernetes-validations:
16347+
- message: numerator must be less than or equal to denominator
16348+
rule: self.numerator <= self.denominator
16349+
clientSamplingRate:
16350+
description: |-
16351+
ClientSamplingRate controls the rate at which traffic will be
16352+
selected for tracing when requested by the client.
16353+
Defaults to 100, valid values [0-100]. 100 indicates 100% sampling.
16354+
16355+
Only one of ClientSamplingRate or ClientSamplingFraction may be specified.
16356+
If neither field is specified, all client requests will be sampled.
16357+
format: int32
16358+
maximum: 100
16359+
minimum: 0
16360+
type: integer
1632916361
customTags:
1633016362
additionalProperties:
1633116363
properties:
@@ -16390,6 +16422,38 @@ spec:
1639016422

1639116423
Deprecated: Use Tags instead.
1639216424
type: object
16425+
overallSamplingFraction:
16426+
description: |-
16427+
OverallSamplingFraction represents the fraction of requests that should be
16428+
selected for tracing after all other sampling checks have been applied.
16429+
properties:
16430+
denominator:
16431+
default: 100
16432+
format: int32
16433+
minimum: 1
16434+
type: integer
16435+
numerator:
16436+
format: int32
16437+
minimum: 0
16438+
type: integer
16439+
required:
16440+
- numerator
16441+
type: object
16442+
x-kubernetes-validations:
16443+
- message: numerator must be less than or equal to denominator
16444+
rule: self.numerator <= self.denominator
16445+
overallSamplingRate:
16446+
description: |-
16447+
OverallSamplingRate controls the rate at which traffic will be
16448+
selected for tracing after all other sampling checks have been applied.
16449+
Defaults to 100, valid values [0-100]. 100 indicates 100% sampling.
16450+
16451+
Only one of OverallSamplingRate or OverallSamplingFraction may be specified.
16452+
If neither field is specified, all requests will be sampled.
16453+
format: int32
16454+
maximum: 100
16455+
minimum: 0
16456+
type: integer
1639316457
provider:
1639416458
description: Provider defines the tracing provider.
1639516459
properties:
@@ -18065,6 +18129,12 @@ spec:
1806518129
- message: only one of SamplingRate or SamplingFraction can be
1806618130
specified
1806718131
rule: '!(has(self.samplingRate) && has(self.samplingFraction))'
18132+
- message: only one of ClientSamplingRate or ClientSamplingFraction
18133+
can be specified
18134+
rule: '!(has(self.clientSamplingRate) && has(self.clientSamplingFraction))'
18135+
- message: only one of OverallSamplingRate or OverallSamplingFraction
18136+
can be specified
18137+
rule: '!(has(self.overallSamplingRate) && has(self.overallSamplingFraction))'
1806818138
type: object
1806918139
type: object
1807018140
status:

internal/gatewayapi/backendtrafficpolicy.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,10 +1193,12 @@ func buildBackendTracing(tracing *egv1a1.Tracing) *ir.BackendTracing {
11931193
return nil
11941194
}
11951195
return &ir.BackendTracing{
1196-
SamplingFraction: tracing.SamplingFraction,
1197-
CustomTags: ir.CustomTagMapToSlice(tracing.CustomTags),
1198-
Tags: ir.MapToSlice(tracing.Tags),
1199-
SpanName: tracing.SpanName,
1196+
SamplingFraction: tracing.SamplingFraction,
1197+
ClientSamplingFraction: tracing.ClientSamplingFraction,
1198+
OverallSamplingFraction: tracing.OverallSamplingFraction,
1199+
CustomTags: ir.CustomTagMapToSlice(tracing.CustomTags),
1200+
Tags: ir.MapToSlice(tracing.Tags),
1201+
SpanName: tracing.SpanName,
12001202
}
12011203
}
12021204

0 commit comments

Comments
 (0)