temporalio 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (310) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +180 -7
  3. data/bridge/Cargo.lock +208 -76
  4. data/bridge/Cargo.toml +5 -2
  5. data/bridge/sdk-core/Cargo.toml +1 -1
  6. data/bridge/sdk-core/README.md +20 -10
  7. data/bridge/sdk-core/client/Cargo.toml +1 -1
  8. data/bridge/sdk-core/client/src/lib.rs +227 -59
  9. data/bridge/sdk-core/client/src/metrics.rs +17 -8
  10. data/bridge/sdk-core/client/src/raw.rs +13 -12
  11. data/bridge/sdk-core/client/src/retry.rs +132 -43
  12. data/bridge/sdk-core/core/Cargo.toml +28 -15
  13. data/bridge/sdk-core/core/benches/workflow_replay.rs +13 -10
  14. data/bridge/sdk-core/core/src/abstractions.rs +225 -36
  15. data/bridge/sdk-core/core/src/core_tests/activity_tasks.rs +217 -79
  16. data/bridge/sdk-core/core/src/core_tests/determinism.rs +165 -2
  17. data/bridge/sdk-core/core/src/core_tests/local_activities.rs +565 -34
  18. data/bridge/sdk-core/core/src/core_tests/queries.rs +247 -90
  19. data/bridge/sdk-core/core/src/core_tests/workers.rs +3 -5
  20. data/bridge/sdk-core/core/src/core_tests/workflow_cancels.rs +1 -1
  21. data/bridge/sdk-core/core/src/core_tests/workflow_tasks.rs +430 -67
  22. data/bridge/sdk-core/core/src/ephemeral_server/mod.rs +106 -12
  23. data/bridge/sdk-core/core/src/internal_flags.rs +136 -0
  24. data/bridge/sdk-core/core/src/lib.rs +148 -34
  25. data/bridge/sdk-core/core/src/protosext/mod.rs +1 -1
  26. data/bridge/sdk-core/core/src/replay/mod.rs +185 -41
  27. data/bridge/sdk-core/core/src/telemetry/log_export.rs +190 -0
  28. data/bridge/sdk-core/core/src/telemetry/metrics.rs +219 -140
  29. data/bridge/sdk-core/core/src/telemetry/mod.rs +326 -315
  30. data/bridge/sdk-core/core/src/telemetry/prometheus_server.rs +20 -14
  31. data/bridge/sdk-core/core/src/test_help/mod.rs +85 -21
  32. data/bridge/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +112 -156
  33. data/bridge/sdk-core/core/src/worker/activities/activity_task_poller_stream.rs +89 -0
  34. data/bridge/sdk-core/core/src/worker/activities/local_activities.rs +364 -128
  35. data/bridge/sdk-core/core/src/worker/activities.rs +263 -170
  36. data/bridge/sdk-core/core/src/worker/client/mocks.rs +23 -3
  37. data/bridge/sdk-core/core/src/worker/client.rs +48 -6
  38. data/bridge/sdk-core/core/src/worker/mod.rs +186 -75
  39. data/bridge/sdk-core/core/src/worker/workflow/bridge.rs +1 -3
  40. data/bridge/sdk-core/core/src/worker/workflow/driven_workflow.rs +13 -24
  41. data/bridge/sdk-core/core/src/worker/workflow/history_update.rs +879 -226
  42. data/bridge/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +101 -48
  43. data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +8 -12
  44. data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +6 -9
  45. data/bridge/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +90 -32
  46. data/bridge/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +6 -9
  47. data/bridge/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +7 -10
  48. data/bridge/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +6 -9
  49. data/bridge/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +160 -83
  50. data/bridge/sdk-core/core/src/worker/workflow/machines/mod.rs +36 -54
  51. data/bridge/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +179 -0
  52. data/bridge/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +104 -157
  53. data/bridge/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +8 -12
  54. data/bridge/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +9 -13
  55. data/bridge/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +10 -4
  56. data/bridge/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +14 -11
  57. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +6 -17
  58. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +395 -299
  59. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +12 -20
  60. data/bridge/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +33 -18
  61. data/bridge/sdk-core/core/src/worker/workflow/managed_run.rs +1032 -374
  62. data/bridge/sdk-core/core/src/worker/workflow/mod.rs +525 -392
  63. data/bridge/sdk-core/core/src/worker/workflow/run_cache.rs +40 -57
  64. data/bridge/sdk-core/core/src/worker/workflow/wft_extraction.rs +125 -0
  65. data/bridge/sdk-core/core/src/worker/workflow/wft_poller.rs +3 -6
  66. data/bridge/sdk-core/core/src/worker/workflow/workflow_stream/saved_wf_inputs.rs +117 -0
  67. data/bridge/sdk-core/core/src/worker/workflow/workflow_stream/tonic_status_serde.rs +24 -0
  68. data/bridge/sdk-core/core/src/worker/workflow/workflow_stream.rs +456 -681
  69. data/bridge/sdk-core/core-api/Cargo.toml +6 -4
  70. data/bridge/sdk-core/core-api/src/errors.rs +1 -34
  71. data/bridge/sdk-core/core-api/src/lib.rs +7 -45
  72. data/bridge/sdk-core/core-api/src/telemetry.rs +141 -0
  73. data/bridge/sdk-core/core-api/src/worker.rs +27 -1
  74. data/bridge/sdk-core/etc/deps.svg +115 -140
  75. data/bridge/sdk-core/etc/regen-depgraph.sh +5 -0
  76. data/bridge/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +18 -15
  77. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +1 -1
  78. data/bridge/sdk-core/fsm/rustfsm_trait/src/lib.rs +8 -3
  79. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-16_history.bin +0 -0
  80. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-23_history.bin +0 -0
  81. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-85_history.bin +0 -0
  82. data/bridge/sdk-core/protos/api_upstream/buf.yaml +0 -3
  83. data/bridge/sdk-core/protos/api_upstream/build/go.mod +7 -0
  84. data/bridge/sdk-core/protos/api_upstream/build/go.sum +5 -0
  85. data/bridge/sdk-core/protos/api_upstream/{temporal/api/enums/v1/cluster.proto → build/tools.go} +7 -18
  86. data/bridge/sdk-core/protos/api_upstream/go.mod +6 -0
  87. data/bridge/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +12 -9
  88. data/bridge/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +15 -26
  89. data/bridge/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +13 -2
  90. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +3 -2
  91. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +4 -9
  92. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +3 -2
  93. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +10 -8
  94. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +28 -2
  95. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +2 -2
  96. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/query.proto +2 -2
  97. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +2 -2
  98. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +2 -2
  99. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +2 -2
  100. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +24 -19
  101. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +2 -2
  102. data/bridge/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +2 -2
  103. data/bridge/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -2
  104. data/bridge/sdk-core/protos/api_upstream/temporal/api/filter/v1/message.proto +2 -2
  105. data/bridge/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +62 -26
  106. data/bridge/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +4 -2
  107. data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +24 -61
  108. data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +2 -21
  109. data/bridge/sdk-core/protos/api_upstream/temporal/api/protocol/v1/message.proto +57 -0
  110. data/bridge/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +2 -2
  111. data/bridge/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +2 -2
  112. data/bridge/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +110 -31
  113. data/bridge/sdk-core/protos/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +63 -0
  114. data/bridge/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +4 -4
  115. data/bridge/sdk-core/protos/api_upstream/temporal/api/update/v1/message.proto +71 -6
  116. data/bridge/sdk-core/protos/api_upstream/temporal/api/version/v1/message.proto +2 -2
  117. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +3 -2
  118. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +111 -36
  119. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +19 -5
  120. data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +1 -0
  121. data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +1 -0
  122. data/bridge/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +1 -0
  123. data/bridge/sdk-core/protos/local/temporal/sdk/core/common/common.proto +1 -0
  124. data/bridge/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +1 -0
  125. data/bridge/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +1 -0
  126. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +9 -0
  127. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +9 -1
  128. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +6 -0
  129. data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +2 -2
  130. data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +2 -2
  131. data/bridge/sdk-core/sdk/Cargo.toml +4 -3
  132. data/bridge/sdk-core/sdk/src/interceptors.rs +36 -3
  133. data/bridge/sdk-core/sdk/src/lib.rs +94 -25
  134. data/bridge/sdk-core/sdk/src/workflow_context.rs +13 -2
  135. data/bridge/sdk-core/sdk/src/workflow_future.rs +10 -13
  136. data/bridge/sdk-core/sdk-core-protos/Cargo.toml +5 -2
  137. data/bridge/sdk-core/sdk-core-protos/build.rs +36 -2
  138. data/bridge/sdk-core/sdk-core-protos/src/history_builder.rs +164 -104
  139. data/bridge/sdk-core/sdk-core-protos/src/history_info.rs +27 -23
  140. data/bridge/sdk-core/sdk-core-protos/src/lib.rs +252 -74
  141. data/bridge/sdk-core/sdk-core-protos/src/task_token.rs +12 -2
  142. data/bridge/sdk-core/test-utils/Cargo.toml +4 -1
  143. data/bridge/sdk-core/test-utils/src/canned_histories.rs +106 -296
  144. data/bridge/sdk-core/test-utils/src/histfetch.rs +1 -1
  145. data/bridge/sdk-core/test-utils/src/lib.rs +161 -50
  146. data/bridge/sdk-core/test-utils/src/wf_input_saver.rs +50 -0
  147. data/bridge/sdk-core/test-utils/src/workflows.rs +29 -0
  148. data/bridge/sdk-core/tests/fuzzy_workflow.rs +130 -0
  149. data/bridge/sdk-core/tests/{load_tests.rs → heavy_tests.rs} +125 -51
  150. data/bridge/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +25 -3
  151. data/bridge/sdk-core/tests/integ_tests/heartbeat_tests.rs +10 -5
  152. data/bridge/sdk-core/tests/integ_tests/metrics_tests.rs +239 -0
  153. data/bridge/sdk-core/tests/integ_tests/polling_tests.rs +4 -60
  154. data/bridge/sdk-core/tests/integ_tests/queries_tests.rs +5 -128
  155. data/bridge/sdk-core/tests/integ_tests/visibility_tests.rs +83 -25
  156. data/bridge/sdk-core/tests/integ_tests/workflow_tests/activities.rs +93 -69
  157. data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +1 -0
  158. data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +6 -13
  159. data/bridge/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +1 -0
  160. data/bridge/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +6 -2
  161. data/bridge/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +3 -10
  162. data/bridge/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +151 -116
  163. data/bridge/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +54 -0
  164. data/bridge/sdk-core/tests/integ_tests/workflow_tests/patches.rs +7 -28
  165. data/bridge/sdk-core/tests/integ_tests/workflow_tests/replay.rs +115 -24
  166. data/bridge/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -0
  167. data/bridge/sdk-core/tests/integ_tests/workflow_tests/signals.rs +18 -14
  168. data/bridge/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +6 -20
  169. data/bridge/sdk-core/tests/integ_tests/workflow_tests/timers.rs +10 -21
  170. data/bridge/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +6 -4
  171. data/bridge/sdk-core/tests/integ_tests/workflow_tests.rs +27 -18
  172. data/bridge/sdk-core/tests/main.rs +8 -16
  173. data/bridge/sdk-core/tests/runner.rs +75 -36
  174. data/bridge/sdk-core/tests/wf_input_replay.rs +32 -0
  175. data/bridge/src/connection.rs +117 -82
  176. data/bridge/src/lib.rs +356 -42
  177. data/bridge/src/runtime.rs +10 -3
  178. data/bridge/src/test_server.rs +153 -0
  179. data/bridge/src/worker.rs +133 -9
  180. data/lib/gen/temporal/api/batch/v1/message_pb.rb +8 -6
  181. data/lib/gen/temporal/api/command/v1/message_pb.rb +10 -16
  182. data/lib/gen/temporal/api/common/v1/message_pb.rb +5 -1
  183. data/lib/gen/temporal/api/enums/v1/batch_operation_pb.rb +2 -1
  184. data/lib/gen/temporal/api/enums/v1/command_type_pb.rb +3 -3
  185. data/lib/gen/temporal/api/enums/v1/common_pb.rb +2 -1
  186. data/lib/gen/temporal/api/enums/v1/event_type_pb.rb +5 -4
  187. data/lib/gen/temporal/api/enums/v1/failed_cause_pb.rb +9 -1
  188. data/lib/gen/temporal/api/enums/v1/namespace_pb.rb +1 -1
  189. data/lib/gen/temporal/api/enums/v1/query_pb.rb +1 -1
  190. data/lib/gen/temporal/api/enums/v1/reset_pb.rb +1 -1
  191. data/lib/gen/temporal/api/enums/v1/schedule_pb.rb +1 -1
  192. data/lib/gen/temporal/api/enums/v1/task_queue_pb.rb +1 -1
  193. data/lib/gen/temporal/api/enums/v1/update_pb.rb +7 -10
  194. data/lib/gen/temporal/api/enums/v1/workflow_pb.rb +1 -1
  195. data/lib/gen/temporal/api/errordetails/v1/message_pb.rb +1 -1
  196. data/lib/gen/temporal/api/failure/v1/message_pb.rb +1 -1
  197. data/lib/gen/temporal/api/filter/v1/message_pb.rb +1 -1
  198. data/lib/gen/temporal/api/history/v1/message_pb.rb +34 -25
  199. data/lib/gen/temporal/api/namespace/v1/message_pb.rb +2 -1
  200. data/lib/gen/temporal/api/operatorservice/v1/request_response_pb.rb +14 -51
  201. data/lib/gen/temporal/api/operatorservice/v1/service_pb.rb +1 -1
  202. data/lib/gen/temporal/api/protocol/v1/message_pb.rb +30 -0
  203. data/lib/gen/temporal/api/query/v1/message_pb.rb +1 -1
  204. data/lib/gen/temporal/api/replication/v1/message_pb.rb +1 -1
  205. data/lib/gen/temporal/api/schedule/v1/message_pb.rb +22 -1
  206. data/lib/gen/temporal/api/sdk/v1/task_complete_metadata_pb.rb +23 -0
  207. data/lib/gen/temporal/api/taskqueue/v1/message_pb.rb +2 -2
  208. data/lib/gen/temporal/api/testservice/v1/request_response_pb.rb +49 -0
  209. data/lib/gen/temporal/api/testservice/v1/service_pb.rb +21 -0
  210. data/lib/gen/temporal/api/update/v1/message_pb.rb +49 -3
  211. data/lib/gen/temporal/api/version/v1/message_pb.rb +1 -1
  212. data/lib/gen/temporal/api/workflow/v1/message_pb.rb +2 -1
  213. data/lib/gen/temporal/api/workflowservice/v1/request_response_pb.rb +47 -20
  214. data/lib/gen/temporal/api/workflowservice/v1/service_pb.rb +1 -1
  215. data/lib/gen/temporal/sdk/core/activity_result/activity_result_pb.rb +13 -9
  216. data/lib/gen/temporal/sdk/core/activity_task/activity_task_pb.rb +10 -6
  217. data/lib/gen/temporal/sdk/core/child_workflow/child_workflow_pb.rb +13 -9
  218. data/lib/gen/temporal/sdk/core/common/common_pb.rb +7 -3
  219. data/lib/gen/temporal/sdk/core/core_interface_pb.rb +9 -3
  220. data/lib/gen/temporal/sdk/core/external_data/external_data_pb.rb +7 -3
  221. data/lib/gen/temporal/sdk/core/workflow_activation/workflow_activation_pb.rb +28 -21
  222. data/lib/gen/temporal/sdk/core/workflow_commands/workflow_commands_pb.rb +32 -24
  223. data/lib/gen/temporal/sdk/core/workflow_completion/workflow_completion_pb.rb +12 -5
  224. data/lib/temporalio/activity/context.rb +102 -0
  225. data/lib/temporalio/activity/info.rb +67 -0
  226. data/lib/temporalio/activity.rb +85 -0
  227. data/lib/temporalio/bridge/connect_options.rb +15 -0
  228. data/lib/temporalio/bridge/error.rb +8 -0
  229. data/lib/temporalio/bridge/retry_config.rb +24 -0
  230. data/lib/temporalio/bridge/tls_options.rb +19 -0
  231. data/lib/temporalio/bridge.rb +14 -0
  232. data/lib/{temporal → temporalio}/client/implementation.rb +57 -56
  233. data/lib/{temporal → temporalio}/client/workflow_handle.rb +35 -35
  234. data/lib/{temporal → temporalio}/client.rb +19 -32
  235. data/lib/temporalio/connection/retry_config.rb +44 -0
  236. data/lib/temporalio/connection/service.rb +20 -0
  237. data/lib/temporalio/connection/test_service.rb +92 -0
  238. data/lib/temporalio/connection/tls_options.rb +51 -0
  239. data/lib/temporalio/connection/workflow_service.rb +731 -0
  240. data/lib/temporalio/connection.rb +86 -0
  241. data/lib/{temporal → temporalio}/data_converter.rb +76 -35
  242. data/lib/{temporal → temporalio}/error/failure.rb +6 -6
  243. data/lib/{temporal → temporalio}/error/workflow_failure.rb +4 -2
  244. data/lib/{temporal → temporalio}/errors.rb +19 -1
  245. data/lib/{temporal → temporalio}/failure_converter/base.rb +5 -5
  246. data/lib/{temporal → temporalio}/failure_converter/basic.rb +58 -52
  247. data/lib/temporalio/failure_converter.rb +7 -0
  248. data/lib/temporalio/interceptor/activity_inbound.rb +22 -0
  249. data/lib/temporalio/interceptor/activity_outbound.rb +24 -0
  250. data/lib/{temporal → temporalio}/interceptor/chain.rb +7 -6
  251. data/lib/{temporal → temporalio}/interceptor/client.rb +27 -2
  252. data/lib/temporalio/interceptor.rb +22 -0
  253. data/lib/{temporal → temporalio}/payload_codec/base.rb +5 -5
  254. data/lib/{temporal → temporalio}/payload_converter/base.rb +3 -3
  255. data/lib/{temporal → temporalio}/payload_converter/bytes.rb +4 -3
  256. data/lib/{temporal → temporalio}/payload_converter/composite.rb +7 -5
  257. data/lib/{temporal → temporalio}/payload_converter/encoding_base.rb +4 -4
  258. data/lib/{temporal → temporalio}/payload_converter/json.rb +4 -3
  259. data/lib/{temporal → temporalio}/payload_converter/nil.rb +4 -3
  260. data/lib/temporalio/payload_converter.rb +14 -0
  261. data/lib/{temporal → temporalio}/retry_policy.rb +17 -7
  262. data/lib/{temporal → temporalio}/retry_state.rb +1 -1
  263. data/lib/temporalio/runtime.rb +25 -0
  264. data/lib/temporalio/testing/time_skipping_handle.rb +32 -0
  265. data/lib/temporalio/testing/time_skipping_interceptor.rb +23 -0
  266. data/lib/temporalio/testing/workflow_environment.rb +112 -0
  267. data/lib/temporalio/testing.rb +175 -0
  268. data/lib/{temporal → temporalio}/timeout_type.rb +2 -2
  269. data/lib/temporalio/version.rb +3 -0
  270. data/lib/temporalio/worker/activity_runner.rb +114 -0
  271. data/lib/temporalio/worker/activity_worker.rb +164 -0
  272. data/lib/temporalio/worker/reactor.rb +46 -0
  273. data/lib/temporalio/worker/runner.rb +63 -0
  274. data/lib/temporalio/worker/sync_worker.rb +124 -0
  275. data/lib/temporalio/worker/thread_pool_executor.rb +51 -0
  276. data/lib/temporalio/worker.rb +204 -0
  277. data/lib/temporalio/workflow/async.rb +46 -0
  278. data/lib/{temporal → temporalio}/workflow/execution_info.rb +4 -4
  279. data/lib/{temporal → temporalio}/workflow/execution_status.rb +1 -1
  280. data/lib/temporalio/workflow/future.rb +138 -0
  281. data/lib/{temporal → temporalio}/workflow/id_reuse_policy.rb +6 -6
  282. data/lib/temporalio/workflow/info.rb +76 -0
  283. data/lib/{temporal → temporalio}/workflow/query_reject_condition.rb +5 -5
  284. data/lib/temporalio.rb +12 -3
  285. data/temporalio.gemspec +11 -6
  286. metadata +137 -64
  287. data/bridge/sdk-core/Cargo.lock +0 -2606
  288. data/bridge/sdk-core/bridge-ffi/Cargo.toml +0 -24
  289. data/bridge/sdk-core/bridge-ffi/LICENSE.txt +0 -23
  290. data/bridge/sdk-core/bridge-ffi/build.rs +0 -25
  291. data/bridge/sdk-core/bridge-ffi/include/sdk-core-bridge.h +0 -249
  292. data/bridge/sdk-core/bridge-ffi/src/lib.rs +0 -825
  293. data/bridge/sdk-core/bridge-ffi/src/wrappers.rs +0 -211
  294. data/bridge/sdk-core/core/src/log_export.rs +0 -62
  295. data/bridge/sdk-core/core/src/worker/workflow/machines/mutable_side_effect_state_machine.rs +0 -127
  296. data/bridge/sdk-core/core/src/worker/workflow/machines/side_effect_state_machine.rs +0 -71
  297. data/bridge/sdk-core/protos/api_upstream/temporal/api/cluster/v1/message.proto +0 -83
  298. data/bridge/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +0 -210
  299. data/bridge/sdk-core/sdk/src/conversions.rs +0 -8
  300. data/lib/bridge.so +0 -0
  301. data/lib/gen/temporal/api/cluster/v1/message_pb.rb +0 -67
  302. data/lib/gen/temporal/api/enums/v1/cluster_pb.rb +0 -26
  303. data/lib/gen/temporal/sdk/core/bridge/bridge_pb.rb +0 -222
  304. data/lib/temporal/bridge.rb +0 -14
  305. data/lib/temporal/connection.rb +0 -736
  306. data/lib/temporal/failure_converter.rb +0 -8
  307. data/lib/temporal/payload_converter.rb +0 -14
  308. data/lib/temporal/runtime.rb +0 -22
  309. data/lib/temporal/version.rb +0 -3
  310. data/lib/temporal.rb +0 -8
