Skip to content

Commit 0639c1c

Browse files
authored
feat!: Allow configuring port numbers and validate config properties (#43)
* feat!: Allow configuring port numbers and validate config properties * ix tests * changelog * typo * finally...
1 parent eab2d82 commit 0639c1c

7 files changed

Lines changed: 101 additions & 42 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- Added a configuration to specify the port numbers for `http`, `https` and `metrics` ([#43]).
10+
711
### Changed
812

13+
- BREAKING: Ensure no unknown config properties have been set. This is to make the user aware that what he tried to configure is not a valid configuration. You may need to adapt your configuration and remove any unknown properties ([#43]).
914
- Bump dependencies, such as `opentelemetry` 0.23 -> 0.24, `kube` 0.92 -> 0.93 and `redis` 0.25 -> 0.26 ([#41]).
1015

1116
[#41]: https://github.com/stackabletech/trino-lb/pull/41
17+
[#43]: https://github.com/stackabletech/trino-lb/pull/43
1218

1319
## [0.2.3] - 2024-07-01
1420

deploy/helm/trino-lb/configs/trino-lb-config.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
_: &common-credentials
2-
username: admin
3-
password: adminadmin
4-
51
trinoLb:
62
externalAddress: https://5.250.179.64:8443
73
tls:
@@ -39,7 +35,9 @@ trinoClusterGroups:
3935
trinoClusters:
4036
- name: trino-s-1
4137
endpoint: https://trino-s-1-coordinator-default.default.svc.cluster.local:8443
42-
credentials: *common-credentials
38+
credentials: &common-credentials
39+
username: admin
40+
password: adminadmin
4341
m:
4442
maxRunningQueries: 2
4543
autoscaling:
@@ -69,7 +67,7 @@ routers:
6967
# This list will be walked top to bottom and the first router making a decision will choose the target trinoClusterGroup.
7068
# If no router makes a decision the query will fall through to the "routingFallback".
7169
- trinoRoutingGroupHeader:
72-
header: X-Trino-Routing-Group
70+
headerName: X-Trino-Routing-Group
7371
- pythonScript:
7472
script: |
7573
# Tested using Python 3.11

docs/routing/TrinoRoutingGroupHeaderRouter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ Additionally you can configure the name of the HTTP header in case it differs fr
1717
```yaml
1818
routers:
1919
- trinoRoutingGroupHeader:
20-
header: X-My-Custom-Routing-Header # optional, defaults to X-Trino-Routing-Group
20+
headerName: X-My-Custom-Routing-Header # optional, defaults to X-Trino-Routing-Group
2121
```

example-configs/dev-local-with-tracing.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
_: &common-credentials
2-
username: admin
3-
password: adminadmin
4-
51
trinoLb:
62
externalAddress: https://127.0.0.1:8443
73
tls:
@@ -23,14 +19,21 @@ trinoLb:
2319
OTEL_EXPORTER_OTLP_PROTOCOL: Grpc
2420
# In case endpoint and protocol are not set here, they will still be read from the env vars
2521
# OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OTLP_PROTOCOL
22+
ports:
23+
# Default values
24+
http: 8080
25+
https: 8443
26+
metrics: 9090
2627

2728
trinoClusterGroups:
2829
s:
2930
maxRunningQueries: 1
3031
trinoClusters:
3132
- name: trino-s-1
3233
endpoint: https://5.250.181.98:8443
33-
credentials: *common-credentials
34+
credentials: &common-credentials
35+
username: admin
36+
password: adminadmin
3437
m:
3538
maxRunningQueries: 1
3639
trinoClusters:
@@ -43,7 +46,7 @@ routers:
4346
# This list will be walked top to bottom and the first router making a decision will choose the target trinoClusterGroup.
4447
# If no router makes a decision the query will fall through to the "routingFallback".
4548
- trinoRoutingGroupHeader:
46-
header: X-Trino-Routing-Group
49+
headerName: X-Trino-Routing-Group
4750
- pythonScript:
4851
script: |
4952
# Tested using Python 3.11

example-configs/ha-redis-autoscaling-stackable.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
_: &common-credentials
2-
username: admin
3-
password: adminadmin
4-
51
trinoLb:
62
externalAddress: https://5.250.179.64:8443
73
tls:
@@ -39,7 +35,9 @@ trinoClusterGroups:
3935
trinoClusters:
4036
- name: trino-s-1
4137
endpoint: https://trino-s-1-coordinator-default.default.svc.cluster.local:8443
42-
credentials: *common-credentials
38+
credentials: &common-credentials
39+
username: admin
40+
password: adminadmin
4341
m:
4442
maxRunningQueries: 2
4543
autoscaling:
@@ -69,7 +67,7 @@ routers:
6967
# This list will be walked top to bottom and the first router making a decision will choose the target trinoClusterGroup.
7068
# If no router makes a decision the query will fall through to the "routingFallback".
7169
- trinoRoutingGroupHeader:
72-
header: X-Trino-Routing-Group
70+
headerName: X-Trino-Routing-Group
7371
- pythonScript:
7472
script: |
7573
# Tested using Python 3.11

trino-lb-core/src/config.rs

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,26 @@ pub enum Error {
2828
}
2929

3030
#[derive(Clone, Debug, Deserialize)]
31-
#[serde(rename_all = "camelCase")]
31+
// We want to fail on unknown config properties (as Trino is doing as well) to make the user aware that what he tried to
32+
// configure is not a valid configuration.
33+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
3234
pub struct Config {
3335
pub trino_lb: TrinoLbConfig,
36+
3437
pub trino_cluster_groups: HashMap<String, TrinoClusterGroupConfig>,
38+
3539
#[serde(default)]
3640
pub trino_cluster_groups_ignore_cert: bool,
41+
3742
pub routers: Vec<RoutingConfig>,
43+
3844
pub routing_fallback: String,
45+
3946
pub cluster_autoscaler: Option<ScalerConfig>,
4047
}
4148

4249
#[derive(Clone, Debug, Deserialize)]
43-
#[serde(rename_all = "camelCase")]
50+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
4451
pub struct TrinoLbConfig {
4552
pub external_address: Url,
4653

@@ -56,14 +63,17 @@ pub struct TrinoLbConfig {
5663
pub refresh_query_counter_interval: Duration,
5764

5865
pub tracing: Option<TrinoLbTracingConfig>,
66+
67+
#[serde(default)]
68+
pub ports: TrinoLbPortsConfig,
5969
}
6070

6171
fn default_refresh_query_counter_interval() -> Duration {
6272
Duration::from_secs(60)
6373
}
6474

6575
#[derive(Clone, Debug, Default, Deserialize)]
66-
#[serde(rename_all = "camelCase")]
76+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
6777
pub struct TrinoLbTlsConfig {
6878
#[serde(default)]
6979
pub enabled: bool,
@@ -73,7 +83,7 @@ pub struct TrinoLbTlsConfig {
7383
}
7484

7585
#[derive(Clone, Debug, Deserialize)]
76-
#[serde(rename_all = "camelCase")]
86+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
7787
pub struct TrinoLbTracingConfig {
7888
#[serde(default)]
7989
pub enabled: bool,
@@ -86,15 +96,54 @@ pub struct TrinoLbTracingConfig {
8696
}
8797

8898
#[derive(Clone, Debug, Deserialize)]
89-
#[serde(rename_all = "camelCase")]
99+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
100+
pub struct TrinoLbPortsConfig {
101+
#[serde(default = "TrinoLbPortsConfig::default_http_port")]
102+
pub http: u16,
103+
104+
#[serde(default = "TrinoLbPortsConfig::default_https_port")]
105+
pub https: u16,
106+
107+
#[serde(default = "TrinoLbPortsConfig::default_metrics_port")]
108+
pub metrics: u16,
109+
}
110+
111+
impl TrinoLbPortsConfig {
112+
/// Same port Trino is using by default
113+
fn default_http_port() -> u16 {
114+
8080
115+
}
116+
117+
/// Same port Trino is using by default
118+
fn default_https_port() -> u16 {
119+
8443
120+
}
121+
122+
fn default_metrics_port() -> u16 {
123+
9090
124+
}
125+
}
126+
127+
impl Default for TrinoLbPortsConfig {
128+
fn default() -> Self {
129+
Self {
130+
http: Self::default_http_port(),
131+
https: Self::default_https_port(),
132+
metrics: Self::default_metrics_port(),
133+
}
134+
}
135+
}
136+
137+
#[derive(Clone, Debug, Deserialize)]
138+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
90139
pub enum PersistenceConfig {
91140
InMemory {},
92141
Redis(RedisConfig),
93142
Postgres(PostgresConfig),
94143
}
95144

96145
#[derive(Clone, Debug, Deserialize)]
97-
#[serde(rename_all = "camelCase")]
146+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
98147
pub struct RedisConfig {
99148
pub endpoint: Url,
100149

@@ -103,7 +152,7 @@ pub struct RedisConfig {
103152
}
104153

105154
#[derive(Clone, Debug, Deserialize)]
106-
#[serde(rename_all = "camelCase")]
155+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
107156
pub struct PostgresConfig {
108157
pub url: Url,
109158

@@ -116,30 +165,30 @@ fn default_max_connections() -> u32 {
116165
}
117166

118167
#[derive(Clone, Debug, Deserialize)]
119-
#[serde(rename_all = "camelCase")]
168+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
120169
pub struct TrinoClusterGroupConfig {
121170
pub max_running_queries: u64,
122171
pub autoscaling: Option<TrinoClusterGroupAutoscalingConfig>,
123172
pub trino_clusters: Vec<TrinoClusterConfig>,
124173
}
125174

126175
#[derive(Clone, Debug, Deserialize)]
127-
#[serde(rename_all = "camelCase")]
176+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
128177
pub struct TrinoClusterConfig {
129178
pub name: String,
130179
pub endpoint: Url,
131180
pub credentials: TrinoClusterCredentialsConfig,
132181
}
133182

134183
#[derive(Clone, Deserialize)]
135-
#[serde(rename_all = "camelCase")]
184+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
136185
pub struct TrinoClusterCredentialsConfig {
137186
pub username: String,
138187
pub password: String,
139188
}
140189

141190
#[derive(Clone, Debug, Deserialize)]
142-
#[serde(rename_all = "camelCase")]
191+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
143192
pub struct TrinoClusterGroupAutoscalingConfig {
144193
pub upscale_queued_queries_threshold: u64,
145194
pub downscale_running_queries_percentage_threshold: u64,
@@ -149,7 +198,7 @@ pub struct TrinoClusterGroupAutoscalingConfig {
149198
}
150199

151200
#[derive(Clone, Debug, Deserialize)]
152-
#[serde(rename_all = "camelCase")]
201+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
153202
pub struct MinClustersConfig {
154203
pub time_utc: String,
155204
pub weekdays: String,
@@ -166,7 +215,7 @@ impl Debug for TrinoClusterCredentialsConfig {
166215
}
167216

168217
#[derive(Clone, Debug, Deserialize)]
169-
#[serde(rename_all = "camelCase")]
218+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
170219
pub enum RoutingConfig {
171220
ExplainCosts(ExplainCostsRouterConfig),
172221
TrinoRoutingGroupHeader(TrinoRoutingGroupHeaderRouterConfig),
@@ -175,15 +224,15 @@ pub enum RoutingConfig {
175224
}
176225

177226
#[derive(Clone, Debug, Deserialize)]
178-
#[serde(rename_all = "camelCase")]
227+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
179228
pub struct ExplainCostsRouterConfig {
180229
pub trino_cluster_to_run_explain_query: TrinoClientConfig,
181230

182231
pub targets: Vec<ExplainCostTargetConfig>,
183232
}
184233

185234
#[derive(Clone, Deserialize)]
186-
#[serde(rename_all = "camelCase")]
235+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
187236
pub struct TrinoClientConfig {
188237
pub endpoint: Url,
189238
#[serde(default)]
@@ -204,6 +253,8 @@ impl Debug for TrinoClientConfig {
204253
}
205254

206255
#[derive(Clone, Debug, Deserialize)]
256+
// #[serde(flatten)] is not supported in combination with structs that use deny_unknown_fields. Neither the outer nor
257+
// inner flattened struct should use that attribute.
207258
#[serde(rename_all = "camelCase")]
208259
pub struct ExplainCostTargetConfig {
209260
#[serde(flatten)]
@@ -212,7 +263,7 @@ pub struct ExplainCostTargetConfig {
212263
}
213264

214265
#[derive(Clone, Debug, Deserialize)]
215-
#[serde(rename_all = "camelCase")]
266+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
216267
pub struct TrinoRoutingGroupHeaderRouterConfig {
217268
#[serde(default = "default_trino_routing_group_header")]
218269
pub header_name: String,
@@ -223,12 +274,14 @@ fn default_trino_routing_group_header() -> String {
223274
}
224275

225276
#[derive(Clone, Debug, Deserialize)]
226-
#[serde(rename_all = "camelCase")]
277+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
227278
pub struct PythonScriptRouterConfig {
228279
pub script: String,
229280
}
230281

231282
#[derive(Clone, Debug, Deserialize)]
283+
// #[serde(flatten)] is not supported in combination with structs that use deny_unknown_fields. Neither the outer nor
284+
// inner flattened struct should use that attribute.
232285
#[serde(rename_all = "camelCase")]
233286
pub struct ClientTagsRouterConfig {
234287
#[serde(flatten)]
@@ -244,19 +297,19 @@ pub enum TagMatchingStrategy {
244297
}
245298

246299
#[derive(Clone, Debug, Deserialize)]
247-
#[serde(rename_all = "camelCase")]
300+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
248301
pub enum ScalerConfig {
249302
Stackable(StackableScalerConfig),
250303
}
251304

252305
#[derive(Clone, Debug, Deserialize)]
253-
#[serde(rename_all = "camelCase")]
306+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
254307
pub struct StackableScalerConfig {
255308
pub clusters: HashMap<TrinoClusterName, StackableCluster>,
256309
}
257310

258311
#[derive(Clone, Debug, Deserialize)]
259-
#[serde(rename_all = "camelCase")]
312+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
260313
pub struct StackableCluster {
261314
pub name: String,
262315
pub namespace: String,

0 commit comments

Comments
 (0)