Repository navigation
Log all invalid worker transitions to scheduler - #6134
Conversation
Also incorporate this into the testing framework so that we fail loudly in this occurs in the test suite, even while hidden in a coroutine.
|
@gjoseph92 you might also find this one of interest (although no rush on it). |
| await asyncio.sleep(0.01) | ||
| if time() > start + 30: | ||
| await asyncio.gather(*(w.close(timeout=1) for w in workers)) | ||
| assert not s.events["invalid-worker-transition"] |
There was a problem hiding this comment.
I'd be a little concerned about erroring out within this cleanup logic? Maybe pull the events off the scheduler, await s.close(), then assert? Same for the other one. Or maybe it doesn't matter, not sure.
There was a problem hiding this comment.
It would also be good to test (in test_utils_test.py) that this works as expected.
There was a problem hiding this comment.
Good idea. See recent commits. I also invested a little in nicely formatted outputs. Dumping the commit message below:
Now we get errors like the following for InvalidTransition
Worker: tcp://127.0.0.1:36443
InvalidTransition: inc-03d935909bba38f9a49655e867cbf56a :: released->foo
Story:
('inc-03d935909bba38f9a49655e867cbf56a', 'compute-task', 'compute-task-1650136473.0490825', 1650136473.049759)
('inc-03d935909bba38f9a49655e867cbf56a', 'released', 'waiting', 'waiting', {'inc-03d935909bba38f9a49655e867cbf56a': 'ready'}, 'compute-task-1650136473.0490825', 1650136473.0498002)
('inc-03d935909bba38f9a49655e867cbf56a', 'waiting', 'ready', 'ready', {'inc-03d935909bba38f9a49655e867cbf56a': 'executing'}, 'compute-task-1650136473.0490825', 1650136473.0498285)
('inc-03d935909bba38f9a49655e867cbf56a', 'ready', 'executing', 'executing', {}, 'compute-task-1650136473.0490825', 1650136473.0498428)
('inc-03d935909bba38f9a49655e867cbf56a', 'put-in-memory', 'compute-task-1650136473.0490825', 1650136473.0505066)
('inc-03d935909bba38f9a49655e867cbf56a', 'executing', 'memory', 'memory', {}, 'compute-task-1650136473.0490825', 1650136473.0505476)
('inc-03d935909bba38f9a49655e867cbf56a', 'ensure-task-exists', 'memory', 'compute-task-1650136473.0510707', 1650136473.0558414)
('free-keys', ('inc-03d935909bba38f9a49655e867cbf56a',), 'memory-released-1650136473.05692', 1650136473.0609956)
('inc-03d935909bba38f9a49655e867cbf56a', 'release-key', 'memory-released-1650136473.05692', 1650136473.0610087)
('inc-03d935909bba38f9a49655e867cbf56a', 'memory', 'released', 'released', {}, 'memory-released-1650136473.05692', 1650136473.061037)
We also test that this shows up in gen_cluster tests
There was a problem hiding this comment.
I'd be a little concerned about erroring out within this cleanup logic? Maybe pull the events off the scheduler, await s.close(), then assert? Same for the other one. Or maybe it doesn't matter, not sure.
Did this too. Good catch.
Now we get errors like the following for InvalidTransition
```
Worker: tcp://127.0.0.1:36443
InvalidTransition: inc-03d935909bba38f9a49655e867cbf56a :: released->foo
Story:
('inc-03d935909bba38f9a49655e867cbf56a', 'compute-task', 'compute-task-1650136473.0490825', 1650136473.049759)
('inc-03d935909bba38f9a49655e867cbf56a', 'released', 'waiting', 'waiting', {'inc-03d935909bba38f9a49655e867cbf56a': 'ready'}, 'compute-task-1650136473.0490825', 1650136473.0498002)
('inc-03d935909bba38f9a49655e867cbf56a', 'waiting', 'ready', 'ready', {'inc-03d935909bba38f9a49655e867cbf56a': 'executing'}, 'compute-task-1650136473.0490825', 1650136473.0498285)
('inc-03d935909bba38f9a49655e867cbf56a', 'ready', 'executing', 'executing', {}, 'compute-task-1650136473.0490825', 1650136473.0498428)
('inc-03d935909bba38f9a49655e867cbf56a', 'put-in-memory', 'compute-task-1650136473.0490825', 1650136473.0505066)
('inc-03d935909bba38f9a49655e867cbf56a', 'executing', 'memory', 'memory', {}, 'compute-task-1650136473.0490825', 1650136473.0505476)
('inc-03d935909bba38f9a49655e867cbf56a', 'ensure-task-exists', 'memory', 'compute-task-1650136473.0510707', 1650136473.0558414)
('free-keys', ('inc-03d935909bba38f9a49655e867cbf56a',), 'memory-released-1650136473.05692', 1650136473.0609956)
('inc-03d935909bba38f9a49655e867cbf56a', 'release-key', 'memory-released-1650136473.05692', 1650136473.0610087)
('inc-03d935909bba38f9a49655e867cbf56a', 'memory', 'released', 'released', {}, 'memory-released-1650136473.05692', 1650136473.061037)
```
We also test that this shows up in gen_cluster tests
6d4a14c to
c130caa
Compare
| assert a.address in str(s.events["invalid-worker-transition"]) | ||
| assert ts.key in str(s.events["invalid-worker-transition"]) | ||
|
|
||
| del s.events["invalid-worker-transition"] # for test cleanup |
There was a problem hiding this comment.
I'm interested in why this is necessary. As far as I can tell Scheduler.events contains nested, simple types. Could there by more complex types containing references that prevent garbage collection?
There was a problem hiding this comment.
This is to stop the check in gen_cluster from triggering and causing the test to err.
| await asyncio.gather(*(end_worker(w) for w in workers)) | ||
| await s.close() # wait until scheduler stops completely | ||
| s.stop() | ||
| check_invalid_worker_transitions(s) |
There was a problem hiding this comment.
I understand that transition failures are catastrophic events, but this makes me wonder whether there are other events that should be checked for during testing fixture teardown. Why not test for them here too? Should we also be serialising them in Scheduler.events as a matter of policy and reconstituting them here? Is this a once-off special-case handling strategy for transition failures?
There was a problem hiding this comment.
Possibly, but for now I'd like to focus on these events. If we find that we want to do this a couple more times then we'll probably generalize things. For now I'd like to focus on a concrete problem for which we have an immediate need of a solution. If we try to do something general then we'll be guessing I think about what the right structure is.
There was a problem hiding this comment.
I think this is fine as exploratory code to tease out failure. I'm concerned that it becomes a forgotten special case. Do we have a process for keeping track of this kind of thing (another github issue for instance?)
There was a problem hiding this comment.
I'm not terribly concerned about us forgetting to track things in gen_cluster as they come up. This already has dozens of checks for various inconsistencies (see functions like clean). We're pretty good at adding to this as things arise. If there is something in particular that you've run into and would like to see checked that isn't then yes, a github issue would be a great place to raise that.
| while not s.events["invalid-worker-transition"]: | ||
| await asyncio.sleep(0.01) | ||
|
|
||
| with pytest.raises(Exception) as info: |
There was a problem hiding this comment.
| with pytest.raises(Exception) as info: | |
| with pytest.raises(ValueError) as info: |
There was a problem hiding this comment.
Can you motivate this change? Do you care in particular that it is a ValueError, or are you just trying to match the behavior as it exists today?
There was a problem hiding this comment.
And, to make my thinking explicit here, I don't care if this is a ValueError or some other kind of error. I personally like using ValueErrors but sometimes folks here like to use very specific things. If they did that in the future I wouldn't want to hold them back. I would want to hold them back if relevant data wasn't in the error message (as is enforced below).
I've chosen to use Exception here because I don't have a strong enough preference on type to want to constrain future developers too much.
There was a problem hiding this comment.
Can you motivate this change?
Just for the normal reason of catching the specific exception type, instead of any Exception: don't accidentally catch something else. I saw that check_invalid_worker_transitions raises ValueError currently, which is what you're hoping to catch.
If, say, the cluster actually deadlocked and timed out, the assert "invalid" in str(info).lower() should fail the test anyway, so it's not that big of a deal. It's just a little easier to read the intention of the test this way.
I've chosen to use Exception here because I don't have a strong enough preference on type to want to constrain future developers too much
If future developers want to change the exception type, then can't they can make a one-line change to the test?
There was a problem hiding this comment.
If, say, the cluster actually deadlocked and timed out, the assert "invalid" in str(info).lower() should fail the test anyway, so it's not that big of a deal. It's just a little easier to read the intention of the test this way.
Yeah, I don't think that we're going to catch unwanted things here. I would also want to be way more specific in actual code.
If future developers want to change the exception type, then can't they can make a one-line change to the test?
Yeah, in this case it's pretty cheap. In general though I like to test only things that I care about. Otherwise we end up asking devs to change all sorts of unrelated tests that they don't know anything about, which error prone. In general my practice here is to "test things you care about, don't test to match current behavior" which is something that I'd love to socialize a bit across the project (historically we didn't do this, and it resulted in significant pain). In this case though I can't come up with any way to trigger this test except in that one line, so I don't care that much. I'm just sticking to my default policy.
Also incorporate this into the testing framework so that we fail loudly
in this occurs in the test suite, even while hidden in a coroutine.