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

Support THeader protocol #564

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

pguillory
Copy link
Collaborator

THeader is an optional wrapper for Thrift RPC messages that allows for requests
to include out-of-band headers, useful for things like distributed tracing in
service oriented architectures.

This change only implements THeader support on the server side. We can
auto-detect the protocol on a per-request basis based on the first two bytes.
THeader starts with 0x0FFF, whereas binary starts with 0x8001.

THeader is an optional wrapper for Thrift RPC messages that allows for requests
to include out-of-band headers, useful for things like distributed tracing in
service oriented architectures.

This change only implements THeader support on the server side. We can
auto-detect the protocol on a per-request basis based on the first two bytes.
THeader starts with 0x0FFF, whereas binary starts with 0x8001.
Copy link
Collaborator

@jparise jparise left a comment

Choose a reason for hiding this comment

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

This looks good overall, but I left a note about the general approach by which the protocol is detected and the protocol-specific code invoked.

It would also be good to add a short note to the README.md that mentioned THeader support.

Comment on lines 34 to 40
# Try other protocols.
def deserialize(payload) do
with {:ok, message} <- Binary.deserialize(:message_begin, payload) do
headers = %{protocol: Binary}
{:ok, headers, message}
end
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure it feels quite right for the THeader module to be the thing that defers to the other protocols (like Binary). I think I would have expected the protocol handler to attempt to match on the magic header one level up and then invoke the appropriate protocol-specific deserialization calls from there.

Copy link
Member

Choose a reason for hiding this comment

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

THeader is really a Transport and not a Protocol. Likely we want to move the abstraction to that level.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jparise: With its protocol_id field, THeader knows about selecting between binary/compact protocols. So to me it feels like a natural place also to be doing protocol auto-detection.

@fishcakez: True that it's a transport. I'll rename it to Thrift.Transport.THeader.

Comment on lines 5 to 6
# THeader format:
# https://github.com/apache/thrift/blob/master/doc/specs/HeaderFormat.md
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this should be part of a moduledoc block?

This link is also duplicated below (above deserialize).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, done.

@fishcakez
Copy link
Member

If the server receives a THeader call, it needs to return a THeader reply, otherwise some clients may break. Generally speaking clients will have a configured a transport/protocol and always use it.

@pguillory
Copy link
Collaborator Author

If the server receives a THeader call, it needs to return a THeader reply, otherwise some clients may break. Generally speaking clients will have a configured a transport/protocol and always use it.

Will work on this.

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