-
Notifications
You must be signed in to change notification settings - Fork 1k
Add overloaded menthod for SdkWarmUp.prime overloaded to accept speci… #7130
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 4 commits into
feature/master/crac_auto_priming_support
from
joviegas/overload-prime
Jul 13, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5831ecd
Add overloaded menthod for SdkWarmUp.prime overloaded to accept speci…
joviegas ccf1b3a
Updated idempotency testing
joviegas 13d3a7c
Handled cases when one warmUp provider fails in overloaded method ,so…
joviegas 34259a2
Handle Review 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
55 changes: 55 additions & 0 deletions
55
...dk-core/src/main/java/software/amazon/awssdk/core/internal/crac/PrimedClientRegistry.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,55 @@ | ||
| /* | ||
| * 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.crac; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
| import software.amazon.awssdk.annotations.ThreadSafe; | ||
|
|
||
| /** | ||
| * Tracks which service clients {@code SdkWarmUp.prime(Class...)} has already warmed, so each is warmed at most once per | ||
| * JVM. State is per-instance, so it is unit-testable with fresh instances; production uses a single long-lived instance. | ||
| */ | ||
| @ThreadSafe | ||
| @SdkInternalApi | ||
| public final class PrimedClientRegistry { | ||
|
|
||
| private final Set<String> primed = ConcurrentHashMap.newKeySet(); | ||
|
|
||
| /** | ||
| * Returns the not-yet-primed subset of {@code clientClassNames}, in encounter order, ignoring nulls. Warm the | ||
| * returned names, then pass them to {@link #markPrimed(Collection)}. | ||
| */ | ||
| public Set<String> selectUnprimed(Collection<String> clientClassNames) { | ||
| Set<String> unprimed = new LinkedHashSet<>(); | ||
| for (String name : clientClassNames) { | ||
| if (name != null && !primed.contains(name)) { | ||
| unprimed.add(name); | ||
| } | ||
| } | ||
| return unprimed; | ||
| } | ||
|
|
||
| /** | ||
| * Records the given names as primed. Call only after warming completes, so a failed run is retried by a later call. | ||
| */ | ||
| public void markPrimed(Collection<String> clientClassNames) { | ||
| primed.addAll(clientClassNames); | ||
| } | ||
| } |
106 changes: 106 additions & 0 deletions
106
...k-core/src/main/java/software/amazon/awssdk/core/internal/crac/TargetedWarmUpInvoker.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,106 @@ | ||
| /* | ||
| * 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.crac; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.EnumSet; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
| import software.amazon.awssdk.annotations.SdkTestInternalApi; | ||
| import software.amazon.awssdk.core.ClientType; | ||
| import software.amazon.awssdk.core.crac.SdkWarmUpProvider; | ||
| import software.amazon.awssdk.utils.Logger; | ||
|
|
||
| /** | ||
| * Warms only the service clients named by {@code SdkWarmUp.prime(Class...)}. Matches each requested client class name | ||
| * against the discovered {@link SdkWarmUpProvider}s' sync and async class names, then warms the matched client type only. | ||
| */ | ||
| @SdkInternalApi | ||
| public final class TargetedWarmUpInvoker { | ||
|
|
||
| private static final Logger log = Logger.loggerFor(TargetedWarmUpInvoker.class); | ||
|
|
||
| private final WarmUpServiceLoader serviceLoader; | ||
|
|
||
| @SdkTestInternalApi | ||
| TargetedWarmUpInvoker(WarmUpServiceLoader serviceLoader) { | ||
| this.serviceLoader = serviceLoader; | ||
| } | ||
|
|
||
| public static TargetedWarmUpInvoker create() { | ||
| return new TargetedWarmUpInvoker(WarmUpServiceLoader.INSTANCE); | ||
| } | ||
|
|
||
| /** | ||
| * Warms the provider client type matching each requested client class name. An unmatched name is logged | ||
| * at warn and skipped, and a provider that fails does not stop the others. | ||
| * | ||
| * @param requestedClassNames the fully qualified sync or async client class names to warm. | ||
| * @return the matched client types and the names that warmed successfully. | ||
| */ | ||
| public TargetedWarmUpResult invoke(Collection<String> requestedClassNames) { | ||
| Set<ClientType> matchedClientTypes = EnumSet.noneOf(ClientType.class); | ||
| Set<String> warmedClientNames = new LinkedHashSet<>(); | ||
| if (requestedClassNames.isEmpty()) { | ||
| return new TargetedWarmUpResult(matchedClientTypes, warmedClientNames); | ||
| } | ||
|
|
||
| List<SdkWarmUpProvider> providers = loadProviders(); | ||
| for (String requested : requestedClassNames) { | ||
| boolean warmFailed = false; | ||
| Set<ClientType> matched = EnumSet.noneOf(ClientType.class); | ||
| for (SdkWarmUpProvider provider : providers) { | ||
| ClientType clientType = clientTypeFor(requested, provider); | ||
| if (clientType == null) { | ||
| continue; | ||
| } | ||
| matched.add(clientType); | ||
| try { | ||
| provider.warmUpClient(clientType); | ||
| } catch (RuntimeException | LinkageError e) { | ||
| warmFailed = true; | ||
| log.warn(() -> "Warm-up failed for " + provider.getClass().getName() + " and was skipped.", e); | ||
| } | ||
| } | ||
| if (matched.isEmpty()) { | ||
| log.warn(() -> "No warm-up provider matched client class " + requested + "; skipping."); | ||
| } else if (!warmFailed) { | ||
| warmedClientNames.add(requested); | ||
| } | ||
| matchedClientTypes.addAll(matched); | ||
| } | ||
| return new TargetedWarmUpResult(matchedClientTypes, warmedClientNames); | ||
| } | ||
|
|
||
| private ClientType clientTypeFor(String requested, SdkWarmUpProvider provider) { | ||
| if (requested.equals(provider.syncClientClassName())) { | ||
| return ClientType.SYNC; | ||
| } | ||
| if (requested.equals(provider.asyncClientClassName())) { | ||
| return ClientType.ASYNC; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| private List<SdkWarmUpProvider> loadProviders() { | ||
| List<SdkWarmUpProvider> providers = new ArrayList<>(); | ||
| WarmUpDiscovery.forEachDiscovered(serviceLoader.loadProviders(), providers::add); | ||
| return providers; | ||
| } | ||
| } |
78 changes: 78 additions & 0 deletions
78
...dk-core/src/main/java/software/amazon/awssdk/core/internal/crac/TargetedWarmUpResult.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,78 @@ | ||
| /* | ||
| * 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.crac; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Set; | ||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
| import software.amazon.awssdk.core.ClientType; | ||
| import software.amazon.awssdk.utils.ToString; | ||
|
|
||
| /** | ||
| * Outcome of a {@link TargetedWarmUpInvoker} run: the client types that matched and the client names that warmed | ||
| * successfully. | ||
| */ | ||
| @SdkInternalApi | ||
| public final class TargetedWarmUpResult { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is passed between layers it probably should implement equals/hashcode/toString
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done also added EqualsVerifier test |
||
|
|
||
| private final Set<ClientType> matchedClientTypes; | ||
| private final Set<String> warmedClientNames; | ||
|
|
||
| TargetedWarmUpResult(Set<ClientType> matchedClientTypes, Set<String> warmedClientNames) { | ||
| this.matchedClientTypes = Collections.unmodifiableSet(matchedClientTypes); | ||
| this.warmedClientNames = Collections.unmodifiableSet(warmedClientNames); | ||
| } | ||
|
|
||
| public Set<ClientType> matchedClientTypes() { | ||
| return matchedClientTypes; | ||
| } | ||
|
|
||
| public Set<String> warmedClientNames() { | ||
| return warmedClientNames; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
|
|
||
| TargetedWarmUpResult that = (TargetedWarmUpResult) o; | ||
|
|
||
| if (!matchedClientTypes.equals(that.matchedClientTypes)) { | ||
| return false; | ||
| } | ||
| return warmedClientNames.equals(that.warmedClientNames); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| int result = matchedClientTypes.hashCode(); | ||
| result = 31 * result + warmedClientNames.hashCode(); | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return ToString.builder("TargetedWarmUpResult") | ||
| .add("matchedClientTypes", matchedClientTypes) | ||
| .add("warmedClientNames", warmedClientNames) | ||
| .build(); | ||
| } | ||
| } | ||
24 changes: 24 additions & 0 deletions
24
core/sdk-core/src/test/java/software/amazon/awssdk/core/crac/RegisteredAsyncClient.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,24 @@ | ||
| /* | ||
| * 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.crac; | ||
|
|
||
| import software.amazon.awssdk.core.SdkClient; | ||
|
|
||
| /** | ||
| * Test-only client whose fully qualified name matches {@link RegisteredWarmUpProvider#asyncClientClassName()}. | ||
| */ | ||
| public interface RegisteredAsyncClient extends SdkClient { | ||
| } |
25 changes: 25 additions & 0 deletions
25
core/sdk-core/src/test/java/software/amazon/awssdk/core/crac/RegisteredSyncClient.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,25 @@ | ||
| /* | ||
| * 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.crac; | ||
|
|
||
| import software.amazon.awssdk.core.SdkClient; | ||
|
|
||
| /** | ||
| * Test-only client whose fully qualified name matches {@link RegisteredWarmUpProvider#syncClientClassName()}, so | ||
| * {@code SdkWarmUp.prime(RegisteredSyncClient.class)} matches that provider's sync client type. | ||
| */ | ||
| public interface RegisteredSyncClient extends SdkClient { | ||
| } |
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.