Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apis/projectcontour/v1alpha1/contourconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,16 @@ type TracingConfig struct {
// +optional
OverallSampling *string `json:"overallSampling,omitempty"`

// ClientSampling defines the sampling rate when x-client-trace-id header is set.
// contour's default is 100.
// +optional
ClientSampling *string `json:"clientSampling,omitempty"`

// RandomSampling defines the random sampling rate for all requests.
// contour's default is 100.
// +optional
RandomSampling *string `json:"randomSampling,omitempty"`

// MaxPathTagLength defines maximum length of the request path
// to extract and include in the HttpUrl tag.
// contour's default is 256.
Expand Down
14 changes: 14 additions & 0 deletions apis/projectcontour/v1alpha1/contourconfig_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ func (t *TracingConfig) Validate() error {
}
}

if t.ClientSampling != nil {
_, err := strconv.ParseFloat(*t.ClientSampling, 64)
if err != nil {
return fmt.Errorf("invalid tracing client sampling: %v", err)
}
}

if t.RandomSampling != nil {
_, err := strconv.ParseFloat(*t.RandomSampling, 64)
if err != nil {
return fmt.Errorf("invalid tracing random sampling: %v", err)
}
}

var customTagNames []string

for _, customTag := range t.CustomTags {
Expand Down
10 changes: 10 additions & 0 deletions apis/projectcontour/v1alpha1/zz_generated.deepcopy.go

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

12 changes: 12 additions & 0 deletions cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,10 +784,22 @@ func (s *Server) setupTracingService(tracingConfig *contour_v1alpha1.TracingConf
overallSampling = 100.0
}

clientSampling, err := strconv.ParseFloat(ptr.Deref(tracingConfig.ClientSampling, "100"), 64)
if err != nil || clientSampling == 0 {
clientSampling = 100.0
}

randomSampling, err := strconv.ParseFloat(ptr.Deref(tracingConfig.RandomSampling, "100"), 64)
if err != nil || randomSampling == 0 {
randomSampling = 100.0
}

return &xdscache_v3.TracingConfig{
ServiceName: ptr.Deref(tracingConfig.ServiceName, "contour"),
ExtensionServiceConfig: extensionSvcConfig,
OverallSampling: overallSampling,
ClientSampling: clientSampling,
RandomSampling: randomSampling,
MaxPathTagLength: ptr.Deref(tracingConfig.MaxPathTagLength, 256),
CustomTags: customTags,
}, nil
Expand Down
20 changes: 20 additions & 0 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,11 @@ spec:
description: Tracing defines properties for exporting trace data to
OpenTelemetry.
properties:
clientSampling:
description: |-
ClientSampling defines the sampling rate when x-client-trace-id header is set.
contour's default is 100.
type: string
customTags:
description: CustomTags defines a list of custom tags with unique
tag name.
Expand Down Expand Up @@ -1150,6 +1155,11 @@ spec:
OverallSampling defines the sampling rate of trace data.
contour's default is 100.
type: string
randomSampling:
description: |-
RandomSampling defines the random sampling rate for all requests.
contour's default is 100.
type: string
serviceName:
description: |-
ServiceName defines the name for the service.
Expand Down Expand Up @@ -5042,6 +5052,11 @@ spec:
description: Tracing defines properties for exporting trace data
to OpenTelemetry.
properties:
clientSampling:
description: |-
ClientSampling defines the sampling rate when x-client-trace-id header is set.
contour's default is 100.
type: string
customTags:
description: CustomTags defines a list of custom tags with
unique tag name.
Expand Down Expand Up @@ -5100,6 +5115,11 @@ spec:
OverallSampling defines the sampling rate of trace data.
contour's default is 100.
type: string
randomSampling:
description: |-
RandomSampling defines the random sampling rate for all requests.
contour's default is 100.
type: string
serviceName:
description: |-
ServiceName defines the name for the service.
Expand Down
20 changes: 20 additions & 0 deletions examples/render/contour-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,11 @@ spec:
description: Tracing defines properties for exporting trace data to
OpenTelemetry.
properties:
clientSampling:
description: |-
ClientSampling defines the sampling rate when x-client-trace-id header is set.
contour's default is 100.
type: string
customTags:
description: CustomTags defines a list of custom tags with unique
tag name.
Expand Down Expand Up @@ -1369,6 +1374,11 @@ spec:
OverallSampling defines the sampling rate of trace data.
contour's default is 100.
type: string
randomSampling:
description: |-
RandomSampling defines the random sampling rate for all requests.
contour's default is 100.
type: string
serviceName:
description: |-
ServiceName defines the name for the service.
Expand Down Expand Up @@ -5261,6 +5271,11 @@ spec:
description: Tracing defines properties for exporting trace data
to OpenTelemetry.
properties:
clientSampling:
description: |-
ClientSampling defines the sampling rate when x-client-trace-id header is set.
contour's default is 100.
type: string
customTags:
description: CustomTags defines a list of custom tags with
unique tag name.
Expand Down Expand Up @@ -5319,6 +5334,11 @@ spec:
OverallSampling defines the sampling rate of trace data.
contour's default is 100.
type: string
randomSampling:
description: |-
RandomSampling defines the random sampling rate for all requests.
contour's default is 100.
type: string
serviceName:
description: |-
ServiceName defines the name for the service.
Expand Down
20 changes: 20 additions & 0 deletions examples/render/contour-gateway-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,11 @@ spec:
description: Tracing defines properties for exporting trace data to
OpenTelemetry.
properties:
clientSampling:
description: |-
ClientSampling defines the sampling rate when x-client-trace-id header is set.
contour's default is 100.
type: string
customTags:
description: CustomTags defines a list of custom tags with unique
tag name.
Expand Down Expand Up @@ -1161,6 +1166,11 @@ spec:
OverallSampling defines the sampling rate of trace data.
contour's default is 100.
type: string
randomSampling:
description: |-
RandomSampling defines the random sampling rate for all requests.
contour's default is 100.
type: string
serviceName:
description: |-
ServiceName defines the name for the service.
Expand Down Expand Up @@ -5053,6 +5063,11 @@ spec:
description: Tracing defines properties for exporting trace data
to OpenTelemetry.
properties:
clientSampling:
description: |-
ClientSampling defines the sampling rate when x-client-trace-id header is set.
contour's default is 100.
type: string
customTags:
description: CustomTags defines a list of custom tags with
unique tag name.
Expand Down Expand Up @@ -5111,6 +5126,11 @@ spec:
OverallSampling defines the sampling rate of trace data.
contour's default is 100.
type: string
randomSampling:
description: |-
RandomSampling defines the random sampling rate for all requests.
contour's default is 100.
type: string
serviceName:
description: |-
ServiceName defines the name for the service.
Expand Down
20 changes: 20 additions & 0 deletions examples/render/contour-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,11 @@ spec:
description: Tracing defines properties for exporting trace data to
OpenTelemetry.
properties:
clientSampling:
description: |-
ClientSampling defines the sampling rate when x-client-trace-id header is set.
contour's default is 100.
type: string
customTags:
description: CustomTags defines a list of custom tags with unique
tag name.
Expand Down Expand Up @@ -1186,6 +1191,11 @@ spec:
OverallSampling defines the sampling rate of trace data.
contour's default is 100.
type: string
randomSampling:
description: |-
RandomSampling defines the random sampling rate for all requests.
contour's default is 100.
type: string
serviceName:
description: |-
ServiceName defines the name for the service.
Expand Down Expand Up @@ -5078,6 +5088,11 @@ spec:
description: Tracing defines properties for exporting trace data
to OpenTelemetry.
properties:
clientSampling:
description: |-
ClientSampling defines the sampling rate when x-client-trace-id header is set.
contour's default is 100.
type: string
customTags:
description: CustomTags defines a list of custom tags with
unique tag name.
Expand Down Expand Up @@ -5136,6 +5151,11 @@ spec:
OverallSampling defines the sampling rate of trace data.
contour's default is 100.
type: string
randomSampling:
description: |-
RandomSampling defines the random sampling rate for all requests.
contour's default is 100.
type: string
serviceName:
description: |-
ServiceName defines the name for the service.
Expand Down
20 changes: 20 additions & 0 deletions examples/render/contour.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,11 @@ spec:
description: Tracing defines properties for exporting trace data to
OpenTelemetry.
properties:
clientSampling:
description: |-
ClientSampling defines the sampling rate when x-client-trace-id header is set.
contour's default is 100.
type: string
customTags:
description: CustomTags defines a list of custom tags with unique
tag name.
Expand Down Expand Up @@ -1369,6 +1374,11 @@ spec:
OverallSampling defines the sampling rate of trace data.
contour's default is 100.
type: string
randomSampling:
description: |-
RandomSampling defines the random sampling rate for all requests.
contour's default is 100.
type: string
serviceName:
description: |-
ServiceName defines the name for the service.
Expand Down Expand Up @@ -5261,6 +5271,11 @@ spec:
description: Tracing defines properties for exporting trace data
to OpenTelemetry.
properties:
clientSampling:
description: |-
ClientSampling defines the sampling rate when x-client-trace-id header is set.
contour's default is 100.
type: string
customTags:
description: CustomTags defines a list of custom tags with
unique tag name.
Expand Down Expand Up @@ -5319,6 +5334,11 @@ spec:
OverallSampling defines the sampling rate of trace data.
contour's default is 100.
type: string
randomSampling:
description: |-
RandomSampling defines the random sampling rate for all requests.
contour's default is 100.
type: string
serviceName:
description: |-
ServiceName defines the name for the service.
Expand Down
8 changes: 8 additions & 0 deletions internal/envoy/v3/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ func TracingConfig(tracing *EnvoyTracingConfig) *envoy_filter_network_http_conne
OverallSampling: &envoy_type_v3.Percent{
Value: tracing.OverallSampling,
},
ClientSampling: &envoy_type_v3.Percent{
Value: tracing.ClientSampling,
},
RandomSampling: &envoy_type_v3.Percent{
Value: tracing.RandomSampling,
},
MaxPathTagLength: wrapperspb.UInt32(tracing.MaxPathTagLength),
CustomTags: customTags,
Provider: &envoy_config_trace_v3.Tracing_Http{
Expand Down Expand Up @@ -102,6 +108,8 @@ type EnvoyTracingConfig struct {
SNI string
Timeout timeout.Setting
OverallSampling float64
ClientSampling float64
RandomSampling float64
MaxPathTagLength uint32
CustomTags []*CustomTag
}
Expand Down
Loading
Loading