Skip to content

Commit e0d4e3b

Browse files
authored
feat: Support configuring the scaler reconcile interval (#61)
* feat: Support configuring the scaler reconcile interval * changelog * Remove uneeded braces * Move into let
1 parent ac08608 commit e0d4e3b

File tree

9 files changed

+61
-22
lines changed

9 files changed

+61
-22
lines changed

CHANGELOG.md

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

55
## [Unreleased]
66

7+
### Added
8+
9+
- Support configuring the scaler reconcile interval ([#61]).
10+
711
### Changed
812

913
- Set defaults to oci ([#57]).
@@ -13,6 +17,7 @@ All notable changes to this project will be documented in this file.
1317
- Reduce max poll delay from 10s to 3s to have better client responsiveness
1418

1519
[#57]: https://github.com/stackabletech/trino-lb/pull/57
20+
[#61]: https://github.com/stackabletech/trino-lb/pull/61
1621

1722
## [0.3.2] - 2024-08-20
1823

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ trinoClusterGroups:
5555
- name: trino-m-2
5656
endpoint: https://trino-m-2-coordinator-default.default.svc.cluster.local:8443
5757
credentials: *common-credentials
58-
oidc:
59-
maxRunningQueries: 3
60-
trinoClusters:
61-
- name: trino-oidc-1
62-
endpoint: https://5.250.182.203:8443
63-
credentials: *common-credentials
58+
# oidc:
59+
# maxRunningQueries: 3
60+
# trinoClusters:
61+
# - name: trino-oidc-1
62+
# endpoint: https://5.250.182.203:8443
63+
# credentials: *common-credentials
6464
trinoClusterGroupsIgnoreCert: true
6565

6666
routers:
@@ -100,6 +100,7 @@ routers:
100100
routingFallback: m
101101

102102
clusterAutoscaler:
103+
reconcileInterval: 1s
103104
stackable:
104105
clusters:
105106
trino-s-1:

deploy/helm/trino-lb/templates/trinos.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ metadata:
88
namespace: default
99
spec:
1010
image:
11-
productVersion: "451"
11+
productVersion: "455"
1212
clusterConfig:
1313
catalogLabelSelector:
1414
matchLabels:
@@ -40,7 +40,7 @@ metadata:
4040
namespace: default
4141
spec:
4242
image:
43-
productVersion: "451"
43+
productVersion: "455"
4444
clusterConfig:
4545
catalogLabelSelector:
4646
matchLabels:

trino-lb-core/src/config.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl Default for TrinoLbPortsConfig {
137137
#[derive(Clone, Debug, Deserialize)]
138138
#[serde(deny_unknown_fields, rename_all = "camelCase")]
139139
pub enum PersistenceConfig {
140-
InMemory {},
140+
InMemory,
141141
Redis(RedisConfig),
142142
Postgres(PostgresConfig),
143143
}
@@ -298,7 +298,23 @@ pub enum TagMatchingStrategy {
298298

299299
#[derive(Clone, Debug, Deserialize)]
300300
#[serde(deny_unknown_fields, rename_all = "camelCase")]
301-
pub enum ScalerConfig {
301+
pub struct ScalerConfig {
302+
#[serde(
303+
with = "humantime_serde",
304+
default = "default_scaler_reconcile_interval"
305+
)]
306+
pub reconcile_interval: Duration,
307+
#[serde(flatten)]
308+
pub implementation: ScalerConfigImplementation,
309+
}
310+
311+
fn default_scaler_reconcile_interval() -> Duration {
312+
Duration::from_secs(5)
313+
}
314+
315+
#[derive(Clone, Debug, Deserialize)]
316+
#[serde(deny_unknown_fields, rename_all = "camelCase")]
317+
pub enum ScalerConfigImplementation {
302318
Stackable(StackableScalerConfig),
303319
}
304320

trino-lb/src/http_server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub enum Error {
4343
#[snafu(display(
4444
"In case https is used the `tls.certPemFile` and `tls.keyPemFile` options must be set"
4545
))]
46-
CertsMissing {},
46+
CertsMissing,
4747
}
4848

4949
pub struct AppState {

trino-lb/src/http_server/ui/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::http_server::AppState;
1616
#[derive(Snafu, Debug)]
1717
pub enum Error {
1818
#[snafu(display("Query ID missing. It needs to be specified as query parameter such as https://127.0.0.1:8443/ui/query.html?trino_lb_20231227_122313_2JzDa3bT"))]
19-
QueryIdMissing {},
19+
QueryIdMissing,
2020

2121
#[snafu(display("Query with ID {query_id:?} not found. Maybe the query is not queued any more but was handed over to a Trino cluster."))]
2222
QueryIdNotFound {

trino-lb/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ mod trino_client;
3434
#[derive(Snafu, Debug)]
3535
pub enum Error {
3636
#[snafu(display("Failed to install rustls crypto provider"))]
37-
InstallRustlsCryptoProvider {},
37+
InstallRustlsCryptoProvider,
3838

3939
#[snafu(display("Failed to set up tracing"))]
4040
SetUpTracing { source: tracing::Error },
@@ -62,6 +62,9 @@ pub enum Error {
6262
#[snafu(display("Failed to create scaler"))]
6363
CreateScaler { source: scaling::Error },
6464

65+
#[snafu(display("Failed to start scaler"))]
66+
StartScaler { source: scaling::Error },
67+
6568
#[snafu(display("Failed to start HTTP server"))]
6669
StartHttpServer { source: http_server::Error },
6770
}
@@ -157,7 +160,7 @@ async fn start() -> Result<(), MainError> {
157160
let scaler = Scaler::new(&config, Arc::clone(&persistence))
158161
.await
159162
.context(CreateScalerSnafu)?;
160-
scaler.start_loop();
163+
scaler.start_loop().context(StartScalerSnafu)?;
161164

162165
let query_count_fetcher = QueryCountFetcher::new(
163166
Arc::clone(&persistence),

trino-lb/src/scaling/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub enum Error {
1616
InvalidTimeRange { time_range: String },
1717

1818
#[snafu(display("Any weekdays other tha \"Mon - Son\" are not supported yet"))]
19-
WeekdaysNotSupportedYet {},
19+
WeekdaysNotSupportedYet,
2020

2121
#[snafu(display(
2222
"Please configure a drainIdleDurationBeforeShutdown of at least {min_duration:?}"

trino-lb/src/scaling/mod.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use tokio::{
1616
};
1717
use tracing::{debug, error, info, instrument, Instrument, Span};
1818
use trino_lb_core::{
19-
config::{Config, ScalerConfig},
19+
config::{Config, ScalerConfig, ScalerConfigImplementation},
2020
trino_cluster::ClusterState,
2121
TrinoClusterName,
2222
};
@@ -109,7 +109,10 @@ pub enum Error {
109109
JoinGetCurrentClusterStateTask { source: JoinError },
110110

111111
#[snafu(display("The variable \"scaler\" is None. This should never happen, as we only run the reconciliation when a scaler is configured!"))]
112-
ScalerVariableIsNone {},
112+
ScalerVariableIsNone,
113+
114+
#[snafu(display("The scaler config is missing. This is a bug in trino-lb, as it should exist at this particular code path"))]
115+
ScalerConfigMissing,
113116
}
114117

115118
/// The scaler periodically
@@ -118,6 +121,8 @@ pub enum Error {
118121
/// 2. In case scaling is enabled for a cluster group it supervises the load and scaled the number of clusters
119122
/// accordingly
120123
pub struct Scaler {
124+
/// The original config passed by the user
125+
config: Option<ScalerConfig>,
121126
/// In case this is [`None`], no scaling at all is configured.
122127
scaler: Option<ScalerImplementation>,
123128
persistence: Arc<PersistenceImplementation>,
@@ -153,14 +158,15 @@ impl Scaler {
153158
// Cluster groups that don't need scaling are missing from the `scaling_config`.
154159
}
155160

156-
Some(match scaler {
157-
ScalerConfig::Stackable(scaler_config) => {
161+
let scaler = match &scaler.implementation {
162+
ScalerConfigImplementation::Stackable(scaler_config) => {
158163
StackableScaler::new(scaler_config, &config.trino_cluster_groups)
159164
.await
160165
.context(CreateStackableAutoscalerSnafu)?
161166
.into()
162167
}
163-
})
168+
};
169+
Some(scaler)
164170
}
165171
};
166172

@@ -192,13 +198,19 @@ impl Scaler {
192198
persistence,
193199
groups,
194200
scaling_config,
201+
config: config.cluster_autoscaler.clone(),
195202
})
196203
}
197204

198-
pub fn start_loop(self) {
205+
pub fn start_loop(self) -> Result<(), Error> {
199206
if self.scaler.is_some() {
200207
// As there is a scaler configured, let's start it normally.
201-
let mut interval = time::interval(Duration::from_secs(10));
208+
let interval = self
209+
.config
210+
.as_ref()
211+
.context(ScalerConfigMissingSnafu)?
212+
.reconcile_interval;
213+
let mut interval = time::interval(interval);
202214
interval.set_missed_tick_behavior(time::MissedTickBehavior::Delay);
203215

204216
let me = Arc::new(self);
@@ -230,6 +242,8 @@ impl Scaler {
230242
}
231243
});
232244
}
245+
246+
Ok(())
233247
}
234248

235249
#[instrument(name = "Scaler::reconcile", skip(self))]

0 commit comments

Comments
 (0)