Skip to content
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

Merged
merged 8 commits into from
Apr 19, 2017

Conversation

brickZA
Copy link
Contributor

@brickZA brickZA commented Apr 12, 2017

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.

Copy link
Contributor

@ajoubertza ajoubertza left a 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'
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in pending commit

@brickZA
Copy link
Contributor Author

brickZA commented Apr 13, 2017

@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)

@ajoubertza
Copy link
Contributor

@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.

@brickZA
Copy link
Contributor Author

brickZA commented Apr 13, 2017

@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.

@ajoubertza
Copy link
Contributor

I'd like to hear some other opinions. @lvdheever?

@brickZA
Copy link
Contributor Author

brickZA commented Apr 13, 2017

Actually, let me just see how much effort it would be to port the katcore implementation to katcp

@lvdheever
Copy link
Contributor

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.

@brickZA
Copy link
Contributor Author

brickZA commented Apr 13, 2017

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))
Copy link
Contributor

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)

Copy link
Contributor Author

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):
Copy link
Contributor

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.

Copy link
Contributor Author

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()
Copy link
Contributor

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.

Copy link
Contributor Author

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.
@brickZA
Copy link
Contributor Author

brickZA commented Apr 19, 2017

@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.

Copy link
Contributor

@ajoubertza ajoubertza left a 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.

return decorator

def request_timeout_hint(timeout_hint):
"""Add recommended client timeout hint to a request for request
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in pending commit.

--------
>>> class MyDevice(DeviceServer):
... @return_reply(Int())
... @request_timeout_hint
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in pending commit.

Parameters
----------
timeout_hint : float (seconds) or None
How long the decorated request should reasonably take to reply
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in pending commit

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,
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clarified in pending commit.

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
Copy link
Contributor

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?

Copy link
Contributor Author

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 :)

self._test_handler_protocol_filters(self.DeviceWithEverything,
self.all_expected_handlers)

def test_handler_protocol_filters_five_with_nothing(self):
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected in pending commit.

"""Test handler filtering where protocol flags and version exclude some"""


class DeviceVersionFiveOneWithMultiClient(self.DeviceWithEverything):
Copy link
Contributor

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?

Copy link
Contributor Author

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.

self.assertEqual(set(), actual_device_handlers & not_expected_handlers)


def test_handler_protocol_filters_all(self):
Copy link
Contributor

@ajoubertza ajoubertza Apr 19, 2017

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in pending commit.

@brickZA
Copy link
Contributor Author

brickZA commented Apr 19, 2017

@ajoubertza OK, updates pushed and ready for renewed scrutiny :)

Copy link
Contributor

@ajoubertza ajoubertza left a comment

Choose a reason for hiding this comment

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

All good!

@brickZA brickZA merged commit 9750769 into master Apr 19, 2017
@brickZA brickZA deleted the user/nmarais/CB-569/timeout-hint-protocol-flags branch April 19, 2017 12:26
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.

4 participants