From ed94dbf3e0ca93590ac13c1dceb10786de542f35 Mon Sep 17 00:00:00 2001 From: Star Poon Date: Tue, 21 Jan 2025 17:03:51 +0900 Subject: [PATCH 1/5] Load ClusterStatsMonitorModule by default --- docs/operation.md | 1 - docs/quickstart-config.yaml | 1 - gateway-ha/gateway-ha-config-docker.yml | 1 - gateway-ha/gateway-ha-config.yml | 1 - .../ha/module/ClusterStatsMonitorModule.java | 56 ------------------- .../ha/module/HaGatewayProviderModule.java | 25 +++++++++ .../test/resources/test-config-template.yml | 1 - .../test-config-with-routing-template.yml | 1 - ...st-config-without-x-forwarded-template.yml | 1 - 9 files changed, 25 insertions(+), 63 deletions(-) delete mode 100644 gateway-ha/src/main/java/io/trino/gateway/ha/module/ClusterStatsMonitorModule.java diff --git a/docs/operation.md b/docs/operation.md index acaba66ea..4581f0565 100644 --- a/docs/operation.md +++ b/docs/operation.md @@ -46,7 +46,6 @@ to config file's modules section like below modules: - io.trino.gateway.ha.module.HaGatewayProviderModule - io.trino.gateway.ha.module.ClusterStateListenerModule - - io.trino.gateway.ha.module.ClusterStatsMonitorModule - io.trino.gateway.ha.module.QueryCountBasedRouterProvider ``` - The router works on the stats it receives from the clusters about the load i.e number queries queued and running on a cluster at regular intervals which can be configured like below. The default interval is 1 min diff --git a/docs/quickstart-config.yaml b/docs/quickstart-config.yaml index 7654bfad1..349b6d07c 100644 --- a/docs/quickstart-config.yaml +++ b/docs/quickstart-config.yaml @@ -16,7 +16,6 @@ clusterStatsConfiguration: modules: - io.trino.gateway.ha.module.HaGatewayProviderModule - io.trino.gateway.ha.module.ClusterStateListenerModule - - io.trino.gateway.ha.module.ClusterStatsMonitorModule managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/gateway-ha-config-docker.yml b/gateway-ha/gateway-ha-config-docker.yml index a57f7d328..2bced1b9d 100644 --- a/gateway-ha/gateway-ha-config-docker.yml +++ b/gateway-ha/gateway-ha-config-docker.yml @@ -19,7 +19,6 @@ clusterStatsConfiguration: modules: - io.trino.gateway.ha.module.HaGatewayProviderModule - io.trino.gateway.ha.module.ClusterStateListenerModule - - io.trino.gateway.ha.module.ClusterStatsMonitorModule managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/gateway-ha-config.yml b/gateway-ha/gateway-ha-config.yml index d9d8c0f78..a085270ce 100644 --- a/gateway-ha/gateway-ha-config.yml +++ b/gateway-ha/gateway-ha-config.yml @@ -23,7 +23,6 @@ monitor: modules: - io.trino.gateway.ha.module.HaGatewayProviderModule - io.trino.gateway.ha.module.ClusterStateListenerModule - - io.trino.gateway.ha.module.ClusterStatsMonitorModule managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/src/main/java/io/trino/gateway/ha/module/ClusterStatsMonitorModule.java b/gateway-ha/src/main/java/io/trino/gateway/ha/module/ClusterStatsMonitorModule.java deleted file mode 100644 index b92ce01e9..000000000 --- a/gateway-ha/src/main/java/io/trino/gateway/ha/module/ClusterStatsMonitorModule.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.trino.gateway.ha.module; - -import com.google.inject.AbstractModule; -import com.google.inject.Provides; -import com.google.inject.Singleton; -import io.airlift.http.client.HttpClient; -import io.trino.gateway.ha.clustermonitor.ClusterStatsHttpMonitor; -import io.trino.gateway.ha.clustermonitor.ClusterStatsInfoApiMonitor; -import io.trino.gateway.ha.clustermonitor.ClusterStatsJdbcMonitor; -import io.trino.gateway.ha.clustermonitor.ClusterStatsMonitor; -import io.trino.gateway.ha.clustermonitor.ForMonitor; -import io.trino.gateway.ha.clustermonitor.NoopClusterStatsMonitor; -import io.trino.gateway.ha.config.ClusterStatsConfiguration; -import io.trino.gateway.ha.config.HaGatewayConfiguration; - -import static java.util.Objects.requireNonNull; - -public class ClusterStatsMonitorModule - extends AbstractModule -{ - private final HaGatewayConfiguration config; - - public ClusterStatsMonitorModule(HaGatewayConfiguration config) - { - this.config = requireNonNull(config, "config is null"); - } - - @Provides - @Singleton - public ClusterStatsMonitor getClusterStatsMonitor(@ForMonitor HttpClient httpClient) - { - ClusterStatsConfiguration clusterStatsConfig = config.getClusterStatsConfiguration(); - if (config.getBackendState() == null) { - return new ClusterStatsInfoApiMonitor(httpClient, config.getMonitor()); - } - return switch (clusterStatsConfig.getMonitorType()) { - case INFO_API -> new ClusterStatsInfoApiMonitor(httpClient, config.getMonitor()); - case UI_API -> new ClusterStatsHttpMonitor(config.getBackendState()); - case JDBC -> new ClusterStatsJdbcMonitor(config.getBackendState(), config.getMonitor()); - case NOOP -> new NoopClusterStatsMonitor(); - }; - } -} diff --git a/gateway-ha/src/main/java/io/trino/gateway/ha/module/HaGatewayProviderModule.java b/gateway-ha/src/main/java/io/trino/gateway/ha/module/HaGatewayProviderModule.java index 78d09ca80..0b1e383ab 100644 --- a/gateway-ha/src/main/java/io/trino/gateway/ha/module/HaGatewayProviderModule.java +++ b/gateway-ha/src/main/java/io/trino/gateway/ha/module/HaGatewayProviderModule.java @@ -15,11 +15,19 @@ import com.google.common.collect.ImmutableList; import com.google.inject.AbstractModule; +import com.google.inject.Inject; import com.google.inject.Provides; import com.google.inject.Singleton; import io.airlift.http.client.HttpClient; +import io.trino.gateway.ha.clustermonitor.ClusterStatsHttpMonitor; +import io.trino.gateway.ha.clustermonitor.ClusterStatsInfoApiMonitor; +import io.trino.gateway.ha.clustermonitor.ClusterStatsJdbcMonitor; +import io.trino.gateway.ha.clustermonitor.ClusterStatsMonitor; +import io.trino.gateway.ha.clustermonitor.ForMonitor; +import io.trino.gateway.ha.clustermonitor.NoopClusterStatsMonitor; import io.trino.gateway.ha.config.AuthenticationConfiguration; import io.trino.gateway.ha.config.AuthorizationConfiguration; +import io.trino.gateway.ha.config.ClusterStatsConfiguration; import io.trino.gateway.ha.config.GatewayCookieConfigurationPropertiesProvider; import io.trino.gateway.ha.config.HaGatewayConfiguration; import io.trino.gateway.ha.config.OAuth2GatewayCookieConfigurationPropertiesProvider; @@ -67,6 +75,7 @@ protected void configure() jaxrsBinder(binder()).bindInstance(resourceSecurityDynamicFeature); } + @Inject public HaGatewayProviderModule(HaGatewayConfiguration configuration) { this.configuration = requireNonNull(configuration, "configuration is null"); @@ -200,4 +209,20 @@ public RoutingGroupSelector getRoutingGroupSelector(@ForRouter HttpClient httpCl } return RoutingGroupSelector.byRoutingGroupHeader(); } + + @Provides + @Singleton + public ClusterStatsMonitor getClusterStatsMonitor(@ForMonitor HttpClient httpClient) + { + ClusterStatsConfiguration clusterStatsConfig = configuration.getClusterStatsConfiguration(); + if (configuration.getBackendState() == null) { + return new ClusterStatsInfoApiMonitor(httpClient, configuration.getMonitor()); + } + return switch (clusterStatsConfig.getMonitorType()) { + case INFO_API -> new ClusterStatsInfoApiMonitor(httpClient, configuration.getMonitor()); + case UI_API -> new ClusterStatsHttpMonitor(configuration.getBackendState()); + case JDBC -> new ClusterStatsJdbcMonitor(configuration.getBackendState(), configuration.getMonitor()); + case NOOP -> new NoopClusterStatsMonitor(); + }; + } } diff --git a/gateway-ha/src/test/resources/test-config-template.yml b/gateway-ha/src/test/resources/test-config-template.yml index cd842b3a8..eb5e893d7 100644 --- a/gateway-ha/src/test/resources/test-config-template.yml +++ b/gateway-ha/src/test/resources/test-config-template.yml @@ -13,7 +13,6 @@ dataStore: modules: - io.trino.gateway.ha.module.HaGatewayProviderModule - io.trino.gateway.ha.module.ClusterStateListenerModule - - io.trino.gateway.ha.module.ClusterStatsMonitorModule managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/src/test/resources/test-config-with-routing-template.yml b/gateway-ha/src/test/resources/test-config-with-routing-template.yml index bcd999038..44581eed2 100644 --- a/gateway-ha/src/test/resources/test-config-with-routing-template.yml +++ b/gateway-ha/src/test/resources/test-config-with-routing-template.yml @@ -12,7 +12,6 @@ dataStore: modules: - io.trino.gateway.ha.module.HaGatewayProviderModule - io.trino.gateway.ha.module.ClusterStateListenerModule - - io.trino.gateway.ha.module.ClusterStatsMonitorModule managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml b/gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml index a44f8e64d..ccbe8402a 100644 --- a/gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml +++ b/gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml @@ -12,7 +12,6 @@ dataStore: modules: - io.trino.gateway.ha.module.HaGatewayProviderModule - io.trino.gateway.ha.module.ClusterStateListenerModule - - io.trino.gateway.ha.module.ClusterStatsMonitorModule managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor From 6623c034ef8bf76e4b7e063ab20dc3dca35f2441 Mon Sep 17 00:00:00 2001 From: Star Poon Date: Tue, 21 Jan 2025 17:20:41 +0900 Subject: [PATCH 2/5] Load ClusterStateListenerModule by default --- docs/operation.md | 1 - docs/quickstart-config.yaml | 1 - gateway-ha/gateway-ha-config-docker.yml | 1 - gateway-ha/gateway-ha-config.yml | 1 - .../ha/module/ClusterStateListenerModule.java | 62 ------------------- .../ha/module/HaGatewayProviderModule.java | 24 +++++++ .../test/resources/test-config-template.yml | 1 - .../test-config-with-routing-template.yml | 1 - ...st-config-without-x-forwarded-template.yml | 1 - 9 files changed, 24 insertions(+), 69 deletions(-) delete mode 100644 gateway-ha/src/main/java/io/trino/gateway/ha/module/ClusterStateListenerModule.java diff --git a/docs/operation.md b/docs/operation.md index 4581f0565..570168772 100644 --- a/docs/operation.md +++ b/docs/operation.md @@ -45,7 +45,6 @@ to config file's modules section like below ```yaml modules: - io.trino.gateway.ha.module.HaGatewayProviderModule - - io.trino.gateway.ha.module.ClusterStateListenerModule - io.trino.gateway.ha.module.QueryCountBasedRouterProvider ``` - The router works on the stats it receives from the clusters about the load i.e number queries queued and running on a cluster at regular intervals which can be configured like below. The default interval is 1 min diff --git a/docs/quickstart-config.yaml b/docs/quickstart-config.yaml index 349b6d07c..dac2f4a6f 100644 --- a/docs/quickstart-config.yaml +++ b/docs/quickstart-config.yaml @@ -15,7 +15,6 @@ clusterStatsConfiguration: modules: - io.trino.gateway.ha.module.HaGatewayProviderModule - - io.trino.gateway.ha.module.ClusterStateListenerModule managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/gateway-ha-config-docker.yml b/gateway-ha/gateway-ha-config-docker.yml index 2bced1b9d..f632522ad 100644 --- a/gateway-ha/gateway-ha-config-docker.yml +++ b/gateway-ha/gateway-ha-config-docker.yml @@ -18,7 +18,6 @@ clusterStatsConfiguration: modules: - io.trino.gateway.ha.module.HaGatewayProviderModule - - io.trino.gateway.ha.module.ClusterStateListenerModule managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/gateway-ha-config.yml b/gateway-ha/gateway-ha-config.yml index a085270ce..3dcfd2ad4 100644 --- a/gateway-ha/gateway-ha-config.yml +++ b/gateway-ha/gateway-ha-config.yml @@ -22,7 +22,6 @@ monitor: modules: - io.trino.gateway.ha.module.HaGatewayProviderModule - - io.trino.gateway.ha.module.ClusterStateListenerModule managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/src/main/java/io/trino/gateway/ha/module/ClusterStateListenerModule.java b/gateway-ha/src/main/java/io/trino/gateway/ha/module/ClusterStateListenerModule.java deleted file mode 100644 index 7ddf9c7fb..000000000 --- a/gateway-ha/src/main/java/io/trino/gateway/ha/module/ClusterStateListenerModule.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.trino.gateway.ha.module; - -import com.google.common.collect.ImmutableList; -import com.google.inject.AbstractModule; -import com.google.inject.Provides; -import com.google.inject.Singleton; -import io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor; -import io.trino.gateway.ha.clustermonitor.ClusterStatsObserver; -import io.trino.gateway.ha.clustermonitor.HealthCheckObserver; -import io.trino.gateway.ha.clustermonitor.TrinoClusterStatsObserver; -import io.trino.gateway.ha.config.HaGatewayConfiguration; -import io.trino.gateway.ha.config.MonitorConfiguration; -import io.trino.gateway.ha.router.BackendStateManager; -import io.trino.gateway.ha.router.RoutingManager; - -import java.util.List; - -public class ClusterStateListenerModule - extends AbstractModule -{ - MonitorConfiguration monitorConfig; - - public ClusterStateListenerModule(HaGatewayConfiguration config) - { - monitorConfig = config.getMonitor(); - } - - /** - * Observers to cluster stats updates from - * {@link ActiveClusterMonitor}. - */ - @Provides - @Singleton - public List getClusterStatsObservers( - RoutingManager mgr, - BackendStateManager backendStateManager) - { - return ImmutableList.builder() - .add(new HealthCheckObserver(mgr)) - .add(new ClusterStatsObserver(backendStateManager)) - .build(); - } - - @Provides - public MonitorConfiguration getMonitorConfiguration() - { - return monitorConfig; - } -} diff --git a/gateway-ha/src/main/java/io/trino/gateway/ha/module/HaGatewayProviderModule.java b/gateway-ha/src/main/java/io/trino/gateway/ha/module/HaGatewayProviderModule.java index 0b1e383ab..8206172e7 100644 --- a/gateway-ha/src/main/java/io/trino/gateway/ha/module/HaGatewayProviderModule.java +++ b/gateway-ha/src/main/java/io/trino/gateway/ha/module/HaGatewayProviderModule.java @@ -23,13 +23,17 @@ import io.trino.gateway.ha.clustermonitor.ClusterStatsInfoApiMonitor; import io.trino.gateway.ha.clustermonitor.ClusterStatsJdbcMonitor; import io.trino.gateway.ha.clustermonitor.ClusterStatsMonitor; +import io.trino.gateway.ha.clustermonitor.ClusterStatsObserver; import io.trino.gateway.ha.clustermonitor.ForMonitor; +import io.trino.gateway.ha.clustermonitor.HealthCheckObserver; import io.trino.gateway.ha.clustermonitor.NoopClusterStatsMonitor; +import io.trino.gateway.ha.clustermonitor.TrinoClusterStatsObserver; import io.trino.gateway.ha.config.AuthenticationConfiguration; import io.trino.gateway.ha.config.AuthorizationConfiguration; import io.trino.gateway.ha.config.ClusterStatsConfiguration; import io.trino.gateway.ha.config.GatewayCookieConfigurationPropertiesProvider; import io.trino.gateway.ha.config.HaGatewayConfiguration; +import io.trino.gateway.ha.config.MonitorConfiguration; import io.trino.gateway.ha.config.OAuth2GatewayCookieConfigurationPropertiesProvider; import io.trino.gateway.ha.config.RoutingRulesConfiguration; import io.trino.gateway.ha.config.RulesExternalConfiguration; @@ -37,6 +41,7 @@ import io.trino.gateway.ha.router.BackendStateManager; import io.trino.gateway.ha.router.ForRouter; import io.trino.gateway.ha.router.RoutingGroupSelector; +import io.trino.gateway.ha.router.RoutingManager; import io.trino.gateway.ha.security.ApiAuthenticator; import io.trino.gateway.ha.security.AuthorizationManager; import io.trino.gateway.ha.security.BasicAuthFilter; @@ -54,6 +59,7 @@ import io.trino.gateway.ha.security.util.ChainedAuthFilter; import jakarta.ws.rs.container.ContainerRequestFilter; +import java.util.List; import java.util.Map; import static io.airlift.jaxrs.JaxrsBinder.jaxrsBinder; @@ -225,4 +231,22 @@ public ClusterStatsMonitor getClusterStatsMonitor(@ForMonitor HttpClient httpCli case NOOP -> new NoopClusterStatsMonitor(); }; } + + @Provides + @Singleton + public List getClusterStatsObservers( + RoutingManager mgr, + BackendStateManager backendStateManager) + { + return ImmutableList.builder() + .add(new HealthCheckObserver(mgr)) + .add(new ClusterStatsObserver(backendStateManager)) + .build(); + } + + @Provides + public MonitorConfiguration getMonitorConfiguration() + { + return configuration.getMonitor(); + } } diff --git a/gateway-ha/src/test/resources/test-config-template.yml b/gateway-ha/src/test/resources/test-config-template.yml index eb5e893d7..9d5552a73 100644 --- a/gateway-ha/src/test/resources/test-config-template.yml +++ b/gateway-ha/src/test/resources/test-config-template.yml @@ -12,7 +12,6 @@ dataStore: modules: - io.trino.gateway.ha.module.HaGatewayProviderModule - - io.trino.gateway.ha.module.ClusterStateListenerModule managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/src/test/resources/test-config-with-routing-template.yml b/gateway-ha/src/test/resources/test-config-with-routing-template.yml index 44581eed2..6917cb4b3 100644 --- a/gateway-ha/src/test/resources/test-config-with-routing-template.yml +++ b/gateway-ha/src/test/resources/test-config-with-routing-template.yml @@ -11,7 +11,6 @@ dataStore: modules: - io.trino.gateway.ha.module.HaGatewayProviderModule - - io.trino.gateway.ha.module.ClusterStateListenerModule managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml b/gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml index ccbe8402a..80db41598 100644 --- a/gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml +++ b/gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml @@ -11,7 +11,6 @@ dataStore: modules: - io.trino.gateway.ha.module.HaGatewayProviderModule - - io.trino.gateway.ha.module.ClusterStateListenerModule managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor From 760485dad43f6daf055f00b991d260b35d73ef54 Mon Sep 17 00:00:00 2001 From: Star Poon Date: Tue, 21 Jan 2025 22:19:45 +0900 Subject: [PATCH 3/5] Load HaGatewayProviderModule by default --- docs/operation.md | 1 - docs/quickstart-config.yaml | 3 --- gateway-ha/gateway-ha-config-docker.yml | 3 --- gateway-ha/gateway-ha-config.yml | 3 --- .../java/io/trino/gateway/baseapp/BaseApp.java | 14 +++++++------- .../io/trino/gateway/ha/HaGatewayLauncher.java | 2 ++ .../src/test/resources/auth/auth-test-config.yml | 3 --- .../src/test/resources/auth/oauth-test-config.yml | 3 --- .../src/test/resources/test-config-template.yml | 3 --- .../test-config-with-routing-template.yml | 3 --- .../test-config-without-x-forwarded-template.yml | 3 --- 11 files changed, 9 insertions(+), 32 deletions(-) diff --git a/docs/operation.md b/docs/operation.md index 570168772..26dd9e07a 100644 --- a/docs/operation.md +++ b/docs/operation.md @@ -44,7 +44,6 @@ to config file's modules section like below ```yaml modules: - - io.trino.gateway.ha.module.HaGatewayProviderModule - io.trino.gateway.ha.module.QueryCountBasedRouterProvider ``` - The router works on the stats it receives from the clusters about the load i.e number queries queued and running on a cluster at regular intervals which can be configured like below. The default interval is 1 min diff --git a/docs/quickstart-config.yaml b/docs/quickstart-config.yaml index dac2f4a6f..8f59fcf48 100644 --- a/docs/quickstart-config.yaml +++ b/docs/quickstart-config.yaml @@ -13,8 +13,5 @@ dataStore: clusterStatsConfiguration: monitorType: INFO_API -modules: - - io.trino.gateway.ha.module.HaGatewayProviderModule - managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/gateway-ha-config-docker.yml b/gateway-ha/gateway-ha-config-docker.yml index f632522ad..b8d82503b 100644 --- a/gateway-ha/gateway-ha-config-docker.yml +++ b/gateway-ha/gateway-ha-config-docker.yml @@ -16,8 +16,5 @@ dataStore: clusterStatsConfiguration: monitorType: INFO_API -modules: - - io.trino.gateway.ha.module.HaGatewayProviderModule - managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/gateway-ha-config.yml b/gateway-ha/gateway-ha-config.yml index 3dcfd2ad4..ba739f7cc 100644 --- a/gateway-ha/gateway-ha-config.yml +++ b/gateway-ha/gateway-ha-config.yml @@ -20,8 +20,5 @@ clusterStatsConfiguration: monitor: taskDelaySeconds: 10 -modules: - - io.trino.gateway.ha.module.HaGatewayProviderModule - managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java b/gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java index 8adb381d4..ac37eeb81 100644 --- a/gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java +++ b/gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java @@ -86,7 +86,7 @@ private static Module newModule(String clazz, HaGatewayConfiguration configurati return null; } - private static void validateModules(List modules, HaGatewayConfiguration configuration) + private static void addDefaultRouterProviderModules(List modules, HaGatewayConfiguration configuration) { Optional routerProvider = modules.stream() .filter(module -> module instanceof RouterBaseModule) @@ -102,14 +102,14 @@ public static List addModules(HaGatewayConfiguration configuration) { List modules = new ArrayList<>(); if (configuration.getModules() == null) { - logger.warn("No modules to load."); - return modules; + logger.info("No modules to load."); } - for (String clazz : configuration.getModules()) { - modules.add(newModule(clazz, configuration)); + else { + for (String clazz : configuration.getModules()) { + modules.add(newModule(clazz, configuration)); + } } - - validateModules(modules, configuration); + addDefaultRouterProviderModules(modules, configuration); return modules; } diff --git a/gateway-ha/src/main/java/io/trino/gateway/ha/HaGatewayLauncher.java b/gateway-ha/src/main/java/io/trino/gateway/ha/HaGatewayLauncher.java index cf6bb0931..9b5e34293 100644 --- a/gateway-ha/src/main/java/io/trino/gateway/ha/HaGatewayLauncher.java +++ b/gateway-ha/src/main/java/io/trino/gateway/ha/HaGatewayLauncher.java @@ -32,6 +32,7 @@ import io.airlift.units.Duration; import io.trino.gateway.baseapp.BaseApp; import io.trino.gateway.ha.config.HaGatewayConfiguration; +import io.trino.gateway.ha.module.HaGatewayProviderModule; import io.trino.gateway.ha.persistence.FlywayMigration; import org.weakref.jmx.guice.MBeanModule; @@ -65,6 +66,7 @@ private void start(List additionalModules, HaGatewayConfiguration config new JsonModule(), new JaxrsModule(), new TracingModule("trino-gateway", version), + new HaGatewayProviderModule(configuration), new BaseApp(configuration)); modules.addAll(additionalModules); diff --git a/gateway-ha/src/test/resources/auth/auth-test-config.yml b/gateway-ha/src/test/resources/auth/auth-test-config.yml index 4d0c16da3..6fe6e22dc 100644 --- a/gateway-ha/src/test/resources/auth/auth-test-config.yml +++ b/gateway-ha/src/test/resources/auth/auth-test-config.yml @@ -9,9 +9,6 @@ dataStore: driver: org.h2.Driver runMigrationsEnabled: false -modules: - - io.trino.gateway.ha.module.HaGatewayProviderModule - extraWhitelistPaths: - '/v1/custom.*' diff --git a/gateway-ha/src/test/resources/auth/oauth-test-config.yml b/gateway-ha/src/test/resources/auth/oauth-test-config.yml index c9b3fb31a..0e25d77b7 100644 --- a/gateway-ha/src/test/resources/auth/oauth-test-config.yml +++ b/gateway-ha/src/test/resources/auth/oauth-test-config.yml @@ -13,9 +13,6 @@ dataStore: driver: org.h2.Driver runMigrationsEnabled: false -modules: - - io.trino.gateway.ha.module.HaGatewayProviderModule - extraWhitelistPaths: - '/v1/custom.*' diff --git a/gateway-ha/src/test/resources/test-config-template.yml b/gateway-ha/src/test/resources/test-config-template.yml index 9d5552a73..e2c6d5b87 100644 --- a/gateway-ha/src/test/resources/test-config-template.yml +++ b/gateway-ha/src/test/resources/test-config-template.yml @@ -10,9 +10,6 @@ dataStore: driver: org.h2.Driver runMigrationsEnabled: false -modules: - - io.trino.gateway.ha.module.HaGatewayProviderModule - managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/src/test/resources/test-config-with-routing-template.yml b/gateway-ha/src/test/resources/test-config-with-routing-template.yml index 6917cb4b3..e490e211d 100644 --- a/gateway-ha/src/test/resources/test-config-with-routing-template.yml +++ b/gateway-ha/src/test/resources/test-config-with-routing-template.yml @@ -9,9 +9,6 @@ dataStore: driver: org.h2.Driver runMigrationsEnabled: false -modules: - - io.trino.gateway.ha.module.HaGatewayProviderModule - managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml b/gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml index 80db41598..adb323442 100644 --- a/gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml +++ b/gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml @@ -9,9 +9,6 @@ dataStore: driver: org.h2.Driver runMigrationsEnabled: false -modules: - - io.trino.gateway.ha.module.HaGatewayProviderModule - managedApps: - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor From 468e2b650961fb83436390d7186fa3c2fc37b299 Mon Sep 17 00:00:00 2001 From: Star Poon Date: Tue, 21 Jan 2025 22:27:55 +0900 Subject: [PATCH 4/5] Load ActiveClusterMonitor by default --- docs/quickstart-config.yaml | 3 --- gateway-ha/gateway-ha-config-docker.yml | 3 --- gateway-ha/gateway-ha-config.yml | 3 --- .../src/main/java/io/trino/gateway/baseapp/BaseApp.java | 4 +++- gateway-ha/src/test/resources/test-config-template.yml | 3 --- .../src/test/resources/test-config-with-routing-template.yml | 3 --- .../resources/test-config-without-x-forwarded-template.yml | 3 --- 7 files changed, 3 insertions(+), 19 deletions(-) diff --git a/docs/quickstart-config.yaml b/docs/quickstart-config.yaml index 8f59fcf48..57451ece7 100644 --- a/docs/quickstart-config.yaml +++ b/docs/quickstart-config.yaml @@ -12,6 +12,3 @@ dataStore: clusterStatsConfiguration: monitorType: INFO_API - -managedApps: - - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/gateway-ha-config-docker.yml b/gateway-ha/gateway-ha-config-docker.yml index b8d82503b..d05805e14 100644 --- a/gateway-ha/gateway-ha-config-docker.yml +++ b/gateway-ha/gateway-ha-config-docker.yml @@ -15,6 +15,3 @@ dataStore: clusterStatsConfiguration: monitorType: INFO_API - -managedApps: - - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/gateway-ha-config.yml b/gateway-ha/gateway-ha-config.yml index ba739f7cc..cd1ccfbc4 100644 --- a/gateway-ha/gateway-ha-config.yml +++ b/gateway-ha/gateway-ha-config.yml @@ -19,6 +19,3 @@ clusterStatsConfiguration: # This can be adjusted based on the coordinator state monitor: taskDelaySeconds: 10 - -managedApps: - - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor diff --git a/gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java b/gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java index ac37eeb81..1792770af 100644 --- a/gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java +++ b/gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java @@ -17,6 +17,7 @@ import com.google.inject.Module; import com.google.inject.Scopes; import io.airlift.log.Logger; +import io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor; import io.trino.gateway.ha.clustermonitor.ForMonitor; import io.trino.gateway.ha.config.HaGatewayConfiguration; import io.trino.gateway.ha.handler.ProxyHandlerStats; @@ -118,6 +119,7 @@ public static List addModules(HaGatewayConfiguration configuration) public void configure(Binder binder) { binder.bind(HaGatewayConfiguration.class).toInstance(configuration); + binder.bind(ActiveClusterMonitor.class).in(Scopes.SINGLETON); registerAuthFilters(binder); registerResources(binder); registerProxyResources(binder); @@ -131,7 +133,7 @@ public void configure(Binder binder) private static void addManagedApps(HaGatewayConfiguration configuration, Binder binder) { if (configuration.getManagedApps() == null) { - logger.error("No managed apps found"); + logger.info("No managed apps found"); return; } configuration.getManagedApps().forEach( diff --git a/gateway-ha/src/test/resources/test-config-template.yml b/gateway-ha/src/test/resources/test-config-template.yml index e2c6d5b87..6ad513e20 100644 --- a/gateway-ha/src/test/resources/test-config-template.yml +++ b/gateway-ha/src/test/resources/test-config-template.yml @@ -10,9 +10,6 @@ dataStore: driver: org.h2.Driver runMigrationsEnabled: false -managedApps: - - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor - clusterStatsConfiguration: monitorType: INFO_API diff --git a/gateway-ha/src/test/resources/test-config-with-routing-template.yml b/gateway-ha/src/test/resources/test-config-with-routing-template.yml index e490e211d..61b1bdc08 100644 --- a/gateway-ha/src/test/resources/test-config-with-routing-template.yml +++ b/gateway-ha/src/test/resources/test-config-with-routing-template.yml @@ -9,9 +9,6 @@ dataStore: driver: org.h2.Driver runMigrationsEnabled: false -managedApps: - - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor - clusterStatsConfiguration: monitorType: INFO_API diff --git a/gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml b/gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml index adb323442..b45c16fea 100644 --- a/gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml +++ b/gateway-ha/src/test/resources/test-config-without-x-forwarded-template.yml @@ -9,9 +9,6 @@ dataStore: driver: org.h2.Driver runMigrationsEnabled: false -managedApps: - - io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor - clusterStatsConfiguration: monitorType: INFO_API From d502895125da26874fc3147eca96e2865c4f7152 Mon Sep 17 00:00:00 2001 From: Star Poon Date: Thu, 23 Jan 2025 10:55:15 +0900 Subject: [PATCH 5/5] Add checks to prevent loading default modules in config --- .../io/trino/gateway/baseapp/BaseApp.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java b/gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java index 1792770af..391e284dd 100644 --- a/gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java +++ b/gateway-ha/src/main/java/io/trino/gateway/baseapp/BaseApp.java @@ -13,6 +13,7 @@ */ package io.trino.gateway.baseapp; +import com.google.common.collect.ImmutableList; import com.google.inject.Binder; import com.google.inject.Module; import com.google.inject.Scopes; @@ -107,6 +108,7 @@ public static List addModules(HaGatewayConfiguration configuration) } else { for (String clazz : configuration.getModules()) { + warnLoadingDefaultModules(clazz); modules.add(newModule(clazz, configuration)); } } @@ -115,6 +117,19 @@ public static List addModules(HaGatewayConfiguration configuration) return modules; } + private static void warnLoadingDefaultModules(String clazz) + { + // Remove this check when user finished the migration + List defaultModules = ImmutableList.of( + "io.trino.gateway.ha.module.HaGatewayProviderModule", + "io.trino.gateway.ha.module.ClusterStateListenerModule", + "io.trino.gateway.ha.module.ClusterStatsMonitorModule"); + if (defaultModules.contains(clazz)) { + logger.error("Default module [%s] is already being loaded. Please remove it from the config file", clazz); + System.exit(1); + } + } + @Override public void configure(Binder binder) { @@ -138,6 +153,11 @@ private static void addManagedApps(HaGatewayConfiguration configuration, Binder } configuration.getManagedApps().forEach( clazz -> { + // Remove this check when user finished the migration + if (clazz.equals("io.trino.gateway.ha.clustermonitor.ActiveClusterMonitor")) { + logger.error("Default class ActiveClusterMonitor is already being loaded. Please remove it from the config file"); + System.exit(1); + } try { Class c = Class.forName(clazz); binder.bind(c).in(Scopes.SINGLETON);