Skip to content

Commit

Permalink
Upgrade HttpCore5/HttpClient5 to support ExtendedSocketOption in Http…
Browse files Browse the repository at this point in the history
…AsyncClient (opensearch-project#16757)

* upgrade httpcore5/httpclient5 to support ExtendedSocketOption in HttpAsyncClient

Signed-off-by: kkewwei <kewei.11@bytedance.com>
Signed-off-by: kkewwei <kkewwei@163.com>

* Use the Upgrade flow by default

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

* Update Reactor Netty to 1.1.26.Final

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

* Add SETTING_H2C_MAX_CONTENT_LENGTH to configure h2cMaxContentLength for reactor-netty4 transport

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

* Update Apache HttpCore5 to 5.3.2

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

---------

Signed-off-by: kkewwei <kewei.11@bytedance.com>
Signed-off-by: kkewwei <kkewwei@163.com>
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
Co-authored-by: Andriy Redko <andriy.redko@aiven.io>
  • Loading branch information
kkewwei and reta authored Jan 15, 2025
1 parent f9c239d commit fa4595c
Show file tree
Hide file tree
Showing 29 changed files with 78 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Views, simplify data access and manipulation by providing a virtual layer over one or more indices ([#11957](https://github.com/opensearch-project/OpenSearch/pull/11957))

### Dependencies
- Bump Apache HttpCore5/HttpClient5 dependencies from 5.2.5/5.3.1 to 5.3.1/5.4.1 to support ExtendedSocketOption in HttpAsyncClient ([#16757](https://github.com/opensearch-project/OpenSearch/pull/16757))

### Changed
- Changed locale provider from COMPAT to CLDR ([#14345](https://github.com/opensearch-project/OpenSearch/pull/14345))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

grant {
permission java.net.SocketPermission "*", "connect,resolve";
};
1 change: 0 additions & 1 deletion client/rest/licenses/httpclient5-5.3.1.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions client/rest/licenses/httpclient5-5.4.1.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ce913081e592ee8eeee35c4e577d7dce13cba7a4
1 change: 0 additions & 1 deletion client/rest/licenses/httpcore5-5.2.5.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions client/rest/licenses/httpcore5-5.3.2.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
35d387301d4a719972b15fbe863020da5f913c22
1 change: 0 additions & 1 deletion client/rest/licenses/httpcore5-h2-5.2.5.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions client/rest/licenses/httpcore5-h2-5.3.2.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d908a946e9161511accdc739e443b1e0b0cbba82
1 change: 0 additions & 1 deletion client/rest/licenses/httpcore5-reactive-5.2.5.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions client/rest/licenses/httpcore5-reactive-5.3.2.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9ee35ef1d3e40855695fc87ad2e31192d85c1e88
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.message.BasicHeader;
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.util.Timeout;

import java.io.IOException;
Expand Down Expand Up @@ -143,6 +144,12 @@ public void testBuild() throws IOException {
builder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
IOReactorConfig.Builder iOReactorConfig = IOReactorConfig.custom();
iOReactorConfig.setTcpKeepCount(randomIntBetween(4, 10));
iOReactorConfig.setTcpKeepInterval(randomIntBetween(5, 10));
iOReactorConfig.setTcpKeepIdle(randomIntBetween(100, 200));
iOReactorConfig.setIoThreadCount(2);
httpClientBuilder.setIOReactorConfig(iOReactorConfig.build());
return httpClientBuilder;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ public void testHeaders() throws Exception {
if (method.equals("HEAD") == false) {
standardHeaders.add("Content-length");
}
if (method.equals("HEAD") == true || method.equals("GET") == true || method.equals("OPTIONS") == true) {
standardHeaders.add("Upgrade");
}

final Header[] requestHeaders = RestClientTestUtil.randomHeaders(getRandom(), "Header");
final int statusCode = randomStatusCode(getRandom());
Request request = new Request(method, "/" + statusCode);
Expand All @@ -400,11 +404,15 @@ public void testHeaders() throws Exception {
assertEquals(method, esResponse.getRequestLine().getMethod());
assertEquals(statusCode, esResponse.getStatusLine().getStatusCode());
assertEquals(pathPrefix + "/" + statusCode, esResponse.getRequestLine().getUri());

assertHeaders(defaultHeaders, requestHeaders, esResponse.getHeaders(), standardHeaders);
final Set<String> removedHeaders = new HashSet<>();
for (final Header responseHeader : esResponse.getHeaders()) {
String name = responseHeader.getName();
if (name.startsWith("Header") == false) {
// Some headers could be returned multiple times in response, like Connection fe.
if (name.startsWith("Header") == false && removedHeaders.contains(name) == false) {
assertTrue("unknown header was returned " + name, standardHeaders.remove(name));
removedHeaders.add(name);
}
}
assertTrue("some expected standard headers weren't returned: " + standardHeaders, standardHeaders.isEmpty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,24 @@ public HttpAsyncClientBuilder customizeHttpClient(
});
//end::rest-client-config-threads
}
{
//tag::rest-client-config-tcpKeepIdle/tcpKeepInterval/tcpKeepCount
RestClientBuilder builder = RestClient.builder(
new HttpHost("localhost", 9200))
.setHttpClientConfigCallback(new HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(
HttpAsyncClientBuilder httpClientBuilder) {
return httpClientBuilder.setIOReactorConfig(
IOReactorConfig.custom()
.setTcpKeepIdle(200)
.setTcpKeepInterval(10)
.setTcpKeepCount(10)
.build());
}
});
//end::rest-client-config-tcpKeepIdle/tcpKeepInterval/tcpKeepCount
}
{
//tag::rest-client-config-basic-auth
final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
Expand Down
1 change: 0 additions & 1 deletion client/sniffer/licenses/httpclient5-5.3.1.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions client/sniffer/licenses/httpclient5-5.4.1.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ce913081e592ee8eeee35c4e577d7dce13cba7a4
1 change: 0 additions & 1 deletion client/sniffer/licenses/httpcore5-5.2.5.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions client/sniffer/licenses/httpcore5-5.3.2.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
35d387301d4a719972b15fbe863020da5f913c22
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ joda = "2.12.7"
roaringbitmap = "1.3.0"

# project reactor
reactor_netty = "1.1.23"
reactor_netty = "1.1.26"
reactor = "3.5.20"

# client dependencies
httpclient5 = "5.3.1"
httpcore5 = "5.2.5"
httpclient5 = "5.4.1"
httpcore5 = "5.3.2"
httpclient = "4.5.14"
httpcore = "4.4.16"
httpasyncclient = "4.1.5"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
05a8c6004161a4c1a9c0639b05387baab6efaa32

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
41682e517e2808fc469d6b2b85fea48d0a7fe73b

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
05a8c6004161a4c1a9c0639b05387baab6efaa32

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
41682e517e2808fc469d6b2b85fea48d0a7fe73b
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.opensearch.common.util.concurrent.OpenSearchExecutors;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.common.util.net.NetUtils;
import org.opensearch.core.common.unit.ByteSizeUnit;
import org.opensearch.core.common.unit.ByteSizeValue;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.http.AbstractHttpServerTransport;
Expand Down Expand Up @@ -87,6 +88,19 @@ public class ReactorNetty4HttpServerTransport extends AbstractHttpServerTranspor
private static final String SETTING_KEY_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS = "http.netty.max_composite_buffer_components";
private static final ByteSizeValue MTU = new ByteSizeValue(Long.parseLong(System.getProperty("opensearch.net.mtu", "1500")));

/**
* Configure the maximum length of the content of the HTTP/2.0 clear-text upgrade request.
* By default the server will reject an upgrade request with non-empty content,
* because the upgrade request is most likely a GET request. If the client sends
* a non-GET upgrade request, {@link #h2cMaxContentLength} specifies the maximum
* length of the content of the upgrade request.
*/
public static final Setting<ByteSizeValue> SETTING_H2C_MAX_CONTENT_LENGTH = Setting.byteSizeSetting(
"h2c.max_content_length",
new ByteSizeValue(65536, ByteSizeUnit.KB),
Property.NodeScope
);

/**
* The number of Reactor Netty HTTP workers
*/
Expand Down Expand Up @@ -133,6 +147,7 @@ public class ReactorNetty4HttpServerTransport extends AbstractHttpServerTranspor
private final ByteSizeValue maxInitialLineLength;
private final ByteSizeValue maxHeaderSize;
private final ByteSizeValue maxChunkSize;
private final ByteSizeValue h2cMaxContentLength;
private final SecureHttpTransportSettingsProvider secureHttpTransportSettingsProvider;
private volatile SharedGroupFactory.SharedGroup sharedGroup;
private volatile DisposableServer disposableServer;
Expand Down Expand Up @@ -208,6 +223,7 @@ public ReactorNetty4HttpServerTransport(
this.maxCompositeBufferComponents = SETTING_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS.get(settings);
this.maxChunkSize = SETTING_HTTP_MAX_CHUNK_SIZE.get(settings);
this.maxHeaderSize = SETTING_HTTP_MAX_HEADER_SIZE.get(settings);
this.h2cMaxContentLength = SETTING_H2C_MAX_CONTENT_LENGTH.get(settings);
this.maxInitialLineLength = SETTING_HTTP_MAX_INITIAL_LINE_LENGTH.get(settings);
this.secureHttpTransportSettingsProvider = secureHttpTransportSettingsProvider;
}
Expand All @@ -228,6 +244,7 @@ protected HttpServerChannel bind(InetSocketAddress socketAddress) throws Excepti
.compress(true)
.httpRequestDecoder(
spec -> spec.maxChunkSize(maxChunkSize.bytesAsInt())
.h2cMaxContentLength(h2cMaxContentLength.bytesAsInt())
.maxHeaderSize(maxHeaderSize.bytesAsInt())
.maxInitialLineLength(maxInitialLineLength.bytesAsInt())
.allowPartialChunks(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ReactorNetty4Plugin() {}
*/
@Override
public List<Setting<?>> getSettings() {
return Arrays.asList(/* no setting registered since we're picking the onces from Netty 4 transport */);
return Arrays.asList(ReactorNetty4HttpServerTransport.SETTING_H2C_MAX_CONTENT_LENGTH);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ grant codeBase "${codebase.httpcore5}" {

grant codeBase "${codebase.httpclient5}" {
// httpclient5 makes socket connections for rest tests
permission java.net.SocketPermission "*", "connect";
permission java.net.SocketPermission "*", "connect,resolve";
};

grant codeBase "${codebase.httpcore-nio}" {
Expand Down

0 comments on commit fa4595c

Please sign in to comment.