-
Notifications
You must be signed in to change notification settings - Fork 107
Adding payload codec pipeline #224
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
Adding payload codec pipeline #224
Conversation
…nal-with-start Change how signal_with_start is exposed
…nal-with-start Update method signature in temporal test fixture
…nal-with-start Update our FailWorkflowTask logic's call to ErrorHandler.handle
…ner/woflo-482 Workflow await condition in context wait_for
…ner/woflo-482-fix Fix EventTarget comparison with wildcard
…ner/m1-fixes Set Ruby 2.7 to be consistent with pay-server
…ins_schedule_to_start Turn off schedule_to_start activity timeout by default
…oner-WOFLO-1235-timeout-history Treat missing history submessage when getting workflow history as timeout
…kins_schedule Dynamic Workflows
…oner-WOFLO-1216 Support terminate-if-running workflow ID reuse policy
…oner-latest-upstream Merge latest Coinbase upstream
|
In the official SDKs search attributes do not go through the user configurable data converter, might want to do the same here. |
this is true, I wonder if anyone has built a data converter for their search attributes though that by removing this and just using JSON would break their existing setup? Should we bump the version just incase? @bergundy |
jeffschoner-stripe
left a comment
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.
Is it possible to update the existing encryption test to use this new pipeline? I think it's better suited to your solution rather than switching out the converter like it does today.
|
|
||
| def from_search_attribute_payload(payload_map) | ||
| # skips the payload_codec step because search attributes don't use this pipeline | ||
| payload_map.map { |key, value| [key, payload_converter.from_payload(value)] }.to_h |
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 abstraction is seeping through here a bit. Should this be named something like from_payload_map_without_codec? The call on search attributes would then be made outside of this file which is specific to performing various kinds of encoding.
| Temporal.configuration.converter | ||
| end | ||
|
|
||
| def payload_codec |
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.
A comment at the top of this file or on this method explaining the difference between payload converters and payload codecs would be worthwhile. Or actually probably in configuration.rb where a user would see it.
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 to the configuration.rb, let me know what you think
| def encodes(payloads) | ||
| return nil if payloads.nil? | ||
|
|
||
| Temporalio::Api::Common::V1::Payloads.new( | ||
| payloads: payloads.payloads.map(&method(:encode)) | ||
| ) | ||
| end | ||
|
|
||
| def decodes(payloads) | ||
| return nil if payloads.nil? | ||
|
|
||
| Temporalio::Api::Common::V1::Payloads.new( | ||
| payloads: payloads.payloads.map(&method(:decode)) | ||
| ) | ||
| 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.
Would these be overridden by someone extending this class? Why not move these into payloads.rb?
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.
they can be, I just was following the same pattern as in payloads.rb which seems to be define the same thing (from_payloads and to_payloads with logic then from_payload and to_payload are empty and required)
You probably are going to only override encode or decode but you have the option to override all for if the use case needs it.
lib/temporal/concerns/payloads.rb
Outdated
| payload_codec.encode(payload) | ||
| end | ||
|
|
||
| def to_search_attribute_payload(data) |
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.
same thing here in the other direction
| # the codecs are applied last to first meaning the earlier encodings wrap the later ones. | ||
| # When decoding, the codecs are applied first to last to reverse the effect. | ||
| class Chain < Base | ||
| def initialize(payload_codecs:) |
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.
nit: This might be more ergonomic with a splat or non-keyword argument instead
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 agree, i was just keeping the same pattern as
| def initialize(payload_converters:) |
| @@ -0,0 +1,76 @@ | |||
| require 'temporal/connection/converter/codec/chain' | |||
|
|
|||
| describe Temporal::Connection::Converter::Codec::Base do | |||
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.
Testing the base class seems strange to me since no one is expected to use this directly. It will always be extended, right? This might be a further indication that these non-abstract methods should simply be moved into payloads.rb instead.
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.
hmm, i don't disagree, just was following the pattern that was already in place for from_payloads and to_payloads. What do you think? Im easy either way.
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.
if we do remove, ill remove the unit tests
Overview
Adds the payload codec pipeline described here https://docs.temporal.io/security#payload-codec.
This adds a new configuration option called
payload_codecwhich always runs after the payload has been serialized (and before deserialization) when sent to (and received from) the server.Currently, all payloads go through the data converter but only non search attributes payloads should go through payload codecs (otherwise if the payload is transformed into something the server can not read e.g. compressed or encrypted, then the server will reject it because it can not insert non datetime strings for example into the es index)
Test Plan