-
Notifications
You must be signed in to change notification settings - Fork 44
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
base: master
Are you sure you want to change the base?
Conversation
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.
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.
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.
lib/thrift/protocol/theader.ex
Outdated
# Try other protocols. | ||
def deserialize(payload) do | ||
with {:ok, message} <- Binary.deserialize(:message_begin, payload) do | ||
headers = %{protocol: Binary} | ||
{:ok, headers, message} | ||
end | ||
end |
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'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.
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.
THeader is really a Transport and not a Protocol. Likely we want to move the abstraction to that level.
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.
@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.
lib/thrift/protocol/theader.ex
Outdated
# THeader format: | ||
# https://github.com/apache/thrift/blob/master/doc/specs/HeaderFormat.md |
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.
Maybe this should be part of a moduledoc block?
This link is also duplicated below (above deserialize
).
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.
Thanks, done.
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. |
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.