-
Notifications
You must be signed in to change notification settings - Fork 951
Add perMethod
, perHost
, perPath
and builder to RetryConfigMapping
#6243
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
Open
schiemon
wants to merge
4
commits into
line:main
Choose a base branch
from
schiemon:6242-retry-config-mapping-per-method-path-and-host-basis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b63e552
feat: add perMethod, perHost, perPath to RetryConfigMapping
schiemon 087b025
test: add tests for RetryConfigMapping
schiemon bc52c44
refactor: revert deprecation of `RetryConfigMapping.of`
schiemon cb5fe28
feat: add `RetryConfig.noRetry()` and add tests
schiemon 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
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
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
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
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
core/src/main/java/com/linecorp/armeria/client/retry/RetryConfigMappingBuilder.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 2025 LY Corporation | ||
* | ||
* LY Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License 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 com.linecorp.armeria.client.retry; | ||
|
||
import com.linecorp.armeria.common.Response; | ||
|
||
public final class RetryConfigMappingBuilder<T extends Response> { | ||
private boolean perHost; | ||
private boolean perMethod; | ||
private boolean perPath; | ||
|
||
public RetryConfigMappingBuilder<T> perHost() { | ||
perHost = true; | ||
return this; | ||
} | ||
|
||
public RetryConfigMappingBuilder<T> perMethod() { | ||
perMethod = true; | ||
return this; | ||
} | ||
|
||
public RetryConfigMappingBuilder<T> perPath() { | ||
perPath = true; | ||
return this; | ||
} | ||
|
||
private boolean validateMappingKeys() { | ||
return perHost || perMethod || perPath; | ||
} | ||
|
||
public RetryConfigMapping<T> build(RetryConfigFactory<T> retryConfigFactory) { | ||
if (!validateMappingKeys()) { | ||
throw new IllegalStateException( | ||
"A RetryConfigMapping created by this builder must be per host, method and/or path"); | ||
} | ||
|
||
return new KeyedRetryConfigMapping<>( | ||
perHost, perMethod, perPath, retryConfigFactory | ||
); | ||
} | ||
} |
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
51 changes: 0 additions & 51 deletions
51
...n/java/com/linecorp/armeria/internal/common/circuitbreaker/CircuitBreakerMappingUtil.java
This file was deleted.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the initiative. I agree intuitively, it makes sense that retry and circuitbreaker share similar APIs.
Having said this, I do think retry is a little different from circuitbreaker in the sense that
CircuitBreaker
share a common mutable configuration across requests. For this reason, amapping
structure is used to cache theCircuitBreaker
s used per host/method/path.On the other hand,
RetryConfig
is an immutable object which decides how each request will be retried (in case there is a retry). Hence, there is no real reason we should be caching the returnedRetryConfig
s. It may be worth checking the discussion at #3145 as well.I do think there is value in pre-parsing method/host/path parameters so that users don't have to extract each value from the
ctx
though.e.g.
I'm not sure of the usefulness of the
builder()
orper*()
apis though since users can simply choose to ignore certain fields of theRetryConfigFactory
anyways.e.g. users can simply choose not to use the path
Let me know what you think.
cc. other maintainers @line/dx
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your review @jrhee17.
Ah, so you're effectively saying that
RetryConfigMapping
doesn't necessarily need akeyFactory
inRetryConfigMapping.of
:and that we could offer an "uncached" version like:
Since this API is not currently offered, and because RetryConfigMapping mentions caching twice, I assumed there was a performance reason for caching — for example, reducing GC pressure or handling expensive factory methods.
If it’s just for ergonomics, I like your suggestion as it avoids specifying the
keyFactory
. However, given that we already cache inKeyedRetryConfigMapping
, and considering that we haveCircuitBreakerMapping
alongside it, I would lean towards using a per*-style approach.I'm also happy to hear input from the other maintainers.