-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add timeout hint protocol flag CB-569 #182
Add timeout hint protocol flag CB-569 #182
Conversation
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.
Implementation looks OK. Where are we going to describe the feature in this repo? E.g. what does a ?request-timeout-hint
look like. Will you update the guidelines, or some other doc?
@@ -596,6 +596,9 @@ class ProtocolFlags(object): | |||
|
|||
MULTI_CLIENT = 'M' | |||
MESSAGE_IDS = 'I' | |||
# New proposal flag to indicate that a device supports ?request-timeout-hint | |||
# See CB-2051 | |||
REQUEST_TIMEOUT_HINTS = 'T' |
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.
Please add to the docstring, line 572.
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.
Done in pending commit
@ajoubertza At the moment the only actual implementation of ?request-timeout-hint is in proxy_base.py in katcore, where the request handler docstring describes it completely. To define it properly I suggest we try and add it to the KATCP spec, which would provide the definitive definition. Then we could probably also add an optional implementation (with proper docstring) to the top level DeviceServer class (only activated if the correct protocol flags are specified) |
@brickZA Yes, it is nicely described in katcore, but that isn't a public repo yet. If we add the flag here, we have to describe its purpose, so that it can be used. A optional implementation would be great. |
@ajoubertza I agree, but I am willing to postpone that work :) Hence the TODO comment. I also made a backlog item in JIRA. Arm is available for twisting though. |
I'd like to hear some other opinions. @lvdheever? |
Actually, let me just see how much effort it would be to port the katcore implementation to katcp |
Agreed that it would be great if it can be moved to katcp to wrapt this up. The problem with these "TODO"s and related JIRA tickets is that they never get enough priority to get attention. So I am against leaving little bits of TODOs for later. Rather just do it now if it is not a substantial amount of work. |
I have come up with a nice clean way of doing it, but I will need some bits from #177 I only need to add some tests to PR177, so I'll go ahead and do that and then we can merge it and go forward. |
katcp/core.py
Outdated
if self.request_timeout_hints and not version_supports_hints: | ||
raise ValueError( | ||
'REQUEST_TIMEOUT_HINTS only suported in katcp v{}.{} and newer' | ||
.format(self.major, self.minor)) |
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.
Please correct reported version info in error & s/suported/supported/.
raise ValueError(
'REQUEST_TIMEOUT_HINTS only supported in katcp v{}.{} and newer'
.format(*self.REQUEST_TIMEOUT_HINTS_MIN_VERSION)
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.
Fixed and pushed.
if name.startswith("request_"): | ||
request_name = convert_method_name("request_", name) | ||
mcs._request_handlers[request_name] = getattr(mcs, name) | ||
assert(mcs._request_handlers[request_name].__doc__ is not None) | ||
if mcs.check_protocol(handler): |
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.
To be more DRY you could move the if mcs.check_protocol(handler):
and assert out of the request/inform/reply condition.
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, but then you need an additional if statement to check if any of the three cases were triggered, etc. I agonised about it for minutes ;)
katcp/core.py
Outdated
try: | ||
protocol_info = mcs.PROTOCOL_INFO | ||
except Exception: | ||
import pdb ; pdb.set_trace() |
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.
Seem you are still busy here.
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.
aah, thanks for catching that :)
It is only activated if the server protocol is set to the (proposed) KATCP v5.1 spec and the timeout hint protocol flag is enabled.
@ajoubertza @martinslabber @lvdheever OK, now ready for re-review. Added default timeout hint request implementation and some machinery for including/excluding request handlers on the basis of the enabled KATCP server protocol flags / protocol version. |
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.
Functionality looks good. Just some comment pedantry to consider.
katcp/kattypes.py
Outdated
return decorator | ||
|
||
def request_timeout_hint(timeout_hint): | ||
"""Add recommended client timeout hint to a request for request |
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.
Suggest you start the docstring with Decorator;
, like the other ones. It makes it more obvious for me.
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.
Added in pending commit.
katcp/kattypes.py
Outdated
-------- | ||
>>> class MyDevice(DeviceServer): | ||
... @return_reply(Int()) | ||
... @request_timeout_hint |
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.
Shouldn't there be a parameter here? E.g. @request_timeout_hint(15.0)
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.
Fixed in pending commit.
katcp/kattypes.py
Outdated
Parameters | ||
---------- | ||
timeout_hint : float (seconds) or None | ||
How long the decorated request should reasonably take to reply |
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.
Please add some information about what happens if the hint is set to None.
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.
Added in pending commit
katcp/test/test_server.py
Outdated
expected_connect_messages = ( | ||
r'#version-connect katcp-protocol 5.0-IM', | ||
# Will have to be updated for every library version bump | ||
r'#version-connect katcp-library katcp-python-%s' % katcp_version, |
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.
Does this comment still apply, if you're pulling the version from __version__
, or are you referring to the 5.0-IM
line?
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 you are right, it does not apply. The 5.0 bit should stay the same since that is the specified protocol version, although the library default might change at some stage.
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.
Clarified in pending commit.
katcp/test/test_server.py
Outdated
self._assert_msgs_equal(req.inform_msgs, | ||
['#request-timeout-hint help 0.0']) | ||
|
||
# Now set hint on help command and check that it is reflected Note, in |
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.
The "Note" shouldn't be capitalised, or is a full stop missing?
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.
Punctuation updated in pending commit. I appreciate the attention to detail / level of pedantry, whichever way you prefer to look at it :)
katcp/test/test_server.py
Outdated
self._test_handler_protocol_filters(self.DeviceWithEverything, | ||
self.all_expected_handlers) | ||
|
||
def test_handler_protocol_filters_five_with_nothing(self): |
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.
Shouldn't this be a five_one
, not a five
?
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.
Corrected in pending commit.
katcp/test/test_server.py
Outdated
"""Test handler filtering where protocol flags and version exclude some""" | ||
|
||
|
||
class DeviceVersionFiveOneWithMultiClient(self.DeviceWithEverything): |
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.
Too many blank lines, before this class?
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.
Made whitespace consistent between these related test methods.
katcp/test/test_server.py
Outdated
self.assertEqual(set(), actual_device_handlers & not_expected_handlers) | ||
|
||
|
||
def test_handler_protocol_filters_all(self): |
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.
Too many blank lines before this method?
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.
Fixed in pending commit.
@ajoubertza OK, updates pushed and ready for renewed scrutiny :) |
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.
All good!
Idea is that we want a server to explicitly tell a client that it can use the ?request-timeout-hint request without the client having to guess.