Skip to content
Merged
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
12 changes: 12 additions & 0 deletions api/v1alpha1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,18 @@ type Tracing struct {
//
// +optional
SamplingFraction *gwapiv1.Fraction `json:"samplingFraction,omitempty"`
// ClientSamplingFraction represents the fraction of requests that should be
// selected for tracing when requested by the client.
// If unspecified, client-forced tracing is disabled by default and users must
// set this field to opt in.
//
// +optional
ClientSamplingFraction *gwapiv1.Fraction `json:"clientSamplingFraction,omitempty"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • can we change the defaults of disabling clientSamplingFraction to 0, so users need to opt in to this feature ? we'll need to note this in the breaking changes section
  • can we avoid overallSamplingFraction ?

wdyt @envoyproxy/gateway-maintainers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asked below about the default value 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// OverallSamplingFraction represents the fraction of requests that should be
// selected for tracing after all other sampling checks have been applied.
//
// +optional
OverallSamplingFraction *gwapiv1.Fraction `json:"overallSamplingFraction,omitempty"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we avoid OverallSamplingFraction since ClientSamplingFraction now defaults to 0 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d keep OverallSamplingFraction. ClientSamplingFraction=0 only disables client-triggered tracing via x-client-trace-id, while OverallSamplingFraction is still useful as the final cap on total trace volume across all sampling paths.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok lets keep it, if we think this is a legit use case,

      samplingRate: 1
      clientSamplingRate: 50
      overallSamplingRate: 10

my preference would be to set explicit individual rates, vs a global cap, wdyt @envoyproxy/gateway-maintainers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// CustomTags defines the custom tags to add to each span.
// If provider is kubernetes, pod name and namespace are added by default.
//
Expand Down
10 changes: 10 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 @@ -3152,6 +3152,28 @@ spec:

This takes precedence over EnvoyProxy tracing when set.
properties:
clientSamplingFraction:
description: |-
ClientSamplingFraction represents the fraction of requests that should be
selected for tracing when requested by the client.
If unspecified, client-forced tracing is disabled by default and users must
set this field to opt in.
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
customTags:
additionalProperties:
properties:
Expand Down Expand Up @@ -3216,6 +3238,26 @@ spec:

Deprecated: Use Tags instead.
type: object
overallSamplingFraction:
description: |-
OverallSamplingFraction represents the fraction of requests that should be
selected for tracing after all other sampling checks have been applied.
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
samplingFraction:
description: |-
SamplingFraction represents the fraction of requests that should be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16329,6 +16329,28 @@ spec:
Tracing defines tracing configuration for managed proxies.
If unspecified, will not send tracing data.
properties:
clientSamplingFraction:
description: |-
ClientSamplingFraction represents the fraction of requests that should be
selected for tracing when requested by the client.
If unspecified, client-forced tracing is disabled by default and users must
set this field to opt in.
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
customTags:
additionalProperties:
properties:
Expand Down Expand Up @@ -16393,6 +16415,26 @@ spec:

Deprecated: Use Tags instead.
type: object
overallSamplingFraction:
description: |-
OverallSamplingFraction represents the fraction of requests that should be
selected for tracing after all other sampling checks have been applied.
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
provider:
description: Provider defines the tracing provider.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3151,6 +3151,28 @@ spec:

This takes precedence over EnvoyProxy tracing when set.
properties:
clientSamplingFraction:
description: |-
ClientSamplingFraction represents the fraction of requests that should be
selected for tracing when requested by the client.
If unspecified, client-forced tracing is disabled by default and users must
set this field to opt in.
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
customTags:
additionalProperties:
properties:
Expand Down Expand Up @@ -3215,6 +3237,26 @@ spec:

Deprecated: Use Tags instead.
type: object
overallSamplingFraction:
description: |-
OverallSamplingFraction represents the fraction of requests that should be
selected for tracing after all other sampling checks have been applied.
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
samplingFraction:
description: |-
SamplingFraction represents the fraction of requests that should be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16328,6 +16328,28 @@ spec:
Tracing defines tracing configuration for managed proxies.
If unspecified, will not send tracing data.
properties:
clientSamplingFraction:
description: |-
ClientSamplingFraction represents the fraction of requests that should be
selected for tracing when requested by the client.
If unspecified, client-forced tracing is disabled by default and users must
set this field to opt in.
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
customTags:
additionalProperties:
properties:
Expand Down Expand Up @@ -16392,6 +16414,26 @@ spec:

Deprecated: Use Tags instead.
type: object
overallSamplingFraction:
description: |-
OverallSamplingFraction represents the fraction of requests that should be
selected for tracing after all other sampling checks have been applied.
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
provider:
description: Provider defines the tracing provider.
properties:
Expand Down
10 changes: 6 additions & 4 deletions internal/gatewayapi/backendtrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1191,10 +1191,12 @@ func buildBackendTracing(tracing *egv1a1.Tracing) *ir.BackendTracing {
return nil
}
return &ir.BackendTracing{
SamplingFraction: tracing.SamplingFraction,
CustomTags: ir.CustomTagMapToSlice(tracing.CustomTags),
Tags: ir.MapToSlice(tracing.Tags),
SpanName: tracing.SpanName,
SamplingFraction: tracing.SamplingFraction,
ClientSamplingFraction: tracing.ClientSamplingFraction,
OverallSamplingFraction: tracing.OverallSamplingFraction,
CustomTags: ir.CustomTagMapToSlice(tracing.CustomTags),
Tags: ir.MapToSlice(tracing.Tags),
SpanName: tracing.SpanName,
}
}

