Skip to content

Commit 9c2f8d9

Browse files
committed
Update tracing strategy types; fix outdated proposal
1 parent 7a34e49 commit 9c2f8d9

File tree

3 files changed

+48
-60
lines changed

3 files changed

+48
-60
lines changed

apis/v1alpha1/observabilitypolicy_types.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ type ObservabilityPolicySpec struct {
5050
}
5151

5252
// Tracing allows for enabling and configuring OpenTelemetry tracing.
53+
//
54+
// +kubebuilder:validation:XValidation:message="ratio can only be specified if strategy is of type ratio",rule="!(has(self.ratio) && self.strategy != 'ratio')"
55+
//
56+
//nolint:lll
5357
type Tracing struct {
54-
// Enable defines if tracing is enabled, disabled, or parent-based.
55-
Enable TraceType `json:"enable"`
58+
// Strategy defines if tracing is ratio-based or parent-based.
59+
Strategy TraceStrategy `json:"strategy"`
5660

5761
// Ratio is the percentage of traffic that should be sampled. Integer from 0 to 100.
5862
// By default, 100% of http requests are traced. Not applicable for parent-based tracing.
@@ -71,6 +75,7 @@ type Tracing struct {
7175
// SpanName defines the name of the Otel span. By default is the name of the location for a request.
7276
// If specified, applies to all locations that are created for a route.
7377
// Format: must have all '"' escaped and must not contain any '$' or end with an unescaped '\'
78+
// Examples of invalid names: some-$value, quoted-"value"-name, unescaped\
7479
//
7580
// +optional
7681
// +kubebuilder:validation:MinLength=1
@@ -87,20 +92,17 @@ type Tracing struct {
8792
SpanAttributes []SpanAttribute `json:"spanAttributes,omitempty"`
8893
}
8994

90-
// TraceType defines if tracing is enabled.
95+
// TraceStrategy defines the tracing strategy.
9196
//
92-
// +kubebuilder:validation:Enum=on;off;parent
93-
type TraceType string
97+
// +kubebuilder:validation:Enum=ratio;parent
98+
type TraceStrategy string
9499

95100
const (
96-
// TraceTypeOn enables tracing.
97-
TraceTypeOn TraceType = "on"
98-
99-
// TraceTypeOff disables tracing.
100-
TraceTypeOff TraceType = "off"
101+
// TraceStrategyOn enables ratio-based tracing, defaulting to 100% sampling rate.
102+
TraceStrategyRatio TraceStrategy = "ratio"
101103

102-
// TraceTypeParent enables tracing and only records spans if the parent span was sampled.
103-
TraceTypeParent TraceType = "parent"
104+
// TraceStrategyParent enables tracing and only records spans if the parent span was sampled.
105+
TraceStrategyParent TraceStrategy = "parent"
104106
)
105107

106108
// TraceContext specifies how to propagate traceparent/tracestate headers.

config/crd/bases/gateway.nginx.org_observabilitypolicies.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,6 @@ spec:
102102
- propagate
103103
- ignore
104104
type: string
105-
enable:
106-
description: Enable defines if tracing is enabled, disabled, or
107-
parent-based.
108-
enum:
109-
- "on"
110-
- "off"
111-
- parent
112-
type: string
113105
ratio:
114106
description: |-
115107
Ratio is the percentage of traffic that should be sampled. Integer from 0 to 100.
@@ -155,13 +147,23 @@ spec:
155147
SpanName defines the name of the Otel span. By default is the name of the location for a request.
156148
If specified, applies to all locations that are created for a route.
157149
Format: must have all '"' escaped and must not contain any '$' or end with an unescaped '\'
150+
Examples of invalid names: some-$value, quoted-"value"-name, unescaped\
158151
maxLength: 255
159152
minLength: 1
160153
pattern: ^([^"$\\]|\\[^$])*$
161154
type: string
155+
strategy:
156+
description: Strategy defines if tracing is ratio-based or parent-based.
157+
enum:
158+
- ratio
159+
- parent
160+
type: string
162161
required:
163-
- enable
162+
- strategy
164163
type: object
164+
x-kubernetes-validations:
165+
- message: ratio can only be specified if strategy is of type ratio
166+
rule: '!(has(self.ratio) && self.strategy != ''ratio'')'
165167
required:
166168
- targetRef
167169
type: object

docs/proposals/observability.md

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,21 @@ type Tracing struct {
9898
// SpanAttributes are custom key/value attributes that are added to each span.
9999
//
100100
// +optional
101-
SpanAttributes map[string]string `json:"spanAttributes,omitempty"`
101+
SpanAttributes []SpanAttribute `json:"spanAttributes,omitempty"`
102102

103-
// Enable defines if tracing is enabled, disabled, or parent-based.
104-
Enable TraceType `json:"enable"`
103+
// Strategy defines if tracing is ratio-based or parent-based.
104+
Strategy TraceStrategy `json:"strategy"`
105105
}
106106

107-
// TraceType defines if tracing is enabled.
108-
type TraceType string
107+
// TraceStrategy defines the tracing strategy.
108+
type TraceStrategy string
109109

110110
const (
111-
// TraceTypeOn enables tracing.
112-
TraceTypeOn TraceType = "on"
111+
// TraceStrategyOn enables ratio-based tracing, defaulting to 100% sampling rate.
112+
TraceStrategyRatio TraceStrategy = "ratio"
113113

114-
// TraceTypeOff disables tracing.
115-
TraceTypeOff TraceType = "off"
116-
117-
// TraceTypeParent enables tracing and only records spans if the parent span was sampled.
118-
TraceTypeParent TraceType = "parent"
114+
// TraceStrategyParent enables tracing and only records spans if the parent span was sampled.
115+
TraceStrategyParent TraceStrategy = "parent"
119116
)
120117

121118
// TraceContext specifies how to propagate traceparent/tracestate headers.
@@ -135,6 +132,15 @@ const (
135132
// TraceContextIgnore skips context headers processing.
136133
TraceContextIgnore TraceContext = "ignore"
137134
)
135+
136+
// SpanAttribute is a key value pair to be added to a tracing span.
137+
type SpanAttribute struct {
138+
// Key is the key for a span attribute.
139+
Key string `json:"key"`
140+
141+
// Value is the value for a span attribute.
142+
Value string `json:"value"`
143+
}
138144
```
139145

140146
### YAML
@@ -152,15 +158,16 @@ spec:
152158
group: gateway.networking.k8s.io
153159
kind: HTTPRoute
154160
name: example-route
155-
sectionName: example-section
156161
tracing:
162+
strategy: ratio
157163
ratio: 10
158164
context: inject
159165
spanName: example-span
160166
spanAttributes:
161-
attribute1: value1
162-
attribute2: value2
163-
enable: "on"
167+
- key: attribute1
168+
value: value1
169+
- key: attribute2
170+
value: value2
164171
status:
165172
ancestors:
166173
ancestorRef:
@@ -175,29 +182,6 @@ status:
175182
message: Policy is accepted
176183
```
177184
178-
and the HTTPRoute it is attached to:
179-
180-
```yaml
181-
apiVersion: gateway.networking.k8s.io/v1
182-
kind: HTTPRoute
183-
metadata:
184-
name: example-route
185-
spec:
186-
gatewayClassName: nginx
187-
listeners:
188-
- name: example-section
189-
port: 80
190-
protocol: HTTP
191-
hostname: "*.example.com"
192-
status:
193-
conditions:
194-
...
195-
- type: gateway.nginx.org/ObservabilityPolicyAffected # new condition
196-
status: "True"
197-
reason: PolicyAffected
198-
message: Object affected by an ObservabilityPolicy.
199-
```
200-
201185
### Status
202186
203187
#### CRD Label

0 commit comments

Comments
 (0)