@@ -1,38 +1,113 @@
1
- use super::TELEM_SERVICE_NAME;
2
- use crate::telemetry::GLOBAL_TELEM_DAT;
3
- use opentelemetry::sdk::metrics::aggregators::Aggregator;
4
- use opentelemetry::sdk::metrics::sdk_api::{Descriptor, InstrumentKind};
1
+ use crate::telemetry::TelemetryInstance;
5
2
  use opentelemetry::{
6
- global,
7
- metrics::{Counter, Histogram, Meter},
3
+ metrics::{noop::NoopMeterProvider, Counter, Histogram, Meter, MeterProvider},
8
4
  sdk::{
9
5
  export::metrics::AggregatorSelector,
10
- metrics::aggregators::{histogram, last_value, sum},
6
+ metrics::{
7
+ aggregators::{histogram, last_value, sum, Aggregator},
8
+ sdk_api::{Descriptor, InstrumentKind},
9
+ },
11
10
  },
12
11
  Context, KeyValue,
13
12
  };
14
- use std::{sync::Arc, time::Duration};
13
+ use std::{ops::Deref, sync::Arc, time::Duration};
14
+ use temporal_client::ClientMetricProvider;
15
15
 
16
16
  /// Used to track context associated with metrics, and record/update them
17
17
  ///
