Skip to content

Commit

Permalink
Make ClusterStatsMonitor http client options can configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Alienero authored and oneonestar committed Aug 15, 2024
1 parent 112c500 commit e74202a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 8 deletions.
8 changes: 8 additions & 0 deletions docs/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,11 @@ Trino Gateway should be added:
-Djavax.net.ssl.trustStore=<truststore file>
-Djavax.net.ssl.trustStorePassword=<truststore password>
```

If you want to skip the hostname validation for a self-signed certificate,
the `serverConfig` configuration file should contain the following:

```
proxy.http-client.https.hostname-verification: false
monitor.http-client.https.hostname-verification: false
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.inject.Module;
import com.google.inject.Scopes;
import io.airlift.log.Logger;
import io.trino.gateway.ha.clustermonitor.ForMonitor;
import io.trino.gateway.ha.config.HaGatewayConfiguration;
import io.trino.gateway.ha.handler.ProxyHandlerStats;
import io.trino.gateway.ha.module.RouterBaseModule;
Expand Down Expand Up @@ -166,5 +167,6 @@ private static void registerProxyResources(Binder binder)
jaxrsBinder(binder).bind(RouterPreMatchContainerRequestFilter.class);
jaxrsBinder(binder).bind(ProxyRequestHandler.class);
httpClientBinder(binder).bindHttpClient("proxy", ForProxy.class);
httpClientBinder(binder).bindHttpClient("monitor", ForMonitor.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
package io.trino.gateway.ha.clustermonitor;

import io.airlift.http.client.HttpClient;
import io.airlift.http.client.HttpClientConfig;
import io.airlift.http.client.JsonResponseHandler;
import io.airlift.http.client.Request;
import io.airlift.http.client.jetty.JettyHttpClient;
import io.trino.gateway.ha.config.ProxyBackendConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -28,14 +26,19 @@
import static io.airlift.http.client.JsonResponseHandler.createJsonResponseHandler;
import static io.airlift.http.client.Request.Builder.prepareGet;
import static io.airlift.json.JsonCodec.jsonCodec;
import static java.util.Objects.requireNonNull;

public class ClusterStatsInfoApiMonitor
implements ClusterStatsMonitor
{
//TODO: make client options configurable
private static final HttpClient client = new JettyHttpClient(new HttpClientConfig());
private static final Logger log = LoggerFactory.getLogger(ClusterStatsInfoApiMonitor.class);
private static final JsonResponseHandler<ServerInfo> SERVER_INFO_JSON_RESPONSE_HANDLER = createJsonResponseHandler(jsonCodec(ServerInfo.class));
private final HttpClient client;

public ClusterStatsInfoApiMonitor(HttpClient client)
{
this.client = requireNonNull(client, "client is null");
}

@Override
public ClusterStats monitor(ProxyBackendConfiguration backend)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.clustermonitor;

import com.google.inject.BindingAnnotation;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Retention(RUNTIME)
@Target({FIELD, PARAMETER, METHOD})
@BindingAnnotation
public @interface ForMonitor
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
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;
Expand All @@ -38,14 +40,14 @@ public ClusterStatsMonitorModule(HaGatewayConfiguration config)

@Provides
@Singleton
public ClusterStatsMonitor getClusterStatsMonitor()
public ClusterStatsMonitor getClusterStatsMonitor(@ForMonitor HttpClient httpClient)
{
ClusterStatsConfiguration clusterStatsConfig = config.getClusterStatsConfiguration();
if (config.getBackendState() == null) {
return new ClusterStatsInfoApiMonitor();
return new ClusterStatsInfoApiMonitor(httpClient);
}
return switch (clusterStatsConfig.getMonitorType()) {
case INFO_API -> new ClusterStatsInfoApiMonitor();
case INFO_API -> new ClusterStatsInfoApiMonitor(httpClient);
case UI_API -> new ClusterStatsHttpMonitor(config.getBackendState());
case JDBC -> new ClusterStatsJdbcMonitor(config.getBackendState());
case NOOP -> new NoopClusterStatsMonitor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
package io.trino.gateway.ha.clustermonitor;

import io.airlift.http.client.HttpClientConfig;
import io.airlift.http.client.jetty.JettyHttpClient;
import io.trino.gateway.ha.config.BackendStateConfiguration;
import io.trino.gateway.ha.config.ProxyBackendConfiguration;
import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -61,7 +63,7 @@ public void testJdbcMonitor()
@Test
public void testInfoApiMonitor()
{
testClusterStatsMonitor(ignored -> new ClusterStatsInfoApiMonitor());
testClusterStatsMonitor(ignored -> new ClusterStatsInfoApiMonitor(new JettyHttpClient(new HttpClientConfig())));
}

private void testClusterStatsMonitor(Function<BackendStateConfiguration, ClusterStatsMonitor> monitorFactory)
Expand Down

0 comments on commit e74202a

Please sign in to comment.