-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(sdk-core): add Async HTTP-client warm-up to SdkWarmUp.prime() for CRaC priming #7092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joviegas
merged 12 commits into
feature/master/crac_auto_priming_support
from
joviegas/crac_warmup_orchestration_partB
Jun 30, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
adaf1a0
feat(sdk-core): add sync HTTP-client warm-up to SdkWarmUp.prime() for…
joviegas 82c723b
Updated tests
joviegas 311aff8
restructure test and comments
joviegas 2f5b864
Fixed checkstyle issues
joviegas 072736d
Handled PR comments
joviegas 9d6a9d5
Update test for blank input
joviegas 131e157
Update before and after conditions in test
joviegas af69a6a
Merge branch 'feature/master/crac_auto_priming_support' into joviegas…
joviegas 838bf52
Merge branch 'feature/master/crac_auto_priming_support' into joviegas…
joviegas 32a2c27
feat(sdk-core): add Async HTTP-client warm-up to SdkWarmUp.prime() fo…
joviegas fcb71e9
feat(sdk-core): add Async HTTP-client warm-up to SdkWarmUp.prime() fo…
joviegas a33ef0c
Handled PR comments
joviegas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
...src/main/java/software/amazon/awssdk/core/internal/http/loader/AsyncHttpClientWarmer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.core.internal.http.loader; | ||
|
|
||
| import java.net.URI; | ||
| import java.nio.ByteBuffer; | ||
| import java.util.Collections; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.function.Supplier; | ||
| import org.reactivestreams.Publisher; | ||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
| import software.amazon.awssdk.annotations.SdkTestInternalApi; | ||
| import software.amazon.awssdk.core.internal.crac.RegionEndpointResolver; | ||
| import software.amazon.awssdk.core.internal.crac.WarmUpDiscovery; | ||
| import software.amazon.awssdk.core.internal.http.async.SimpleHttpContentPublisher; | ||
| import software.amazon.awssdk.http.SdkHttpFullRequest; | ||
| import software.amazon.awssdk.http.SdkHttpMethod; | ||
| import software.amazon.awssdk.http.SdkHttpResponse; | ||
| import software.amazon.awssdk.http.async.AsyncExecuteRequest; | ||
| import software.amazon.awssdk.http.async.SdkAsyncHttpClient; | ||
| import software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler; | ||
| import software.amazon.awssdk.http.async.SdkAsyncHttpService; | ||
| import software.amazon.awssdk.http.async.SimpleSubscriber; | ||
| import software.amazon.awssdk.utils.AttributeMap; | ||
| import software.amazon.awssdk.utils.IoUtils; | ||
| import software.amazon.awssdk.utils.Logger; | ||
|
|
||
| /** | ||
| * Warms every async {@link SdkAsyncHttpService} on the classpath for CRaC priming: builds each client and sends a best-effort | ||
| * {@code GET} to the resolved STS endpoint, draining the reactive response body, so the HTTP/DNS/TLS/cert-chain code is | ||
| * JIT-compiled into the snapshot. | ||
| */ | ||
| @SdkInternalApi | ||
| public final class AsyncHttpClientWarmer implements HttpClientWarmer { | ||
|
|
||
| private static final Logger log = Logger.loggerFor(AsyncHttpClientWarmer.class); | ||
|
|
||
| private static final long WARM_UP_TIMEOUT_SECONDS = 5; | ||
|
|
||
| private final Iterable<SdkAsyncHttpService> services; | ||
| private final Supplier<URI> endpointProvider; | ||
|
|
||
| @SdkTestInternalApi | ||
| AsyncHttpClientWarmer(Iterable<SdkAsyncHttpService> services, Supplier<URI> endpointProvider) { | ||
| this.services = services; | ||
| this.endpointProvider = endpointProvider; | ||
| } | ||
|
|
||
| /** | ||
| * Warms a single {@code service} against {@code endpointProvider}. | ||
| */ | ||
| @SdkTestInternalApi | ||
| public static AsyncHttpClientWarmer forService(Supplier<URI> endpointProvider, SdkAsyncHttpService service) { | ||
| return new AsyncHttpClientWarmer(Collections.singletonList(service), endpointProvider); | ||
| } | ||
|
|
||
| public static AsyncHttpClientWarmer create() { | ||
| return new AsyncHttpClientWarmer(discoverServices(), () -> RegionEndpointResolver.create().endpoint()); | ||
| } | ||
|
|
||
| /** | ||
| * Like {@link #create()}, but warms against {@code endpointProvider}. | ||
| */ | ||
| @SdkTestInternalApi | ||
| public static AsyncHttpClientWarmer create(Supplier<URI> endpointProvider) { | ||
| return new AsyncHttpClientWarmer(discoverServices(), endpointProvider); | ||
| } | ||
|
|
||
| private static Iterable<SdkAsyncHttpService> discoverServices() { | ||
| return () -> SdkServiceLoader.INSTANCE.loadServices(SdkAsyncHttpService.class); | ||
| } | ||
|
|
||
| @Override | ||
| public void warmAll() { | ||
| URI endpoint = endpointProvider.get(); | ||
| WarmUpDiscovery.forEachDiscovered(services.iterator(), service -> { | ||
| SdkAsyncHttpClient client = service.createAsyncHttpClientFactory().buildWithDefaults(AttributeMap.empty()); | ||
| warmClient(client, endpoint); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Sends the warm-up {@code GET} to {@code endpoint}, drains the response body, and closes the client. Best-effort: any | ||
| * failure or timeout is logged and swallowed. We block on the execute future (bounded) because the bundled async | ||
| * clients complete it only after the body is drained, so its completion implies the full path was exercised. | ||
| */ | ||
| private void warmClient(SdkAsyncHttpClient client, URI endpoint) { | ||
| try { | ||
| SdkHttpFullRequest httpRequest = SdkHttpFullRequest.builder() | ||
| .method(SdkHttpMethod.GET) | ||
| .uri(endpoint) | ||
| .build(); | ||
| AsyncExecuteRequest request = AsyncExecuteRequest.builder() | ||
| .request(httpRequest) | ||
| .requestContentPublisher(new SimpleHttpContentPublisher(httpRequest)) | ||
| .responseHandler(new WarmUpResponseHandler()) | ||
| .build(); | ||
| client.execute(request).get(WARM_UP_TIMEOUT_SECONDS, TimeUnit.SECONDS); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| log.debug(() -> "Async HTTP client warm-up call was interrupted (ignored).", e); | ||
| } catch (Exception e) { | ||
| // Includes ExecutionException for a failed warm-up request; best-effort, so swallow. | ||
| log.debug(() -> "Async HTTP client warm-up call failed (ignored).", e); | ||
| } finally { | ||
| IoUtils.closeQuietlyV2(client, log); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Subscribes a {@link SimpleSubscriber} to drain and discard the response body, exercising the body-read/TLS path. | ||
| * The subscription is required: some clients complete the execute future only once the body is consumed. | ||
| */ | ||
| private static final class WarmUpResponseHandler implements SdkAsyncHttpResponseHandler { | ||
|
|
||
| @Override | ||
| public void onHeaders(SdkHttpResponse headers) { | ||
| // No-op: warm-up only needs the body drained, not the headers. | ||
| } | ||
|
|
||
| @Override | ||
| public void onStream(Publisher<ByteBuffer> stream) { | ||
| stream.subscribe(new SimpleSubscriber(byteBuffer -> { | ||
| // Discard the bytes; warm-up only needs the path exercised. | ||
| })); | ||
| } | ||
|
|
||
| @Override | ||
| public void onError(Throwable error) { | ||
| // No-op: failure is surfaced via the execute future, which the caller blocks on. | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.