18
18
  /// Possible improvement: make generic over some type tag so that methods are only exposed if the
19
19
  /// appropriate k/vs have already been set.
20
- #[derive(Default, Clone, Debug)]
20
+ #[derive(Clone)]
21
21
  pub(crate) struct MetricsContext {
22
22
  ctx: Context,
23
23
  kvs: Arc<Vec<KeyValue>>,
24
+ instruments: Arc<Instruments>,
25
+ }
26
+
27
+ /// Wraps OTel's [Meter] to ensure we name our metrics properly, or any other temporal-specific
28
+ /// metrics customizations
29
+ #[derive(derive_more::Constructor)]
30
+ pub struct TemporalMeter<'a> {
31
+ inner: &'a Meter,
32
+ metrics_prefix: &'static str,
33
+ }
34
+
35
+ impl<'a> TemporalMeter<'a> {
36
+ pub(crate) fn counter(&self, name: &'static str) -> Counter<u64> {
37
+ self.inner
38
+ .u64_counter(self.metrics_prefix.to_string() + name)
39
+ .init()
40
+ }
41
+
42
+ pub(crate) fn histogram(&self, name: &'static str) -> Histogram<u64> {
43
+ self.inner
44
+ .u64_histogram(self.metrics_prefix.to_string() + name)
45
+ .init()
46
+ }
47
+ }
48
+
49
+ impl<'a> ClientMetricProvider for TemporalMeter<'a> {
50
+ fn counter(&self, name: &'static str) -> Counter<u64> {
51
+ self.counter(name)
52
+ }
53
+
54
+ fn histogram(&self, name: &'static str) -> Histogram<u64> {
55
+ self.histogram(name)
56
+ }
57
+ }
58
+
59
+ impl<'a> Deref for TemporalMeter<'a> {
60
+ type Target = dyn ClientMetricProvider + 'a;
61
+
62
+ fn deref(&self) -> &Self::Target {
63
+ self as &Self::Target
64
+ }
65
+ }
66
+
67
+ struct Instruments {
68
+ wf_completed_counter: Counter<u64>,
69
+ wf_canceled_counter: Counter<u64>,
70
+ wf_failed_counter: Counter<u64>,
71
+ wf_cont_counter: Counter<u64>,
72
+ wf_e2e_latency: Histogram<u64>,
73
+ wf_task_queue_poll_empty_counter: Counter<u64>,
74
+ wf_task_queue_poll_succeed_counter: Counter<u64>,
75
+ wf_task_execution_failure_counter: Counter<u64>,
76
+ wf_task_sched_to_start_latency: Histogram<u64>,
77
+ wf_task_replay_latency: Histogram<u64>,
78
+ wf_task_execution_latency: Histogram<u64>,
79
+ act_poll_no_task: Counter<u64>,
80
+ act_task_received_counter: Counter<u64>,
81
+ act_execution_failed: Counter<u64>,
82
+ act_sched_to_start_latency: Histogram<u64>,
83
+ act_exec_latency: Histogram<u64>,
84
+ worker_registered: Counter<u64>,
85
+ num_pollers: Histogram<u64>,
86
+ task_slots_available: Histogram<u64>,
87
+ sticky_cache_hit: Counter<u64>,
88
+ sticky_cache_miss: Counter<u64>,
89
+ sticky_cache_size: Histogram<u64>,
24
90
  }
