Commit ce4d4bfd authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch 'es-rest-client-config' into 'main'

A few updates

See merge request genesys-pgr/genesys-server!703
parents c72f1be2 35cb61d2
......@@ -37,8 +37,8 @@ RUN set -ex; \
WORKDIR ${JETTY_BASE}
# Update jetty configuration
# Enable http-forwarded module
RUN java -jar /usr/local/jetty/start.jar --create-startd --add-to-start=http-forwarded
# Enable modules: http-forwarded, gzip
RUN java -jar /usr/local/jetty/start.jar --create-startd --add-module=http-forwarded --add-module=gzip
# Add our config
COPY jetty ${JETTY_BASE}/
......
# ---------------------------------------
# Module: gzip
# Enables GzipHandler for dynamic gzip compression for the entire server.
# If MSIE prior to version 7 are to be handled, also enable the msie module.
# ---------------------------------------
--module=gzip
## Minimum content length after which gzip is enabled
jetty.gzip.minGzipSize=500
## Check whether a file with *.gz extension exists
# jetty.gzip.checkGzExists=false
## Inflate request buffer size, or 0 for no request inflation
# jetty.gzip.inflateBufferSize=0
## Inflater pool max size (-1 for unlimited, 0 for no pooling)
# jetty.gzip.inflaterPool.capacity=1024
## Inflater pool use GZIP compatible compression
#jetty.gzip.inflaterPool.noWrap=true
## Deflater pool max size (-1 for unlimited, 0 for no pooling)
# jetty.gzip.deflaterPool.capacity=1024
## Gzip compression level (-1 for default)
# jetty.gzip.deflaterPool.compressionLevel=-1
## Deflater pool use GZIP compatible compression
# jetty.gzip.deflaterPool.noWrap=true
## Set the {@link Deflater} flush mode to use.
jetty.gzip.syncFlush=true
## The set of DispatcherType that this filter will operate on
# jetty.gzip.dispatcherTypes=REQUEST
## Comma separated list of included HTTP methods
jetty.gzip.includedMethodList=GET,POST,PUT
## Comma separated list of excluded HTTP methods
# jetty.gzip.excludedMethodList=
## Comma separated list of included MIME types
# jetty.gzip.includedMimeTypeList=
## Comma separated list of excluded MIME types
# jetty.gzip.excludedMimeTypeList=
## Comma separated list of included Path specs
# jetty.gzip.includedPathList=
## Comma separated list of excluded Path specs
# jetty.gzip.excludedPathList=
......@@ -462,7 +462,7 @@ public class ElasticsearchServiceImpl implements ElasticsearchService, Initializ
if (queueSize == 0) {
break;
}
LOG.info("ES Reindex queue has {} elements, waiting to realias {}...", queueSize, indexName);
LOG.trace("ES Reindex queue has {} elements, waiting to realias {}...", queueSize, indexName);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
......
......@@ -29,7 +29,6 @@ import java.util.concurrent.LinkedBlockingQueue;
import org.apache.commons.lang3.RandomUtils;
import org.apache.http.HttpHost;
import org.apache.http.impl.NoConnectionReuseStrategy;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.genesys.blocks.model.JsonViews;
......@@ -63,8 +62,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.ElasticsearchConfigurationSupport;
import org.springframework.data.elasticsearch.core.ElasticsearchEntityMapper;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
......@@ -144,39 +141,44 @@ public class ElasticsearchConfig extends ElasticsearchConfigurationSupport {
@Bean
@DependsOn({ "embeddedNode" })
public RestHighLevelClient elasticClient() throws Exception {
ArrayList<HttpHost> httpHosts = new ArrayList<>();
if ("embedded".equals(clusterNodes)) {
var embeddedNode = embeddedNode();
if (embeddedNode != null) {
return RestClients.create(ClientConfiguration.create("localhost:" + embeddedNode.getObject().getPort())).rest();
httpHosts.add(new HttpHost("localhost", embeddedNode.getObject().getPort()));
} else {
throw new RuntimeException("ES configuration mismatch. Embedded node is not available");
}
throw new RuntimeException("ES configuration mismatch. Embedded node is not available");
} else {
LOG.info("Using external Elasticsearch nodes={}", clusterNodes);
ArrayList<HttpHost> httpHosts = new ArrayList<>();
LOG.info("Using external Elasticsearch nodes={}", clusterNodes);
for (String host : clusterNodes.split(",")) {
URL hostUrl = new URL(host);
httpHosts.add(new HttpHost(hostUrl.getHost(), hostUrl.getPort(), hostUrl.getProtocol()));
}
return new RestHighLevelClient(RestClient.builder(httpHosts.toArray(new HttpHost[httpHosts.size()])).setHttpClientConfigCallback((httpClientBuilder) -> {
// Does this make a difference?
httpClientBuilder.disableAuthCaching().disableCookieManagement();
httpClientBuilder.setMaxConnTotal(50);
httpClientBuilder.setMaxConnPerRoute(50);
// Don't reuse connections
httpClientBuilder.setConnectionReuseStrategy(NoConnectionReuseStrategy.INSTANCE);
// TCP
httpClientBuilder.setDefaultIOReactorConfig(IOReactorConfig.custom().setSoKeepAlive(true).setSoTimeout(1000).build());
System.err.println("Updated ES HTTP client config");
return httpClientBuilder;
}).setRequestConfigCallback((requestConfigBuilder) -> {
requestConfigBuilder.setConnectTimeout(2000); // default is 1000
requestConfigBuilder.setConnectionRequestTimeout(2000); // default is 1000
requestConfigBuilder.setSocketTimeout(45 * 1000); // 45s
return requestConfigBuilder;
}));
}
return new RestHighLevelClient(RestClient.builder(httpHosts.toArray(new HttpHost[] {})).setHttpClientConfigCallback((httpClientBuilder) -> {
// Does this make a difference?
httpClientBuilder.disableAuthCaching().disableCookieManagement();
httpClientBuilder.setMaxConnTotal(50);
httpClientBuilder.setMaxConnPerRoute(50);
// Don't reuse connections
httpClientBuilder.setConnectionReuseStrategy(NoConnectionReuseStrategy.INSTANCE);
System.err.println("Updated ES HTTP client config");
return httpClientBuilder;
}).setRequestConfigCallback((requestConfigBuilder) -> {
requestConfigBuilder.setConnectTimeout(2000); // default is 1000
requestConfigBuilder.setConnectionRequestTimeout(2000); // default is 1000
requestConfigBuilder.setSocketTimeout(-1); // forever
requestConfigBuilder.setContentCompressionEnabled(false);
return requestConfigBuilder;
}));
}
// We don't want to scan for entities
......
......@@ -38,7 +38,6 @@ import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import org.tuckey.web.filters.urlrewrite.UrlRewriteFilter;
import org.tuckey.web.filters.urlrewrite.gzip.GzipFilter;
//import com.hazelcast.web.SessionListener;
......@@ -146,10 +145,7 @@ public class WebInitializer extends AbstractAnnotationConfigDispatcherServletIni
sitemeshFilter.addMappingForUrlPatterns(null, false, "/*");
// GZip filter configuration
final FilterRegistration.Dynamic gZIPFilter = servletContext.addFilter("gZIPFilter", GzipFilter.class);
gZIPFilter.addMappingForUrlPatterns(null, false, "/html/*");
// gZIPFilter.addMappingForUrlPatterns(null, false, "/sitemap*");
// gZIPFilter.addMappingForUrlPatterns(null, false, "/api/*");
// final FilterRegistration.Dynamic gZIPFilter = servletContext.addFilter("gZIPFilter", GzipFilter.class); // Never enable gzipFilter!
}
@Override
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment