Repository navigation
temporal-sdk-migration [2/x]: temporal: support protobuf sharing with the official Ruby SDK #9
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e5b2320
Apply upstream PR335 to support shared Temporal protobuf definitions.
yfang-figma 5dfaf58
Preserve Coinbase's original protobuf import order and clarify owners…
yfang-figma 845b6a6
Honor PROTO_OUT when guarding generated protobuf imports.
yfang-figma d8d83c0
Add tests, CI coverage, and documentation for protobuf sharing.
yfang-figma 34d2726
Update CI to Ruby 3.4 and repair incompatible test fixtures.
yfang-figma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| .bundle/ | ||
| .yardoc | ||
| Gemfile.lock | ||
| /gemfiles/*.lock | ||
| _yardoc/ | ||
|
|
||
| /coverage/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| source 'https://rubygems.org' | ||
|
|
||
| gem 'google-protobuf', '~> 4.33' | ||
| gem 'google-protobuf', '4.33.1' | ||
|
|
||
| gemspec |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| _Written with AI_ | ||
|
|
||
| # Load both Ruby SDKs in one process | ||
|
|
||
| The two SDKs define the same Temporal API protobuf messages. Load the official | ||
| messages first. Then disable this SDK's message loading before requiring it: | ||
|
|
||
| ```ruby | ||
| require 'temporalio/client' | ||
| ENV['COINBASE_TEMPORAL_RUBY_DISABLE_PROTO_LOAD'] = '1' | ||
| require 'temporal-ruby' | ||
| ``` | ||
|
|
||
| The option is process-wide. Set it before the first Coinbase require. Do not | ||
| change it after boot. The Coinbase gRPC service stubs still load, but use the | ||
| official SDK's message classes. Without the option, Coinbase loading stays | ||
| unchanged. The `temporalio` gem is not a runtime dependency of this gem. | ||
|
|
||
| This follows the approach in [Coinbase PR 335](https://github.com/coinbase/temporal-ruby/pull/335). | ||
| It does not make the two Workflow runtimes' histories compatible. Each Task | ||
| Queue must have only one Workflow runtime, even if a process loads both SDKs. | ||
| Do not create official runtimes or clients before a process forks. | ||
|
|
||
| Run the protobuf loading and serialization probes with: | ||
|
|
||
| ```sh | ||
| BUNDLE_GEMFILE=gemfiles/temporalio.gemfile bundle install | ||
| BUNDLE_GEMFILE=gemfiles/temporalio.gemfile bundle exec rspec spec/unit/lib/temporal/protobuf_loading_spec.rb | ||
| ``` | ||
|
|
||
| These probes do not connect to Temporal. Application boot, fork, polling, and | ||
| payload compatibility need separate environment tests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| eval_gemfile '../Gemfile' | ||
|
|
||
| gem 'temporalio', '1.10.1', require: false |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| require 'open3' | ||
| require 'rbconfig' | ||
|
|
||
| describe 'Temporal protobuf loading' do | ||
| let(:lib_dir) { File.expand_path('../../../../lib', __dir__) } | ||
|
|
||
| def run_probe(code, disable_proto_load: nil) | ||
| Open3.capture3( | ||
| { 'COINBASE_TEMPORAL_RUBY_DISABLE_PROTO_LOAD' => disable_proto_load }, | ||
| RbConfig.ruby, '-I', lib_dir, '-e', code | ||
| ) | ||
| end | ||
|
|
||
| let(:exercise_coinbase) do | ||
| <<~'RUBY' | ||
| require 'temporal-ruby' | ||
| require 'temporal/worker' | ||
| require 'temporal/testing/replay_tester' | ||
|
|
||
| payload_converter = Temporal::Connection::Converter::Payload::ProtoJSON.new | ||
| execution = Temporalio::Api::Common::V1::WorkflowExecution.new(workflow_id: 'test-id') | ||
| payload = payload_converter.to_payload(execution) | ||
| raise 'protobuf payload did not round trip' unless payload_converter.from_payload(payload) == execution | ||
|
|
||
| converter = Temporal::ConverterWrapper.new( | ||
| Temporal::Configuration::DEFAULT_CONVERTER, | ||
| Temporal::Configuration::DEFAULT_PAYLOAD_CODEC | ||
| ) | ||
| command = Temporal::Workflow::Command::CompleteWorkflow.new(result: 'test-result') | ||
| proto = Temporal::Connection::Serializer.serialize(command, converter) | ||
| raise 'wrong command type' unless proto.command_type == :COMMAND_TYPE_COMPLETE_WORKFLOW_EXECUTION | ||
| result = converter.from_result_payloads(proto.complete_workflow_execution_command_attributes.result) | ||
| raise 'result did not round trip' unless result == 'test-result' | ||
|
|
||
| workflow_stub = Temporalio::Api::WorkflowService::V1::WorkflowService::Stub | ||
| operator_stub = Temporalio::Api::OperatorService::V1::OperatorService::Stub | ||
| raise 'missing Ruby gRPC stubs' unless workflow_stub < GRPC::ClientStub && operator_stub < GRPC::ClientStub | ||
| RUBY | ||
| end | ||
|
|
||
| it 'loads its own messages and stubs without the opt-in' do | ||
| stdout, stderr, status = run_probe(exercise_coinbase + <<~'RUBY') | ||
| raise 'official SDK loaded without the opt-in' if defined?(Temporalio::Client) | ||
| raise 'legacy messages were not loaded' unless $LOADED_FEATURES.any? do |path| | ||
| path.include?('/gen/temporal/api/common/v1/message_pb.rb') | ||
| end | ||
| RUBY | ||
| expect(status.success?).to eq(true), "#{stdout}\n#{stderr}" | ||
| end | ||
|
|
||
| it 'uses official messages with Coinbase serializers, worker definitions, and gRPC stubs' do | ||
| skip 'Run with BUNDLE_GEMFILE=gemfiles/temporalio.gemfile' unless ENV['BUNDLE_GEMFILE']&.end_with?('temporalio.gemfile') | ||
|
|
||
| stdout, stderr, status = run_probe( | ||
| "require 'temporalio/client'\n" + exercise_coinbase + <<~'RUBY', | ||
| require 'temporalio/worker' | ||
| message_loads = $LOADED_FEATURES.grep(%r{/gen/temporal/api/.*_pb\.rb$}).reject do |path| | ||
| path.end_with?('_services_pb.rb') | ||
| end | ||
| raise "Coinbase messages loaded: #{message_loads}" unless message_loads.empty? | ||
| raise 'Coinbase gen directory entered the load path' if $LOAD_PATH.any? { |path| path.end_with?('/lib/gen') } | ||
| raise 'official client not loaded' unless defined?(Temporalio::Client) | ||
| raise 'official worker not loaded' unless defined?(Temporalio::Worker) | ||
| RUBY | ||
| disable_proto_load: '1' | ||
| ) | ||
| expect(status.success?).to eq(true), "#{stdout}\n#{stderr}" | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Proto sed breaks on macOS
Low Severity
The new
make protostep uses GNUsed -iwith no backup suffix to re-apply theCOINBASE_TEMPORAL_RUBY_DISABLE_PROTO_LOADguards. BSDsedon macOS treats the script as a backup extension and fails after protoc has already overwrittenservice_services_pb.rb. Regeneration then leaves the gRPC stubs unguarded, so a later commit can drop coexistence support.Reviewed by Cursor Bugbot for commit 29327b5. Configure 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.
It's ok.