Skip to content

Commit

Permalink
[CDAP-21118] Enable gzip compression for PreviewHttpServer
Browse files Browse the repository at this point in the history
  • Loading branch information
sidhdirenge committed Jan 31, 2025
1 parent 82c4490 commit 8b2dc6a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
import io.cdap.cdap.common.security.HttpsEnabler;
import io.cdap.cdap.internal.app.services.AppFabricServer;
import io.cdap.cdap.proto.id.NamespaceId;
import io.cdap.http.ChannelPipelineModifier;
import io.cdap.http.HttpHandler;
import io.cdap.http.NettyHttpService;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.HttpContentDecompressor;
import java.util.Set;
import org.apache.twill.common.Cancellable;
import org.apache.twill.discovery.DiscoveryService;
Expand Down Expand Up @@ -64,7 +67,13 @@ public class PreviewHttpServer extends AbstractIdleService {
.setConnectionBacklog(cConf.getInt(Constants.Preview.BACKLOG_CONNECTIONS))
.setExecThreadPoolSize(cConf.getInt(Constants.Preview.EXEC_THREADS))
.setBossThreadPoolSize(cConf.getInt(Constants.Preview.BOSS_THREADS))
.setWorkerThreadPoolSize(cConf.getInt(Constants.Preview.WORKER_THREADS));
.setWorkerThreadPoolSize(cConf.getInt(Constants.Preview.WORKER_THREADS))
.setChannelPipelineModifier(new ChannelPipelineModifier() {
@Override
public void modify(ChannelPipeline pipeline) {
pipeline.addAfter("compressor", "decompressor", new HttpContentDecompressor());
}
});

if (cConf.getBoolean(Constants.Security.SSL.INTERNAL_ENABLED)) {
new HttpsEnabler().configureKeyStore(cConf, sConf).enable(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ public static final class Preview {
public static final String CONTAINER_JVM_OPTS = "preview.runner.container.jvm.opts";
public static final String GCE_METADATA_HOST_ENV_VAR = "GCE_METADATA_HOST";
public static final String INTERNAL_ROUTER_ENABLED = "preview.runner.internal.router.enabled";
public static final String HTTP_COMPRESS_PAYLOAD = "preview.http.compress.payload";
}

/**
Expand Down
8 changes: 8 additions & 0 deletions cdap-common/src/main/resources/cdap-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3795,6 +3795,14 @@
</description>
</property>

<property>
<name>preview.http.compress.payload</name>
<value>true</value>
<description>
Compress payload for HTTP calls in the preview http handler.
</description>
</property>

<property>
<name>service.retry.policy.base.delay.ms</name>
<value>100</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package io.cdap.cdap.messaging.client;

import com.google.inject.Inject;
import io.cdap.cdap.common.conf.CConfiguration;
import io.cdap.cdap.common.conf.Constants;
import io.cdap.cdap.common.conf.Constants.Service;
import io.cdap.cdap.common.internal.remote.RemoteClientFactory;
import org.slf4j.Logger;
Expand All @@ -31,10 +33,11 @@ public class PreviewRunnerClientMessagingService extends AbstractClientMessaging
PreviewRunnerClientMessagingService.class);

@Inject
public PreviewRunnerClientMessagingService(RemoteClientFactory remoteClientFactory) {
// TODO (CDAP-21118) - enable gzip compression for preview http server.
public PreviewRunnerClientMessagingService(CConfiguration cConf,
RemoteClientFactory remoteClientFactory) {
super(remoteClientFactory.createRemoteClient(Service.PREVIEW_HTTP, HTTP_REQUEST_CONFIG,
"/v1/namespaces/"), false);
"/v1/namespaces/"),
cConf.getBoolean(Constants.Preview.HTTP_COMPRESS_PAYLOAD));
LOG.info("PreviewRunnerClientMessagingService initialised");
}
}

0 comments on commit 8b2dc6a

Please sign in to comment.