Skip to content

Commit

Permalink
api: allow tracing sampleRate smaller than 1% (envoyproxy#5096)
Browse files Browse the repository at this point in the history
* api: allow tracing sampleRate smaller than 1%

Signed-off-by: zirain <[email protected]>
Signed-off-by: EshaanAgg <[email protected]>
  • Loading branch information
zirain authored and EshaanAgg committed Jan 22, 2025
1 parent 75e0f0d commit 9bda954
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 4 deletions.
17 changes: 17 additions & 0 deletions api/v1alpha1/tracing_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,32 @@

package v1alpha1

import gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

// ProxyTracing defines the tracing configuration for a proxy.
// +kubebuilder:validation:XValidation:message="only one of SamplingRate or SamplingFraction can be specified",rule="!(has(self.samplingRate) && has(self.samplingFraction))"
type ProxyTracing struct {
// SamplingRate controls the rate at which traffic will be
// selected for tracing if no prior sampling decision has been made.
// Defaults to 100, valid values [0-100]. 100 indicates 100% sampling.
//
// Only one of SamplingRate or SamplingFraction may be specified.
// If neither field is specified, 1% of requests will be sampled.
//
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=100
// +kubebuilder:default=100
// +optional
SamplingRate *uint32 `json:"samplingRate,omitempty"`
// SamplingFraction represents the fraction of requests that should be
// selected for tracing if no prior sampling decision has been made.
//
// Only one of SamplingRate or SamplingFraction may be specified.
// If neither field is specified, 1% of requests will be sampled.
//
// +notImplementedHide
// +optional
SamplingFraction *gwapiv1.Fraction `json:"samplingFraction,omitempty"`
// CustomTags defines the custom tags to add to each span.
// If provider is kubernetes, pod name and namespace are added by default.
CustomTags map[string]CustomTag `json:"customTags,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14437,19 +14437,49 @@ spec:
- message: BackendRefs only supports Core group.
rule: 'has(self.backendRefs) ? (self.backendRefs.all(f,
f.group == "")) : true'
samplingFraction:
description: |-
SamplingFraction represents the fraction of requests that should be
selected for tracing if no prior sampling decision has been made.

Only one of SamplingRate or SamplingFraction may be specified.
If neither field is specified, 1% of requests will be sampled.
properties:
denominator:
default: 100
format: int32
minimum: 1
type: integer
numerator:
format: int32
minimum: 0
type: integer
required:
- numerator
type: object
x-kubernetes-validations:
- message: numerator must be less than or equal to denominator
rule: self.numerator <= self.denominator
samplingRate:
default: 100
description: |-
SamplingRate controls the rate at which traffic will be
selected for tracing if no prior sampling decision has been made.
Defaults to 100, valid values [0-100]. 100 indicates 100% sampling.

Only one of SamplingRate or SamplingFraction may be specified.
If neither field is specified, 1% of requests will be sampled.
format: int32
maximum: 100
minimum: 0
type: integer
required:
- provider
type: object
x-kubernetes-validations:
- message: only one of SamplingRate or SamplingFraction can be
specified
rule: '!(has(self.samplingRate) && has(self.samplingFraction))'
type: object
type: object
status:
Expand Down
4 changes: 2 additions & 2 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -3419,14 +3419,14 @@ _Appears in:_




ProxyTracing defines the tracing configuration for a proxy.

_Appears in:_
- [ProxyTelemetry](#proxytelemetry)

| Field | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `samplingRate` | _integer_ | false | 100 | SamplingRate controls the rate at which traffic will be<br />selected for tracing if no prior sampling decision has been made.<br />Defaults to 100, valid values [0-100]. 100 indicates 100% sampling. |
| `samplingRate` | _integer_ | false | 100 | SamplingRate controls the rate at which traffic will be<br />selected for tracing if no prior sampling decision has been made.<br />Defaults to 100, valid values [0-100]. 100 indicates 100% sampling.<br /><br />Only one of SamplingRate or SamplingFraction may be specified.<br />If neither field is specified, 1% of requests will be sampled. |
| `customTags` | _object (keys:string, values:[CustomTag](#customtag))_ | true | | CustomTags defines the custom tags to add to each span.<br />If provider is kubernetes, pod name and namespace are added by default. |
| `provider` | _[TracingProvider](#tracingprovider)_ | true | | Provider defines the tracing provider. |

Expand Down
4 changes: 2 additions & 2 deletions site/content/zh/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -3419,14 +3419,14 @@ _Appears in:_




ProxyTracing defines the tracing configuration for a proxy.

_Appears in:_
- [ProxyTelemetry](#proxytelemetry)

| Field | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `samplingRate` | _integer_ | false | 100 | SamplingRate controls the rate at which traffic will be<br />selected for tracing if no prior sampling decision has been made.<br />Defaults to 100, valid values [0-100]. 100 indicates 100% sampling. |
| `samplingRate` | _integer_ | false | 100 | SamplingRate controls the rate at which traffic will be<br />selected for tracing if no prior sampling decision has been made.<br />Defaults to 100, valid values [0-100]. 100 indicates 100% sampling.<br /><br />Only one of SamplingRate or SamplingFraction may be specified.<br />If neither field is specified, 1% of requests will be sampled. |
| `customTags` | _object (keys:string, values:[CustomTag](#customtag))_ | true | | CustomTags defines the custom tags to add to each span.<br />If provider is kubernetes, pod name and namespace are added by default. |
| `provider` | _[TracingProvider](#tracingprovider)_ | true | | Provider defines the tracing provider. |

Expand Down
33 changes: 33 additions & 0 deletions test/cel-validation/envoyproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/gatewayapi"
)

func TestEnvoyProxyProvider(t *testing.T) {
Expand Down Expand Up @@ -1404,6 +1405,38 @@ func TestEnvoyProxyProvider(t *testing.T) {
"provided bootstrap patch doesn't match the configured patch type",
},
},
{
desc: "cannot set samplingRate and samplingFraction at the same time",
mutate: func(envoy *egv1a1.EnvoyProxy) {
envoy.Spec = egv1a1.EnvoyProxySpec{
Telemetry: &egv1a1.ProxyTelemetry{
Tracing: &egv1a1.ProxyTracing{
SamplingRate: ptr.To[uint32](1),
SamplingFraction: &gwapiv1.Fraction{Numerator: 1, Denominator: ptr.To[int32](1000)},
Provider: egv1a1.TracingProvider{
BackendCluster: egv1a1.BackendCluster{
BackendRefs: []egv1a1.BackendRef{
{
BackendObjectReference: gwapiv1.BackendObjectReference{
Namespace: gatewayapi.NamespacePtr("ns-2"),
Name: "test-backend",
Kind: gatewayapi.KindPtr("Backend"),
Group: gatewayapi.GroupPtr(egv1a1.GroupName),
},
},
},
},
Type: egv1a1.TracingProviderTypeZipkin,
Zipkin: &egv1a1.ZipkinTracingProvider{},
},
},
},
}
},
wantErrors: []string{
"only one of SamplingRate or SamplingFraction can be specified",
},
},
}

for _, tc := range cases {
Expand Down

0 comments on commit 9bda954

Please sign in to comment.