Skip to content

Commit 4c7367c

Browse files
andythsuebyhr
authored andcommitted
Use Airlift Duration in MonitorConfiguration
1 parent d718b3f commit 4c7367c

File tree

9 files changed

+20
-24
lines changed

9 files changed

+20
-24
lines changed

docs/operation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ modules:
4949
```
5050
- The router operates based on the stats it receives from the clusters, such as
5151
the number of queued and running queries. These values are retrieved at regular
52-
intervals. This interval can be configured by setting `taskDelaySeconds` under
53-
`monitor` section in the config file. The default interval is 60
52+
intervals. This interval can be configured by setting `taskDelay` under
53+
`monitor` section in the config file. The default interval is 1 minute
5454
```yaml
5555
monitor:
56-
taskDelaySeconds: 10
56+
taskDelay: 1m
5757
```
5858

5959
## Monitoring <a name="monitoring"></a>

docs/routers.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Use the following steps to create a new router:
5050
- The router listens to the list of `ClusterStats` via the`updateBackEndStats`
5151
method.
5252
- This method is called on regular intervals defined in the config
53-
parameter `monitor=>taskDelaySeconds`.
53+
parameter `monitor=>taskDelay`.
5454
- Each element in the list corresponds to each backend cluster.
5555
- Only the stats from the healthy cluster are reported, unhealthy clusters are
5656
not included in the list. If you have three cluster backends and one is
@@ -71,9 +71,6 @@ backendState:
7171
clusterStatsConfiguration:
7272
monitorType: UI_API
7373

74-
monitor:
75-
taskDelaySeconds: 10
76-
7774
modules:
7875
- io.trino.gateway.ha.module.QueryCountBasedRouterProvider
7976
```

gateway-ha/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ clusterStatsConfiguration:
1818

1919
# This can be adjusted based on the coordinator state
2020
monitor:
21-
taskDelaySeconds: 10
21+
taskDelay: 1m

gateway-ha/src/main/java/io/trino/gateway/ha/clustermonitor/ActiveClusterMonitor.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import com.google.inject.Inject;
1717
import io.airlift.log.Logger;
18+
import io.airlift.units.Duration;
1819
import io.trino.gateway.ha.config.MonitorConfiguration;
1920
import io.trino.gateway.ha.config.ProxyBackendConfiguration;
2021
import io.trino.gateway.ha.router.GatewayBackendManager;
@@ -27,21 +28,19 @@
2728
import java.util.concurrent.Executors;
2829
import java.util.concurrent.Future;
2930
import java.util.concurrent.ScheduledExecutorService;
30-
import java.util.concurrent.TimeUnit;
3131

3232
import static java.util.Objects.requireNonNull;
3333

3434
public class ActiveClusterMonitor
3535
{
36-
public static final int MONITOR_TASK_DELAY_SECONDS = 60;
3736
public static final int DEFAULT_THREAD_POOL_SIZE = 20;
3837
private static final Logger log = Logger.get(ActiveClusterMonitor.class);
3938

4039
private volatile boolean isInitialized;
4140
private final List<TrinoClusterStatsObserver> clusterStatsObservers;
4241
private final GatewayBackendManager gatewayBackendManager;
4342

44-
private final int taskDelaySeconds;
43+
private final Duration taskDelay;
4544
private final ClusterStatsMonitor clusterStatsMonitor;
4645
private final ExecutorService executorService = Executors.newFixedThreadPool(DEFAULT_THREAD_POOL_SIZE);
4746
private final ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
@@ -56,13 +55,13 @@ public ActiveClusterMonitor(
5655
this.clusterStatsMonitor = requireNonNull(clusterStatsMonitor, "clusterStatsMonitor is null");
5756
this.clusterStatsObservers = requireNonNull(clusterStatsObservers, "clusterStatsObservers is null");
5857
this.gatewayBackendManager = requireNonNull(gatewayBackendManager, "gatewayBackendManager is null");
59-
this.taskDelaySeconds = monitorConfiguration.getTaskDelaySeconds();
58+
this.taskDelay = monitorConfiguration.getTaskDelay();
6059
}
6160

6261
@PostConstruct
6362
public void start()
6463
{
65-
log.info("Running cluster monitor with connection task delay of %d seconds", taskDelaySeconds);
64+
log.info("Running cluster monitor with connection task delay of %s", taskDelay);
6665
scheduledExecutor.scheduleAtFixedRate(() -> {
6766
try {
6867
log.info("Getting stats for all active clusters");
@@ -89,7 +88,7 @@ public void start()
8988
catch (Exception e) {
9089
log.error(e, "Error performing backend monitor tasks");
9190
}
92-
}, 0, taskDelaySeconds, TimeUnit.SECONDS);
91+
}, 0, (long) taskDelay.getValue(), taskDelay.getUnit());
9392
}
9493

9594
@PreDestroy

gateway-ha/src/main/java/io/trino/gateway/ha/config/MonitorConfiguration.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
import com.google.common.collect.ImmutableMap;
1717
import io.airlift.units.Duration;
18-
import io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor;
1918

2019
import java.util.Map;
2120

21+
import static java.util.concurrent.TimeUnit.MINUTES;
2222
import static java.util.concurrent.TimeUnit.SECONDS;
2323

2424
public class MonitorConfiguration
2525
{
26-
private int taskDelaySeconds = ActiveClusterMonitor.MONITOR_TASK_DELAY_SECONDS;
26+
private Duration taskDelay = new Duration(1, MINUTES);
2727

2828
private int retries;
2929

@@ -44,14 +44,14 @@ public class MonitorConfiguration
4444

4545
public MonitorConfiguration() {}
4646

47-
public int getTaskDelaySeconds()
47+
public Duration getTaskDelay()
4848
{
49-
return this.taskDelaySeconds;
49+
return this.taskDelay;
5050
}
5151

52-
public void setTaskDelaySeconds(int taskDelaySeconds)
52+
public void setTaskDelay(Duration taskDelay)
5353
{
54-
this.taskDelaySeconds = taskDelaySeconds;
54+
this.taskDelay = taskDelay;
5555
}
5656

5757
public int getRetries()

gateway-ha/src/test/resources/test-config-template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ clusterStatsConfiguration:
1313
monitorType: INFO_API
1414

1515
monitor:
16-
taskDelaySeconds: 1
16+
taskDelay: 1s
1717

1818
extraWhitelistPaths:
1919
- '/v1/custom.*'

gateway-ha/src/test/resources/test-config-with-routing-rules-api.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ clusterStatsConfiguration:
1212
monitorType: INFO_API
1313

1414
monitor:
15-
taskDelaySeconds: 1
15+
taskDelay: 1s
1616

1717
extraWhitelistPaths:
1818
- '/v1/custom.*'

gateway-ha/src/test/resources/test-config-with-routing-template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ clusterStatsConfiguration:
1212
monitorType: INFO_API
1313

1414
monitor:
15-
taskDelaySeconds: 1
15+
taskDelay: 1s
1616

1717
extraWhitelistPaths:
1818
- '/v1/custom.*'

gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ clusterStatsConfiguration:
1212
monitorType: INFO_API
1313

1414
monitor:
15-
taskDelaySeconds: 1
15+
taskDelay: 1s
1616

1717
extraWhitelistPaths:
1818
- '/v1/custom.*'

0 commit comments

Comments
 (0)