Skip to content

Commit 9949681

Browse files
committed
Add regex validation for the name of the batch of custom queries being added, according to OTel component naming restrictions.
1 parent 8f26e19 commit 9949681

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

config/crd/bases/postgres-operator.crunchydata.com_pgadmins.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2066,7 +2066,11 @@ spec:
20662066
x-kubernetes-validations:
20672067
- rule: duration("0") <= self && self <= duration("60m")
20682068
name:
2069-
description: The name of this batch of queries.
2069+
description: |-
2070+
The name of this batch of queries, which will be used in naming the OTel
2071+
SqlQuery receiver.
2072+
maxLength: 20
2073+
pattern: ^[^\pZ\pC\pS]+$
20702074
type: string
20712075
queries:
20722076
description: A ConfigMap holding the yaml file that

config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11722,7 +11722,11 @@ spec:
1172211722
x-kubernetes-validations:
1172311723
- rule: duration("0") <= self && self <= duration("60m")
1172411724
name:
11725-
description: The name of this batch of queries.
11725+
description: |-
11726+
The name of this batch of queries, which will be used in naming the OTel
11727+
SqlQuery receiver.
11728+
maxLength: 20
11729+
pattern: ^[^\pZ\pC\pS]+$
1172611730
type: string
1172711731
queries:
1172811732
description: A ConfigMap holding the yaml file that

pkg/apis/postgres-operator.crunchydata.com/v1beta1/instrumentation_types.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,27 @@ import corev1 "k8s.io/api/core/v1"
1111
type InstrumentationSpec struct {
1212
// Image name to use for collector containers. When omitted, the value
1313
// comes from an operator environment variable.
14+
// ---
1415
// +optional
1516
Image string `json:"image,omitempty"`
1617

1718
// Resources holds the resource requirements for the collector container.
19+
// ---
1820
// +optional
1921
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
2022

2123
// Config is the place for users to configure exporters and provide files.
24+
// ---
2225
// +optional
2326
Config *InstrumentationConfigSpec `json:"config,omitempty"`
2427

2528
// Logs is the place for users to configure the log collection.
29+
// ---
2630
// +optional
2731
Logs *InstrumentationLogsSpec `json:"logs,omitempty"`
2832

2933
// Metrics is the place for users to configure metrics collection.
34+
// ---
3035
// +optional
3136
Metrics *InstrumentationMetricsSpec `json:"metrics,omitempty"`
3237
}
@@ -46,6 +51,7 @@ type InstrumentationConfigSpec struct {
4651

4752
// Exporters allows users to configure OpenTelemetry exporters that exist
4853
// in the collector image.
54+
// ---
4955
// +kubebuilder:pruning:PreserveUnknownFields
5056
// +kubebuilder:validation:Schemaless
5157
// +kubebuilder:validation:Type=object
@@ -98,30 +104,41 @@ type InstrumentationLogsSpec struct {
98104
type InstrumentationMetricsSpec struct {
99105
// Where users can turn off built-in metrics and also provide their own
100106
// custom queries.
107+
// ---
101108
// +optional
102109
CustomQueries *InstrumentationCustomQueriesSpec `json:"customQueries,omitempty"`
103110
}
104111

105112
type InstrumentationCustomQueriesSpec struct {
106113
// User defined queries and metrics.
114+
// ---
107115
// +optional
108116
Add []InstrumentationCustomQueries `json:"add,omitempty"`
109117

110118
// A list of built-in queries that should be removed. If all queries for a
111119
// given SQL statement are removed, the SQL statement will no longer be run.
112-
//
120+
// ---
113121
// +optional
114122
Remove []string `json:"remove,omitempty"`
115123
}
116124

117125
type InstrumentationCustomQueries struct {
118-
// The name of this batch of queries.
126+
// The name of this batch of queries, which will be used in naming the OTel
127+
// SqlQuery receiver.
128+
// ---
129+
// OTel restricts component names from having whitespace, control characters,
130+
// or symbols.
131+
// https://github.com/open-telemetry/opentelemetry-collector/blob/main/component/identifiable.go#L23-L26
132+
// +kubebuilder:validation:Pattern=`^[^\pZ\pC\pS]+$`
133+
//
134+
// Set a max length to keep rule costs low.
135+
// +kubebuilder:validation:MaxLength=20
119136
//
120137
// +required
121138
Name string `json:"name"`
122139

123140
// A ConfigMap holding the yaml file that contains the queries.
124-
//
141+
// ---
125142
// +required
126143
Queries ConfigMapKeyRef `json:"queries"`
127144

@@ -147,7 +164,7 @@ type InstrumentationCustomQueries struct {
147164
// ---
148165
// Configuration for the OpenTelemetry Batch Processor
149166
// https://pkg.go.dev/go.opentelemetry.io/collector/processor/batchprocessor#section-readme
150-
//
167+
// ---
151168
// The batch processor stops batching when *either* of these is zero, but that is confusing.
152169
// Make the user set both so it is evident there is *no* motivation to create any batch.
153170
// +kubebuilder:validation:XValidation:rule=`(has(self.minRecords) && self.minRecords == 0) == (has(self.maxDelay) && self.maxDelay == duration('0'))`,message=`to disable batching, both minRecords and maxDelay must be zero`

0 commit comments

Comments
 (0)