Skip to content

Commit

Permalink
Version bump for next release
Browse files Browse the repository at this point in the history
Adding routing for UI path
  • Loading branch information
Puneet Jaiswal authored and puneetjaiswal committed Aug 12, 2019
1 parent 6345501 commit 73b67d3
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,2 +1,4 @@
.idea
**/target/*
.DS_Store
*.iml
2 changes: 1 addition & 1 deletion baseapp/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.lyft.data</groupId>
<artifactId>prestogateway-parent</artifactId>
<version>1.6.0</version>
<version>1.6.1</version>
<relativePath>../</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion gateway/pom.xml
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.lyft.data</groupId>
<artifactId>prestogateway-parent</artifactId>
<version>1.6.0</version>
<version>1.6.1</version>
<relativePath>../</relativePath>
</parent>

Expand Down
Expand Up @@ -14,7 +14,7 @@ public class RequestRouterConfiguration {
private String cacheDir;

// Use SSL?
private String ssl;
private boolean ssl;
private String keystorePath;
private String keystorePass;

Expand Down
Expand Up @@ -39,11 +39,12 @@ public class QueryIdCachingProxyHandler extends ProxyHandler {
public static final String V1_STATEMENT_PATH = "/v1/statement";
public static final String V1_QUERY_PATH = "/v1/query";
public static final String V1_INFO_PATH = "/v1/info";
public static final String QUERY_HTML_PATH = "/ui/query.html";
public static final String PRESTO_UI_PATH = "/ui";
public static final String USER_HEADER = "X-Presto-User";
public static final String SOURCE_HEADER = "X-Presto-Source";
public static final String ROUTING_GROUP_HEADER = "X-Presto-Routing-Group";
public static final String ADHOC_ROUTING_GROUP = "adhoc";
static final int QUERY_TEXT_LENGTH_FOR_HISTORY = 200;

private static final Pattern EXTRACT_BETWEEN_SINGLE_QUOTES = Pattern.compile("'([^\\s']+)'");

Expand Down Expand Up @@ -80,14 +81,12 @@ private int getApplicationPort(GatewayConfiguration configuration) {
: Stream.of((SimpleServerFactory) configuration.getServerFactory())
.map(SimpleServerFactory::getConnector);

int port =
connectors
.filter(connector -> connector.getClass().isAssignableFrom(HttpConnectorFactory.class))
.map(connector -> (HttpConnectorFactory) connector)
.mapToInt(HttpConnectorFactory::getPort)
.findFirst()
.orElseThrow(IllegalStateException::new);
return port;
return connectors
.filter(connector -> connector.getClass().isAssignableFrom(HttpConnectorFactory.class))
.map(connector -> (HttpConnectorFactory) connector)
.mapToInt(HttpConnectorFactory::getPort)
.findFirst()
.orElseThrow(IllegalStateException::new);
}

@Override
Expand All @@ -110,9 +109,9 @@ public void preConnectionHook(HttpServletRequest request, Request proxyRequest)

private boolean isPathWhiteListed(String path) {
return path.startsWith(V1_STATEMENT_PATH)
|| path.startsWith(V1_QUERY_PATH)
|| path.startsWith(QUERY_HTML_PATH)
|| path.startsWith(V1_INFO_PATH);
|| path.startsWith(V1_QUERY_PATH)
|| path.startsWith(PRESTO_UI_PATH)
|| path.startsWith(V1_INFO_PATH);
}

@Override
Expand Down Expand Up @@ -192,7 +191,7 @@ protected String extractQueryIdIfPresent(HttpServletRequest request) {
if (tokens.length >= 4) {
queryId = tokens[3];
}
} else if (path.startsWith(QUERY_HTML_PATH)) {
} else if (path.startsWith(PRESTO_UI_PATH)) {
queryId = queryParams;
}
log.debug("query id in url [{}]", queryId);
Expand Down Expand Up @@ -272,7 +271,9 @@ private QueryHistoryManager.QueryDetail getQueryDetailsFromRequest(HttpServletRe
queryDetail.setSource(request.getHeader(SOURCE_HEADER));
String queryText = CharStreams.toString(request.getReader());
queryDetail.setQueryText(
queryText.length() > 400 ? queryText.substring(0, 400) + "..." : queryText);
queryText.length() > QUERY_TEXT_LENGTH_FOR_HISTORY
? queryText.substring(0, QUERY_TEXT_LENGTH_FOR_HISTORY) + "..."
: queryText);
return queryDetail;
}
}
Expand Up @@ -77,7 +77,7 @@ public ProxyServer provideGateway() {
routerProxyConfig.setLocalPort(routerConfiguration.getPort());
routerProxyConfig.setName(routerConfiguration.getName());
routerProxyConfig.setProxyTo("");
routerProxyConfig.setSsl(routerConfiguration.getSsl());
routerProxyConfig.setSsl(routerConfiguration.isSsl());
routerProxyConfig.setKeystorePath(routerConfiguration.getKeystorePath());
routerProxyConfig.setKeystorePass(routerConfiguration.getKeystorePass());

Expand Down
Expand Up @@ -20,7 +20,8 @@ public QueryHistoryManagerImpl(int size) {

@Override
public void submitQueryDetail(QueryDetail queryDetail) {
if (queryDetail.getQueryText().startsWith("EXPLAIN (TYPE VALIDATE) ")) {
String queryText = queryDetail.getQueryText();
if (queryText.startsWith("EXPLAIN (TYPE VALIDATE) ")) {
return;
}
int pos = (int) queryCounter.incrementAndGet() % size;
Expand Down
2 changes: 1 addition & 1 deletion gateway/src/main/resources/template/gateway-view.ftl
Expand Up @@ -82,7 +82,7 @@
<tbody>
<#list queryHistory as q>
<tr>
<td><a href="${q.backendUrl}/ui/query.html?${q.queryId}"
<td><a href="/ui/query.html?${q.queryId}"
target="_blank">${q.queryId}</a></td>
<td> ${q.user}</td>
<td>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -9,7 +9,7 @@
<artifactId>prestogateway-parent</artifactId>
<name>prestogateway-parent</name>
<packaging>pom</packaging>
<version>1.6.0</version>
<version>1.6.1</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down Expand Up @@ -96,7 +96,7 @@
<configLocation>google_checks.xml</configLocation>
<consoleOutput>true</consoleOutput>
<logViolationsToConsole>true</logViolationsToConsole>
<failOnViolation>false</failOnViolation>
<failOnViolation>true</failOnViolation>
<failsOnError>true</failsOnError>
<violationIgnore>${checkstyle.violation.ignore}</violationIgnore>
<violationSeverity>warning</violationSeverity>
Expand Down
2 changes: 1 addition & 1 deletion proxyserver/pom.xml
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.lyft.data</groupId>
<artifactId>prestogateway-parent</artifactId>
<version>1.6.0</version>
<version>1.6.1</version>
<relativePath>../</relativePath>
</parent>

Expand Down
Expand Up @@ -10,6 +10,8 @@

import lombok.extern.slf4j.Slf4j;

import org.apache.http.util.TextUtils;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.proxy.ConnectHandler;
import org.eclipse.jetty.server.HttpConfiguration;
Expand Down Expand Up @@ -38,7 +40,7 @@ public ProxyServer(ProxyServerConfiguration config, ProxyHandler proxyHandler) {
private void setupContext(ProxyServerConfiguration config) {
ServerConnector connector = null;

if (config.getSsl()) {
if (config.isSsl()) {
String keystorePath = config.getKeystorePath();
String keystorePass = config.getKeystorePass();
File keystoreFile = new File(keystorePath);
Expand All @@ -48,22 +50,24 @@ private void setupContext(ProxyServerConfiguration config) {
sslContextFactory.setStopTimeout(TimeUnit.SECONDS.toMillis(15));
sslContextFactory.setSslSessionTimeout((int) TimeUnit.SECONDS.toMillis(15));

if (!(keystorePath == null || keystorePath.isEmpty())) {
if (!TextUtils.isBlank(keystorePath)) {
sslContextFactory.setKeyStorePath(keystoreFile.getAbsolutePath());
sslContextFactory.setKeyStorePassword(keystorePass);
sslContextFactory.setKeyManagerPassword(keystorePass);
}

HttpConfiguration httpsConfig = new HttpConfiguration();
httpsConfig.setSecureScheme("https");
httpsConfig.setSecureScheme(HttpScheme.HTTPS.asString());
httpsConfig.setSecurePort(config.getLocalPort());
httpsConfig.setOutputBufferSize(32768);

SecureRequestCustomizer src = new SecureRequestCustomizer();
src.setStsMaxAge(2000);
src.setStsMaxAge(TimeUnit.SECONDS.toSeconds(2000));
src.setStsIncludeSubDomains(true);
httpsConfig.addCustomizer(src);
connector = new ServerConnector(server,
connector =
new ServerConnector(
server,
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
new HttpConnectionFactory(httpsConfig));
} else {
Expand Down
Expand Up @@ -10,7 +10,7 @@ public class ProxyServerConfiguration {
private String prefix = "/";
private String trustAll = "true";
private String preserveHost = "true";
private String ssl = "false";
private boolean ssl;
private String keystorePath;
private String keystorePass;

Expand All @@ -26,7 +26,7 @@ protected String getPreserveHost() {
return preserveHost;
}

protected boolean getSsl() {
return Boolean.parseBoolean(ssl);
protected boolean isSsl() {
return ssl;
}
}
Expand Up @@ -33,7 +33,7 @@ protected HttpClient newHttpClient() {
sslFactory.setSslSessionTimeout((int) TimeUnit.SECONDS.toMillis(15));

HttpClient httpClient = new HttpClient(sslFactory);
httpClient.setMaxConnectionsPerDestination(2000);
httpClient.setMaxConnectionsPerDestination(10000);
httpClient.setConnectTimeout(TimeUnit.SECONDS.toMillis(60));
return httpClient;
}
Expand Down

0 comments on commit 73b67d3

Please sign in to comment.