Skip to content

Commit 7adc97f

Browse files
committed
Fix null check for clusterStatsConfiguration
1 parent a2d2d3d commit 7adc97f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

gateway-ha/src/main/java/io/trino/gateway/ha/module/HaGatewayProviderModule.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
import java.util.Map;
6666

6767
import static io.airlift.jaxrs.JaxrsBinder.jaxrsBinder;
68+
import static io.trino.gateway.ha.config.ClusterStatsMonitorType.INFO_API;
69+
import static io.trino.gateway.ha.config.ClusterStatsMonitorType.NOOP;
6870
import static java.util.Objects.requireNonNull;
6971

7072
public class HaGatewayProviderModule
@@ -223,9 +225,13 @@ public RoutingGroupSelector getRoutingGroupSelector(@ForRouter HttpClient httpCl
223225
public ClusterStatsMonitor getClusterStatsMonitor(@ForMonitor HttpClient httpClient)
224226
{
225227
ClusterStatsConfiguration clusterStatsConfig = configuration.getClusterStatsConfiguration();
226-
if (configuration.getBackendState() == null) {
228+
if (clusterStatsConfig == null) {
227229
return new ClusterStatsInfoApiMonitor(httpClient, configuration.getMonitor());
228230
}
231+
if (!(clusterStatsConfig.getMonitorType() == INFO_API || clusterStatsConfig.getMonitorType() == NOOP)
232+
&& configuration.getBackendState() == null) {
233+
throw new IllegalArgumentException("BackendStateConfiguration is required for monitor type: " + clusterStatsConfig.getMonitorType());
234+
}
229235
return switch (clusterStatsConfig.getMonitorType()) {
230236
case INFO_API -> new ClusterStatsInfoApiMonitor(httpClient, configuration.getMonitor());
231237
case UI_API -> new ClusterStatsHttpMonitor(configuration.getBackendState());

0 commit comments

Comments
 (0)