-
Notifications
You must be signed in to change notification settings - Fork 16
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
instrument retrying channels scheduled executor service #485
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 |
---|---|---|
|
@@ -33,9 +33,13 @@ | |
import com.palantir.logsafe.exceptions.SafeRuntimeException; | ||
import com.palantir.tracing.DetachedSpan; | ||
import com.palantir.tracing.Tracers; | ||
import com.palantir.tritium.metrics.MetricRegistries; | ||
import com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry; | ||
import com.palantir.tritium.metrics.registry.TaggedMetricRegistry; | ||
import java.net.SocketTimeoutException; | ||
import java.time.Duration; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.DoubleSupplier; | ||
|
@@ -49,20 +53,19 @@ | |
final class RetryingChannel implements Channel { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(RetryingChannel.class); | ||
private static final String SCHEDULER_NAME = "dialogue-RetryingChannel-scheduler"; | ||
|
||
/* | ||
* Shared single thread executor is reused between all retrying channels. If it becomes oversaturated | ||
* we may wait longer than expected before resuming requests, but this is an | ||
* edge case where services are already operating in a degraded state and we should not | ||
* spam servers. | ||
*/ | ||
static final Supplier<ListeningScheduledExecutorService> sharedScheduler = | ||
Suppliers.memoize(() -> MoreExecutors.listeningDecorator(Tracers.wrap( | ||
"dialogue-RetryingChannel-scheduler", | ||
Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder() | ||
.setNameFormat("dialogue-RetryingChannel-scheduler-%d") | ||
.setDaemon(false) | ||
.build())))); | ||
static final Supplier<ScheduledExecutorService> sharedScheduler = | ||
Suppliers.memoize(() -> Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder() | ||
.setNameFormat(SCHEDULER_NAME + "-%d") | ||
.setDaemon(false) | ||
.build())); | ||
|
||
private final ListeningScheduledExecutorService scheduler; | ||
private final Channel delegate; | ||
|
@@ -80,6 +83,7 @@ final class RetryingChannel implements Channel { | |
ClientConfiguration.RetryOnTimeout retryOnTimeout) { | ||
this( | ||
delegate, | ||
new DefaultTaggedMetricRegistry(), | ||
maxRetries, | ||
backoffSlotSize, | ||
serverQoS, | ||
|
@@ -90,18 +94,19 @@ final class RetryingChannel implements Channel { | |
|
||
RetryingChannel( | ||
Channel delegate, | ||
TaggedMetricRegistry metrics, | ||
int maxRetries, | ||
Duration backoffSlotSize, | ||
ClientConfiguration.ServerQoS serverQoS, | ||
ClientConfiguration.RetryOnTimeout retryOnTimeout, | ||
ListeningScheduledExecutorService scheduler, | ||
ScheduledExecutorService scheduler, | ||
DoubleSupplier jitter) { | ||
this.delegate = delegate; | ||
this.maxRetries = maxRetries; | ||
this.backoffSlotSize = backoffSlotSize; | ||
this.serverQoS = serverQoS; | ||
this.retryOnTimeout = retryOnTimeout; | ||
this.scheduler = scheduler; | ||
this.scheduler = instrument(scheduler, metrics); | ||
this.jitter = jitter; | ||
} | ||
|
||
|
@@ -245,4 +250,10 @@ private static boolean shouldPropagateQos(ClientConfiguration.ServerQoS serverQo | |
throw new SafeIllegalStateException( | ||
"Encountered unknown propagate QoS configuration", SafeArg.of("serverQoS", serverQoS)); | ||
} | ||
|
||
private static ListeningScheduledExecutorService instrument( | ||
ScheduledExecutorService delegate, TaggedMetricRegistry metrics) { | ||
return MoreExecutors.listeningDecorator( | ||
Tracers.wrap(SCHEDULER_NAME, MetricRegistries.instrument(metrics, delegate, SCHEDULER_NAME))); | ||
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. nice |
||
} | ||
} |
This file contains 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 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
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.
I think we need to add this to the constructor and pass the registry from our ClientConfiguration
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.
Yes we do do that, this constructor is only visible for testing. Let me make that more clear
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.
oh doh, I misread, sorry!