25
91
 
26
92
  impl MetricsContext {
27
- fn new(kvs: Vec<KeyValue>) -> Self {
93
+ pub(crate) fn no_op() -> Self {
28
94
  Self {
29
- ctx: Context::current(),
30
- kvs: Arc::new(kvs),
95
+ ctx: Default::default(),
96
+ kvs: Default::default(),
97
+ instruments: Arc::new(Instruments::new_explicit(TemporalMeter::new(
98
+ &NoopMeterProvider::new().meter("fakemeter"),
99
+ "fakemetrics",
100
+ ))),
31
101
  }
32
102
  }
33
103
 
34
- pub(crate) fn top_level(namespace: String) -> Self {
35
- Self::new(vec![KeyValue::new(KEY_NAMESPACE, namespace)])
104
+ pub(crate) fn top_level(namespace: String, telemetry: &TelemetryInstance) -> Self {
105
+ let kvs = vec![KeyValue::new(KEY_NAMESPACE, namespace)];
106
+ Self {
107
+ ctx: Context::current(),
108
+ kvs: Arc::new(kvs),
109
+ instruments: Arc::new(Instruments::new(telemetry)),
110
+ }
36
111
  }
37
112
 
38
113
  pub(crate) fn with_task_q(mut self, tq: String) -> Self {
@@ -47,155 +122,213 @@ impl MetricsContext {
47
122
  Self {
48
123
  ctx: Context::current(),
49
124
  kvs,
125
+ instruments: self.instruments.clone(),
50
126
  }
51
127
  }
52
128
 
53
129
  /// A workflow task queue poll succeeded
54
130
  pub(crate) fn wf_tq_poll_ok(&self) {
55
- WF_TASK_QUEUE_POLL_SUCCEED_COUNTER.add(&self.ctx, 1, &self.kvs);
131
+ self.instruments
132
+ .wf_task_queue_poll_succeed_counter
133
+ .add(&self.ctx, 1, &self.kvs);
56
134
  }
57
135
 
58
136
  /// A workflow task queue poll timed out / had empty response
59
137
  pub(crate) fn wf_tq_poll_empty(&self) {
60
- WF_TASK_QUEUE_POLL_EMPTY_COUNTER.add(&self.ctx, 1, &self.kvs);
138
+ self.instruments
139
+ .wf_task_queue_poll_empty_counter
140
+ .add(&self.ctx, 1, &self.kvs);
61
141
  }
62
142
 
63
143
  /// A workflow task execution failed
64
144
  pub(crate) fn wf_task_failed(&self) {
65
- WF_TASK_EXECUTION_FAILURE_COUNTER.add(&self.ctx, 1, &self.kvs);
145
+ self.instruments
146
+ .wf_task_execution_failure_counter
147
+ .add(&self.ctx, 1, &self.kvs);
66
148
  }
67
149
 
68
150
  /// A workflow completed successfully
69
151
  pub(crate) fn wf_completed(&self) {
70
- WF_COMPLETED_COUNTER.add(&self.ctx, 1, &self.kvs);
152
+ self.instruments
153
+ .wf_completed_counter
154
+ .add(&self.ctx, 1, &self.kvs);
71
155
  }
72
156
 
73
157
  /// A workflow ended cancelled
74
158
  pub(crate) fn wf_canceled(&self) {
75
- WF_CANCELED_COUNTER.add(&self.ctx, 1, &self.kvs);
159
+ self.instruments
160
+ .wf_canceled_counter
161
+ .add(&self.ctx, 1, &self.kvs);
76
162
  }
77
163
 
78
164
  /// A workflow ended failed
79
165
  pub(crate) fn wf_failed(&self) {
80
- WF_FAILED_COUNTER.add(&self.ctx, 1, &self.kvs);
166
+ self.instruments
167
+ .wf_failed_counter
168
+ .add(&self.ctx, 1, &self.kvs);
81
169
  }
82
170
 
83
171
  /// A workflow continued as new
84
172
  pub(crate) fn wf_continued_as_new(&self) {
85
- WF_CONT_COUNTER.add(&self.ctx, 1, &self.kvs);
173
+ self.instruments
174
+ .wf_cont_counter
175
+ .add(&self.ctx, 1, &self.kvs);
86
176
  }
87
177
 
88
178
  /// Record workflow total execution time in milliseconds
89
179
  pub(crate) fn wf_e2e_latency(&self, dur: Duration) {
90
- WF_E2E_LATENCY.record(&self.ctx, dur.as_millis() as u64, &self.kvs);
180
+ self.instruments
181
+ .wf_e2e_latency
182
+ .record(&self.ctx, dur.as_millis() as u64, &self.kvs);
91
183
  }
92
184
 
93
185
  /// Record workflow task schedule to start time in millis
94
186
  pub(crate) fn wf_task_sched_to_start_latency(&self, dur: Duration) {
95
- WF_TASK_SCHED_TO_START_LATENCY.record(&self.ctx, dur.as_millis() as u64, &self.kvs);
187
+ self.instruments.wf_task_sched_to_start_latency.record(
188
+ &self.ctx,
189
+ dur.as_millis() as u64,
190
+ &self.kvs,
191
+ );
96
192
  }
97
193
 
98
194
  /// Record workflow task execution time in milliseconds
99
195
  pub(crate) fn wf_task_latency(&self, dur: Duration) {
100
- WF_TASK_EXECUTION_LATENCY.record(&self.ctx, dur.as_millis() as u64, &self.kvs);
196
+ self.instruments.wf_task_execution_latency.record(
197
+ &self.ctx,
198
+ dur.as_millis() as u64,
199
+ &self.kvs,
200
+ );
101
201
  }
102
202
 
103
203
  /// Record time it takes to catch up on replaying a WFT
104
204
  pub(crate) fn wf_task_replay_latency(&self, dur: Duration) {
105
- WF_TASK_REPLAY_LATENCY.record(&self.ctx, dur.as_millis() as u64, &self.kvs);
205
+ self.instruments.wf_task_replay_latency.record(
206
+ &self.ctx,
207
+ dur.as_millis() as u64,
208
+ &self.kvs,
209
+ );
106
210
  }
107
211
 
108
212
  /// An activity long poll timed out
109
213
  pub(crate) fn act_poll_timeout(&self) {
110
- ACT_POLL_NO_TASK.add(&self.ctx, 1, &self.kvs);
214
+ self.instruments
215
+ .act_poll_no_task
216
+ .add(&self.ctx, 1, &self.kvs);
217
+ }
218
+
219
+ /// A count of activity tasks received
220
+ pub(crate) fn act_task_received(&self) {
221
+ self.instruments
222
+ .act_task_received_counter
223
+ .add(&self.ctx, 1, &self.kvs);
111
224
  }
112
225
 
113
226
  /// An activity execution failed
114
227
  pub(crate) fn act_execution_failed(&self) {
115
- ACT_EXECUTION_FAILED.add(&self.ctx, 1, &self.kvs);
228
+ self.instruments
229
+ .act_execution_failed
230
+ .add(&self.ctx, 1, &self.kvs);
116
231
  }
117
232
 
118
233
  /// Record activity task schedule to start time in millis
119
234
  pub(crate) fn act_sched_to_start_latency(&self, dur: Duration) {
120
- ACT_SCHED_TO_START_LATENCY.record(&self.ctx, dur.as_millis() as u64, &self.kvs);
235
+ self.instruments.act_sched_to_start_latency.record(
236
+ &self.ctx,
237
+ dur.as_millis() as u64,
238
+ &self.kvs,
239
+ );
121
240
  }
122
241
 
123
242
  /// Record time it took to complete activity execution, from the time core generated the
124
243
  /// activity task, to the time lang responded with a completion (failure or success).
125
244
  pub(crate) fn act_execution_latency(&self, dur: Duration) {
126
- ACT_EXEC_LATENCY.record(&self.ctx, dur.as_millis() as u64, &self.kvs);
245
+ self.instruments
246
+ .act_exec_latency
247
+ .record(&self.ctx, dur.as_millis() as u64, &self.kvs);
127
248
  }
128
249
 
129
250
  /// A worker was registered
130
251
  pub(crate) fn worker_registered(&self) {
131
- WORKER_REGISTERED.add(&self.ctx, 1, &self.kvs);
252
+ self.instruments
253
+ .worker_registered
254
+ .add(&self.ctx, 1, &self.kvs);
132
255
  }
133
256
 
134
257
  /// Record current number of available task slots. Context should have worker type set.
135
258
  pub(crate) fn available_task_slots(&self, num: usize) {
136
- TASK_SLOTS_AVAILABLE.record(&self.ctx, num as u64, &self.kvs)
259
+ self.instruments
260
+ .task_slots_available
261
+ .record(&self.ctx, num as u64, &self.kvs)
137
262
  }
138
263
 
139
264
  /// Record current number of pollers. Context should include poller type / task queue tag.
140
265
  pub(crate) fn record_num_pollers(&self, num: usize) {
141
- NUM_POLLERS.record(&self.ctx, num as u64, &self.kvs);
266
+ self.instruments
267
+ .num_pollers
268
+ .record(&self.ctx, num as u64, &self.kvs);
142
269
  }
143
270
 
144
271
  /// A workflow task found a cached workflow to run against
145
272
  pub(crate) fn sticky_cache_hit(&self) {
146
- STICKY_CACHE_HIT.add(&self.ctx, 1, &self.kvs);
273
+ self.instruments
274
+ .sticky_cache_hit
275
+ .add(&self.ctx, 1, &self.kvs);
147
276
  }
148
277
 
149
278
  /// A workflow task did not find a cached workflow
150
279
  pub(crate) fn sticky_cache_miss(&self) {
151
- STICKY_CACHE_MISS.add(&self.ctx, 1, &self.kvs);
280
+ self.instruments
281
+ .sticky_cache_miss
282
+ .add(&self.ctx, 1, &self.kvs);
152
283
  }
153
284
 
154
285
  /// Record current cache size (in number of wfs, not bytes)
155
286
  pub(crate) fn cache_size(&self, size: u64) {
156
- STICKY_CACHE_SIZE.record(&self.ctx, size, &self.kvs);
287
+ self.instruments
288
+ .sticky_cache_size
289
+ .record(&self.ctx, size, &self.kvs);
157
290
  }
158
291
  }
159
292
 
160
- lazy_static::lazy_static! {
161
- pub(crate) static ref METRIC_METER: Meter = {
162
- #[cfg(not(test))]
163
- if crate::telemetry::GLOBAL_TELEM_DAT.get().is_none() {
164
- panic!("Tried to use a metric but telemetry has not been initialized")
165
- }
166
- global::meter(TELEM_SERVICE_NAME)
167
- };
168
- }
169
- fn metric_prefix() -> &'static str {
170
- GLOBAL_TELEM_DAT
171
- .get()
172
- .map(|gtd| {
173
- if gtd.no_temporal_prefix_for_metrics {
174
- ""
175
- } else {
176
- "temporal_"
177
- }
178
- })
179
- .unwrap_or("")
180
- }
293
+ impl Instruments {
294
+ fn new(telem: &TelemetryInstance) -> Self {
295
+ let no_op_meter: Meter;
296
+ let meter = if let Some(meter) = telem.get_metric_meter() {
297
+ meter
298
+ } else {
299
+ no_op_meter = NoopMeterProvider::default().meter("no_op");
300
+ TemporalMeter::new(&no_op_meter, "fakemetrics")
301
+ };
302
+ Self::new_explicit(meter)
303
+ }
181
304
 
182
- /// Define a temporal metric. All metrics are kept private to this file, and should be accessed
183
- /// through functions on the [MetricsContext]
184
- macro_rules! tm {
185
- (ctr, $ident:ident, $name:expr) => {
186
- lazy_static::lazy_static! {
187
- static ref $ident: Counter<u64> = {
188
- METRIC_METER.u64_counter(metric_prefix().to_string() + $name).init()
189
- };
190
- }
191
- };
192
- (vr_u64, $ident:ident, $name:expr) => {
193
- lazy_static::lazy_static! {
194
- static ref $ident: Histogram<u64> = {
195
- METRIC_METER.u64_histogram(metric_prefix().to_string() + $name).init()
196
- };
305
+ fn new_explicit(meter: TemporalMeter) -> Self {
306
+ Self {
307
+ wf_completed_counter: meter.counter("workflow_completed"),
308
+ wf_canceled_counter: meter.counter("workflow_canceled"),
309
+ wf_failed_counter: meter.counter("workflow_failed"),
310
+ wf_cont_counter: meter.counter("workflow_continue_as_new"),
311
+ wf_e2e_latency: meter.histogram(WF_E2E_LATENCY_NAME),
312
+ wf_task_queue_poll_empty_counter: meter.counter("workflow_task_queue_poll_empty"),
313
+ wf_task_queue_poll_succeed_counter: meter.counter("workflow_task_queue_poll_succeed"),
314
+ wf_task_execution_failure_counter: meter.counter("workflow_task_execution_failed"),
315
+ wf_task_sched_to_start_latency: meter.histogram(WF_TASK_SCHED_TO_START_LATENCY_NAME),
316
+ wf_task_replay_latency: meter.histogram(WF_TASK_REPLAY_LATENCY_NAME),
317
+ wf_task_execution_latency: meter.histogram(WF_TASK_EXECUTION_LATENCY_NAME),
318
+ act_poll_no_task: meter.counter("activity_poll_no_task"),
319
+ act_task_received_counter: meter.counter("activity_task_received"),
320
+ act_execution_failed: meter.counter("activity_execution_failed"),
321
+ act_sched_to_start_latency: meter.histogram(ACT_SCHED_TO_START_LATENCY_NAME),
322
+ act_exec_latency: meter.histogram(ACT_EXEC_LATENCY_NAME),
323
+ // name kept as worker start for compat with old sdk / what users expect
324
+ worker_registered: meter.counter("worker_start"),
325
+ num_pollers: meter.histogram(NUM_POLLERS_NAME),
326
+ task_slots_available: meter.histogram(TASK_SLOTS_AVAILABLE_NAME),
327
+ sticky_cache_hit: meter.counter("sticky_cache_hit"),
328
+ sticky_cache_miss: meter.counter("sticky_cache_miss"),
329
+ sticky_cache_size: meter.histogram(STICKY_CACHE_SIZE_NAME),
197
330
  }
198
- };
331
+ }
199
332
  }
200
333
 
201
334
  const KEY_NAMESPACE: &str = "namespace";
@@ -204,6 +337,7 @@ const KEY_TASK_QUEUE: &str = "task_queue";
204
337
  const KEY_ACT_TYPE: &str = "activity_type";
205
338
  const KEY_POLLER_TYPE: &str = "poller_type";
206
339
  const KEY_WORKER_TYPE: &str = "worker_type";
340
+ const KEY_EAGER: &str = "eager";
207
341
 
208
342
  pub(crate) fn workflow_poller() -> KeyValue {
209
343
  KeyValue::new(KEY_POLLER_TYPE, "workflow_task")
@@ -224,85 +358,27 @@ pub(crate) fn workflow_type(ty: String) -> KeyValue {
224
358
  KeyValue::new(KEY_WF_TYPE, ty)
225
359
  }
226
360
  pub(crate) fn workflow_worker_type() -> KeyValue {
227
- KeyValue {
228
- key: opentelemetry::Key::from_static_str(KEY_WORKER_TYPE),
229
- value: opentelemetry::Value::String("WorkflowWorker".into()),
230
- }
361
+ KeyValue::new(KEY_WORKER_TYPE, "WorkflowWorker")
231
362
  }
232
363
  pub(crate) fn activity_worker_type() -> KeyValue {
233
- KeyValue {
234
- key: opentelemetry::Key::from_static_str(KEY_WORKER_TYPE),
235
- value: opentelemetry::Value::String("ActivityWorker".into()),
236
- }
364
+ KeyValue::new(KEY_WORKER_TYPE, "ActivityWorker")
237
365
  }
238
366
  pub(crate) fn local_activity_worker_type() -> KeyValue {
239
- KeyValue {
240
- key: opentelemetry::Key::from_static_str(KEY_WORKER_TYPE),
241
- value: opentelemetry::Value::String("LocalActivityWorker".into()),
242
- }
367
+ KeyValue::new(KEY_WORKER_TYPE, "LocalActivityWorker")
368
+ }
369
+ pub(crate) fn eager(is_eager: bool) -> KeyValue {
370
+ KeyValue::new(KEY_EAGER, is_eager)
243
371
  }
244
372
 
245
- tm!(ctr, WF_COMPLETED_COUNTER, "workflow_completed");
246
- tm!(ctr, WF_CANCELED_COUNTER, "workflow_canceled");
247
- tm!(ctr, WF_FAILED_COUNTER, "workflow_failed");
248
- tm!(ctr, WF_CONT_COUNTER, "workflow_continue_as_new");
249
373
  const WF_E2E_LATENCY_NAME: &str = "workflow_endtoend_latency";
250
- tm!(vr_u64, WF_E2E_LATENCY, WF_E2E_LATENCY_NAME);
251
-
252
- tm!(
253
- ctr,
254
- WF_TASK_QUEUE_POLL_EMPTY_COUNTER,
255
- "workflow_task_queue_poll_empty"
256
- );
257
- tm!(
258
- ctr,
259
- WF_TASK_QUEUE_POLL_SUCCEED_COUNTER,
260
- "workflow_task_queue_poll_succeed"
261
- );
262
- tm!(
263
- ctr,
264
- WF_TASK_EXECUTION_FAILURE_COUNTER,
265
- "workflow_task_execution_failed"
266
- );
267
374
  const WF_TASK_SCHED_TO_START_LATENCY_NAME: &str = "workflow_task_schedule_to_start_latency";
268
- tm!(
269
- vr_u64,
270
- WF_TASK_SCHED_TO_START_LATENCY,
271
- WF_TASK_SCHED_TO_START_LATENCY_NAME
272
- );
273
375
  const WF_TASK_REPLAY_LATENCY_NAME: &str = "workflow_task_replay_latency";
274
- tm!(vr_u64, WF_TASK_REPLAY_LATENCY, WF_TASK_REPLAY_LATENCY_NAME);
275
376
  const WF_TASK_EXECUTION_LATENCY_NAME: &str = "workflow_task_execution_latency";
276
- tm!(
277
- vr_u64,
278
- WF_TASK_EXECUTION_LATENCY,
279
- WF_TASK_EXECUTION_LATENCY_NAME
280
- );
281
-
282
- tm!(ctr, ACT_POLL_NO_TASK, "activity_poll_no_task");
283
- tm!(ctr, ACT_EXECUTION_FAILED, "activity_execution_failed");
284
- // Act task unregistered can't be known by core right now since it's not well defined as an
285
- // activity result. We could add a flag to the failed activity result if desired.
286
377
  const ACT_SCHED_TO_START_LATENCY_NAME: &str = "activity_schedule_to_start_latency";
287
- tm!(
288
- vr_u64,
289
- ACT_SCHED_TO_START_LATENCY,
290
- ACT_SCHED_TO_START_LATENCY_NAME
291
- );
292
378
  const ACT_EXEC_LATENCY_NAME: &str = "activity_execution_latency";
293
- tm!(vr_u64, ACT_EXEC_LATENCY, ACT_EXEC_LATENCY_NAME);
294
-
295
- // name kept as worker start for compat with old sdk / what users expect
296
- tm!(ctr, WORKER_REGISTERED, "worker_start");
297
379
  const NUM_POLLERS_NAME: &str = "num_pollers";
298
- tm!(vr_u64, NUM_POLLERS, NUM_POLLERS_NAME);
299
380
  const TASK_SLOTS_AVAILABLE_NAME: &str = "worker_task_slots_available";
300
- tm!(vr_u64, TASK_SLOTS_AVAILABLE, TASK_SLOTS_AVAILABLE_NAME);
301
-
302
- tm!(ctr, STICKY_CACHE_HIT, "sticky_cache_hit");
303
- tm!(ctr, STICKY_CACHE_MISS, "sticky_cache_miss");
304
381
  const STICKY_CACHE_SIZE_NAME: &str = "sticky_cache_size";
305
- tm!(vr_u64, STICKY_CACHE_SIZE, STICKY_CACHE_SIZE_NAME);
306
382
 
307
383
  /// Artisanal, handcrafted latency buckets for workflow e2e latency which should expose a useful
308
384
  /// set of buckets for < 1 day runtime workflows. Beyond that, this metric probably isn't very
@@ -335,15 +411,18 @@ static WF_TASK_MS_BUCKETS: &[f64] = &[1., 10., 20., 50., 100., 200., 500., 1000.
335
411
  static ACT_EXE_MS_BUCKETS: &[f64] = &[50., 100., 500., 1000., 5000., 10_000., 60_000.];
336
412
 
337
413
  /// Schedule-to-start latency buckets for both WFT and AT
338
- static TASK_SCHED_TO_START_MS_BUCKETS: &[f64] = &[100., 500., 1000., 5000., 10_000.];
414
+ static TASK_SCHED_TO_START_MS_BUCKETS: &[f64] =
415
+ &[100., 500., 1000., 5000., 10_000., 100_000., 1_000_000.];
339
416
 
340
417
  /// Default buckets. Should never really be used as they will be meaningless for many things, but
341
418
  /// broadly it's trying to represent latencies in millis.
342
419
  pub(super) static DEFAULT_MS_BUCKETS: &[f64] = &[50., 100., 500., 1000., 2500., 10_000.];
343
420
 
344
421
  /// Chooses appropriate aggregators for our metrics
345
- #[derive(Debug)]
346
- pub struct SDKAggSelector;
422
+ #[derive(Debug, Clone)]
423
+ pub struct SDKAggSelector {
424
+ pub metric_prefix: &'static str,
425
+ }
347
426
 
348
427
  impl AggregatorSelector for SDKAggSelector {
349
428
  fn aggregator_for(&self, descriptor: &Descriptor) -> Option<Arc<dyn Aggregator + Send + Sync>> {
@@ -355,7 +434,7 @@ impl AggregatorSelector for SDKAggSelector {
355
434
  if *descriptor.instrument_kind() == InstrumentKind::Histogram {
356
435
  let dname = descriptor
357
436
  .name()
358
- .strip_prefix(metric_prefix())
437
+ .strip_prefix(self.metric_prefix)
359
438
  .unwrap_or_else(|| descriptor.name());
360
439
  // Some recorders are just gauges
361
440
  match dname {