Expand Down
49 changes: 30 additions & 19 deletions internal/gatewayapi/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,12 +1015,14 @@ func (t *Translator) processTracing(gwCtx *GatewayContext, envoyproxy *egv1a1.En
}

return &ir.Tracing{
Authority: authority,
ServiceName: serviceName,
SamplingRate: proxySamplingRate(tracing),
CustomTags: ir.CustomTagMapToSlice(tracing.CustomTags),
Tags: ir.MapToSlice(tracing.Tags),
ResourceAttributes: ir.MapToSlice(getOpenTelemetryTracingResourceAttributes(&tracing.Provider)),
Authority: authority,
ServiceName: serviceName,
SamplingRate: proxySamplingRate(tracing.SamplingRate, tracing.SamplingFraction),
ClientSamplingRate: proxySamplingFractionPtr(tracing.ClientSamplingFraction),
OverallSamplingRate: proxySamplingFractionPtr(tracing.OverallSamplingFraction),
CustomTags: ir.CustomTagMapToSlice(tracing.CustomTags),
Tags: ir.MapToSlice(tracing.Tags),
ResourceAttributes: ir.MapToSlice(getOpenTelemetryTracingResourceAttributes(&tracing.Provider)),
Destination: ir.RouteDestination{
Name: destName,
Settings: ds,
Expand All @@ -1033,20 +1035,29 @@ func (t *Translator) processTracing(gwCtx *GatewayContext, envoyproxy *egv1a1.En
}, nil
}

func proxySamplingRate(tracing *egv1a1.ProxyTracing) float64 {
rate := 100.0
if tracing.SamplingRate != nil {
rate = float64(*tracing.SamplingRate)
} else if tracing.SamplingFraction != nil {
numerator := float64(tracing.SamplingFraction.Numerator)
denominator := ptr.Deref(tracing.SamplingFraction.Denominator, 100)

rate = numerator * 100 / float64(denominator)
// Identifies a percentage, in the range [0.0, 100.0]
rate = math.Max(0, rate)
rate = math.Min(100, rate)
func proxySamplingFractionPtr(fraction *gwapiv1.Fraction) *float64 {
if fraction == nil {
return nil
}
return new(proxySamplingRate(nil, fraction))
}

func proxySamplingRate(rate *uint32, fraction *gwapiv1.Fraction) float64 {
if rate != nil {
return float64(*rate)
}
return rate
if fraction == nil {
return 100.0
}

numerator := float64(fraction.Numerator)
denominator := ptr.Deref(fraction.Denominator, 100)

value := numerator * 100 / float64(denominator)
// Identifies a percentage, in the range [0.0, 100.0]
value = math.Max(0, value)
value = math.Min(100, value)
return value
}

// getAuthorityFromDestination extracts the gRPC authority from a destination setting.
Expand Down
Loading
Loading