Skip to content

Commit 40337f6

Browse files
andythsuwillmostly
authored andcommitted
Convert byte array to string for logging in ProxyResponse
1 parent c2ba1ea commit 40337f6

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed

docs/installation.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ serverConfig:
212212
http-server.process-forwarded: true
213213
```
214214

215+
## Configure larger proxy response size
216+
217+
Trino Gateway reads the response from Trino in bytes (up to 32MB by default).
218+
It can be configured by setting:
219+
220+
```yaml
221+
proxyResponseConfiguration:
222+
responseSize: 50MB
223+
```
224+
215225
## Running Trino Gateway
216226

217227
Start Trino Gateway with the following java command in the directory of the

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class HaGatewayConfiguration
4242
private GatewayCookieConfiguration gatewayCookieConfiguration = new GatewayCookieConfiguration();
4343
private List<String> statementPaths = ImmutableList.of(V1_STATEMENT_PATH);
4444
private boolean includeClusterHostInResponse;
45+
private ProxyResponseConfiguration proxyResponseConfiguration = new ProxyResponseConfiguration();
4546

4647
private RequestAnalyzerConfig requestAnalyzerConfig = new RequestAnalyzerConfig();
4748

@@ -255,6 +256,16 @@ public void setIncludeClusterHostInResponse(boolean includeClusterHostInResponse
255256
this.includeClusterHostInResponse = includeClusterHostInResponse;
256257
}
257258

259+
public ProxyResponseConfiguration getProxyResponseConfiguration()
260+
{
261+
return this.proxyResponseConfiguration;
262+
}
263+
264+
public void setProxyResponseConfiguration(ProxyResponseConfiguration proxyResponseConfiguration)
265+
{
266+
this.proxyResponseConfiguration = proxyResponseConfiguration;
267+
}
268+
258269
private void validateStatementPath(String statementPath, List<String> statementPaths)
259270
{
260271
if (statementPath.startsWith(V1_STATEMENT_PATH) ||
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.trino.gateway.ha.config;
15+
16+
import io.airlift.units.DataSize;
17+
18+
import static io.airlift.units.DataSize.Unit.MEGABYTE;
19+
20+
public class ProxyResponseConfiguration
21+
{
22+
private DataSize responseSize = DataSize.of(32, MEGABYTE);
23+
24+
public ProxyResponseConfiguration() {}
25+
26+
public DataSize getResponseSize()
27+
{
28+
return responseSize;
29+
}
30+
31+
public void setResponseSize(DataSize responseSize)
32+
{
33+
this.responseSize = responseSize;
34+
}
35+
}

gateway-ha/src/main/java/io/trino/gateway/proxyserver/ProxyRequestHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.airlift.units.Duration;
2626
import io.trino.gateway.ha.config.GatewayCookieConfigurationPropertiesProvider;
2727
import io.trino.gateway.ha.config.HaGatewayConfiguration;
28+
import io.trino.gateway.ha.config.ProxyResponseConfiguration;
2829
import io.trino.gateway.ha.router.GatewayCookie;
2930
import io.trino.gateway.ha.router.OAuth2GatewayCookie;
3031
import io.trino.gateway.ha.router.QueryHistoryManager;
@@ -87,6 +88,7 @@ public class ProxyRequestHandler
8788
private final List<String> statementPaths;
8889
private final boolean includeClusterInfoInResponse;
8990
private final TrinoRequestUser.TrinoRequestUserProvider trinoRequestUserProvider;
91+
private final ProxyResponseConfiguration proxyResponseConfiguration;
9092

9193
@Inject
9294
public ProxyRequestHandler(
@@ -104,6 +106,7 @@ public ProxyRequestHandler(
104106
addXForwardedHeaders = haGatewayConfiguration.getRouting().isAddXForwardedHeaders();
105107
statementPaths = haGatewayConfiguration.getStatementPaths();
106108
this.includeClusterInfoInResponse = haGatewayConfiguration.isIncludeClusterHostInResponse();
109+
proxyResponseConfiguration = haGatewayConfiguration.getProxyResponseConfiguration();
107110
}
108111

109112
@PreDestroy
@@ -245,7 +248,7 @@ private void setupAsyncResponse(AsyncResponse asyncResponse, ListenableFuture<Re
245248

246249
private FluentFuture<ProxyResponse> executeHttp(Request request)
247250
{
248-
return FluentFuture.from(httpClient.executeAsync(request, new ProxyResponseHandler()));
251+
return FluentFuture.from(httpClient.executeAsync(request, new ProxyResponseHandler(proxyResponseConfiguration)));
249252
}
250253

251254
private static Response handleProxyException(Request request, ProxyException e)

gateway-ha/src/main/java/io/trino/gateway/proxyserver/ProxyResponseHandler.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,25 @@
1818
import io.airlift.http.client.Request;
1919
import io.airlift.http.client.Response;
2020
import io.airlift.http.client.ResponseHandler;
21+
import io.airlift.units.DataSize;
22+
import io.trino.gateway.ha.config.ProxyResponseConfiguration;
2123
import io.trino.gateway.proxyserver.ProxyResponseHandler.ProxyResponse;
2224

2325
import java.io.IOException;
26+
import java.nio.charset.StandardCharsets;
2427

2528
import static java.util.Objects.requireNonNull;
2629

2730
public class ProxyResponseHandler
2831
implements ResponseHandler<ProxyResponse, RuntimeException>
2932
{
33+
private final DataSize responseSize;
34+
35+
public ProxyResponseHandler(ProxyResponseConfiguration proxyResponseConfiguration)
36+
{
37+
this.responseSize = requireNonNull(proxyResponseConfiguration.getResponseSize(), "responseSize is null");
38+
}
39+
3040
@Override
3141
public ProxyResponse handleException(Request request, Exception exception)
3242
{
@@ -37,7 +47,7 @@ public ProxyResponse handleException(Request request, Exception exception)
3747
public ProxyResponse handle(Request request, Response response)
3848
{
3949
try {
40-
return new ProxyResponse(response.getStatusCode(), response.getHeaders(), response.getInputStream().readAllBytes());
50+
return new ProxyResponse(response.getStatusCode(), response.getHeaders(), new String(response.getInputStream().readNBytes((int) responseSize.toBytes()), StandardCharsets.UTF_8));
4151
}
4252
catch (IOException e) {
4353
throw new ProxyException("Failed reading response from remote Trino server", e);
@@ -47,7 +57,7 @@ public ProxyResponse handle(Request request, Response response)
4757
public record ProxyResponse(
4858
int statusCode,
4959
ListMultimap<HeaderName, String> headers,
50-
byte[] body)
60+
String body)
5161
{
5262
public ProxyResponse
5363
{

0 commit comments

Comments
 (0)