drain manager: Refactor DrainManagerImpl with simulated time#11138
Conversation
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
|
/retest |
|
🔨 rebuilding |
Signed-off-by: Auni Ahsan <auni@google.com>
|
/wait |
Signed-off-by: Auni Ahsan <auni@google.com>
|
Sorry for the format presubmit fails...I thought I had it setup to automatically lint before pushing, trying to fix that. |
Signed-off-by: Auni Ahsan <auni@google.com>
|
/wait |
Signed-off-by: Auni Ahsan <auni@google.com>
|
/retest |
|
🐴 hold your horses - no failures detected, yet. |
Signed-off-by: Auni Ahsan <auni@google.com>
|
I don't understand why these presubmits are failing...unable to reproduce yet, and my local |
Signed-off-by: Auni Ahsan <auni@google.com>
jmarantz
left a comment
There was a problem hiding this comment.
basically looks good modulo one last naming nit.
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
|
Fix the naming nit, is this good to go? |
|
@envoyproxy/senior-maintainers |
mattklein123
left a comment
There was a problem hiding this comment.
Nice, thanks. LGTM with one comment.
/wait
Signed-off-by: Auni Ahsan <auni@google.com>
|
(I'm waiting to resolve #11240 before introducing more changes.) |
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
|
Fixed the ternary, added an expected_delay to the mock expect, and put up #11345 which addresses the tangential race condition. Hope this is good to go! |
Signed-off-by: Auni Ahsan <auni@google.com>
|
/retest |
|
🤷♀️ nothing to rebuild. |
| // P(return true) = elapsed time / drain timeout | ||
| const auto remaining_time = | ||
| std::chrono::duration_cast<std::chrono::seconds>(drain_deadline_ - current_time); | ||
| const auto elapsed_time = server_.options().drainTime() - remaining_time; |
There was a problem hiding this comment.
is there a guarantee that drainTime() >= current_time ? Or should we do a compare first? I don't totally understand the surrounding draining architecture, but it looks like drainClose() can be called by something not controlled by the timer, so current_time_ may just be later. In that case maybe we should skip the subtraction underflow and compare to random and just return true?
There was a problem hiding this comment.
Assuming you mean drain_deadline_ (the computed deadline time point) and not drainTime() (the server configuration)? This case is tested for at drain_manager_impl_test.cc:83. If current_time > drain_deadline, the probability of drain close is 100%,
There was a problem hiding this comment.
sorry I meant checking server_.options().drainTime() >= remaining_time
or is that guaranteed to be true due to the wait remaining_time is calculated?
There was a problem hiding this comment.
(psuedo variables)
drain_deadline = drain_timeout + previous_time
remaining_time = drain_deadline - current_time
remaining_time = drain_timeout + previous_time - current_time
current_time >= previous time, therefore remaining_time <= drain_timeout
Math checks out to me!
There was a problem hiding this comment.
awesome. add assert then?
There was a problem hiding this comment.
Not sure if it's the exact ASSERT you wanted but
drain >= remaining
drain - remaining >= 0
elapsed = drain - remaining
elapsed >= 0
so I added ASSERT(elapsed_time >= 0);
There was a problem hiding this comment.
probably not, if elapsed_time is ultimately a uint_something it would be true by defintion.
I meant asserting the subtraction is non-underflowing.
ASSERT(server_.options().drainTime() >= remaining_time);
Signed-off-by: Auni Ahsan <auni@google.com>
|
@mattklein123 is this good to merge? |
| namespace { | ||
|
|
||
| class DrainManagerImplTest : public testing::Test { | ||
| constexpr int DrainTimeSeconds(600); |
There was a problem hiding this comment.
nit: just use std::chrono::seconds here. Feel free to do this change in one of your other PRs.
drain_manager: Refactor DrainManagerImpl with simulated time
* Replace recurring timer in DrainManagerImpl with a single timer that can be tested via simulated time.
* Clarify the behaviour where probability of drain close increases as the deadline is approached, and add mocks on the random() call to test this
* Rely on the system scheduler rather than tick time
* Had to remove the "drain tick #x" trace log
* Remove overly explicit includes
* Add TODO for integration tests on this via a real time system, once TestDrainManager is removed (that's a separate thread of work)
Additional Description: Preparatory work for enhancing graceful drain functionality.
Risk Level: Medium. This is changing a core dependency (via the server) that hasn't been touched in a while, but the behaviour should be a noop.
Testing: I added a lot more testing coverage, and some aspects of this (the probabilistic draining) weren't being tested at all prior.