Skip to content

refactor retry state impl API#6132

Merged
mattklein123 merged 6 commits intoenvoyproxy:masterfrom
mpuncel:mpuncel/refactor-retry-state-impl
Mar 1, 2019
Merged

refactor retry state impl API#6132
mattklein123 merged 6 commits intoenvoyproxy:masterfrom
mpuncel:mpuncel/refactor-retry-state-impl

Conversation

@mpuncel
Copy link
Copy Markdown
Contributor

@mpuncel mpuncel commented Feb 28, 2019

Previously there was a single shouldRetry() method which takes a HTTP
header map and a stream reset reason and asserts that only one is set.
In anticipation of adding a new retry case for #5841, this commit breaks
apart this function into shouldRetryHeaders and shouldRetryReset. This
leads to fewer asserts and more intentional code.

Signed-off-by: Michael Puncel mpuncel@squareup.com

Description: Refactor public API for RetryState.
Risk Level: Low
Testing: unit tests
Docs Changes: N/A
Release Notes: N/A
This was done in anticipation of #5841 which will be adding a new retry condition (per try timeout) that does not result from a stream reset or response headers

Previously there was a single shouldRetry() method which takes a HTTP
header map and a stream reset reason and asserts that only one is set.
In anticipation of adding a new retry case for envoyproxy#5841, this commit breaks
apart this function into shouldRetryHeaders and shouldRetryReset. This
leads to fewer asserts and more intentional code.

Signed-off-by: Michael Puncel <mpuncel@squareup.com>
Signed-off-by: Michael Puncel <mpuncel@squareup.com>
@snowp snowp self-assigned this Feb 28, 2019
Copy link
Copy Markdown
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this seems like an improvement

Comment thread include/envoy/router/router.h Outdated
DoRetryCallback callback) PURE;

/**
* Determine whether a request should be retried after a reset based on the reason for the rest.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"for the rest"?


RetryStatus RetryStateImpl::shouldRetryHeaders(const Http::HeaderMap* response_headers,
DoRetryCallback callback) {
ASSERT(response_headers != nullptr);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of asserting that this is true, you can change response_headers to be passed by const ref which ensures that it's not null


if (callback_ && !wouldRetry(response_headers, reset_reason)) {
RetryStatus RetryStateImpl::shouldRetry(RetryPredicate would_retry, DoRetryCallback callback) {
if (callback_ && !would_retry()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not your code but could you add a comment explaining why this makes sense? Took me a minute

Comment thread source/common/router/retry_state_impl.h Outdated
Signed-off-by: Michael Puncel <mpuncel@squareup.com>
Signed-off-by: Michael Puncel <mpuncel@squareup.com>
snowp
snowp previously approved these changes Feb 28, 2019
Copy link
Copy Markdown
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this LGTM

@mattklein123 mattklein123 self-assigned this Mar 1, 2019
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very nice, 1 question / small comment.

/wait


RetryStatus retry_status =
retry_state_->shouldRetry(nullptr, reset_reason, [this]() -> void { doRetry(); });
retry_state_->shouldRetryReset(reset_reason.value(), [this]() -> void { doRetry(); });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are we guaranteed that this option as a value()? It's not clear to me from the code flow. Can you add a comment or potentially look at changing the logic if always has a value?

Also, while you are here, can you change the call signature to pass the StreamResetReason by value and not reference? It will be faster (my own badly written code most likely).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think I don't need an optional anymore, will do that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm there is a place where it might not have a value (onResponseTimeout()). I actually take care of that case and remove the optional in #6142. For this PR i'll put a comment explaining why it will always have a value

Signed-off-by: Michael Puncel <mpuncel@squareup.com>
Signed-off-by: Michael Puncel <mpuncel@squareup.com>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@mattklein123 mattklein123 merged commit cd7d479 into envoyproxy:master Mar 1, 2019
fredlas pushed a commit to fredlas/envoy that referenced this pull request Mar 5, 2019
Previously there was a single shouldRetry() method which takes a HTTP
header map and a stream reset reason and asserts that only one is set.
In anticipation of adding a new retry case for envoyproxy#5841, this commit breaks
apart this function into shouldRetryHeaders and shouldRetryReset. This
leads to fewer asserts and more intentional code.

Signed-off-by: Michael Puncel <mpuncel@squareup.com>
Signed-off-by: Fred Douglas <fredlas@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants