@temporalio/core-bridge 1.4.4 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +327 -419
- package/Cargo.toml +1 -1
- package/index.js +25 -2
- package/lib/errors.d.ts +22 -0
- package/lib/errors.js +65 -0
- package/lib/errors.js.map +1 -0
- package/lib/index.d.ts +440 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/package.json +11 -5
- package/releases/aarch64-apple-darwin/index.node +0 -0
- package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
- package/releases/x86_64-apple-darwin/index.node +0 -0
- package/releases/x86_64-pc-windows-msvc/index.node +0 -0
- package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
- package/sdk-core/.buildkite/docker/Dockerfile +1 -1
- package/sdk-core/.buildkite/docker/docker-compose.yaml +2 -2
- package/sdk-core/bridge-ffi/Cargo.toml +1 -1
- package/sdk-core/bridge-ffi/include/sdk-core-bridge.h +0 -25
- package/sdk-core/bridge-ffi/src/lib.rs +29 -108
- package/sdk-core/bridge-ffi/src/wrappers.rs +35 -25
- package/sdk-core/client/Cargo.toml +1 -1
- package/sdk-core/client/src/lib.rs +12 -20
- package/sdk-core/client/src/raw.rs +9 -8
- package/sdk-core/client/src/retry.rs +100 -23
- package/sdk-core/core/Cargo.toml +5 -5
- package/sdk-core/core/benches/workflow_replay.rs +13 -10
- package/sdk-core/core/src/abstractions.rs +22 -22
- package/sdk-core/core/src/core_tests/activity_tasks.rs +1 -1
- package/sdk-core/core/src/core_tests/local_activities.rs +228 -6
- package/sdk-core/core/src/core_tests/queries.rs +247 -89
- package/sdk-core/core/src/core_tests/workers.rs +2 -2
- package/sdk-core/core/src/core_tests/workflow_cancels.rs +1 -1
- package/sdk-core/core/src/core_tests/workflow_tasks.rs +46 -27
- package/sdk-core/core/src/lib.rs +139 -32
- package/sdk-core/core/src/replay/mod.rs +185 -41
- package/sdk-core/core/src/telemetry/log_export.rs +190 -0
- package/sdk-core/core/src/telemetry/metrics.rs +184 -139
- package/sdk-core/core/src/telemetry/mod.rs +296 -318
- package/sdk-core/core/src/telemetry/prometheus_server.rs +4 -3
- package/sdk-core/core/src/test_help/mod.rs +9 -7
- package/sdk-core/core/src/worker/activities/local_activities.rs +2 -1
- package/sdk-core/core/src/worker/activities.rs +40 -23
- package/sdk-core/core/src/worker/client/mocks.rs +1 -1
- package/sdk-core/core/src/worker/client.rs +30 -4
- package/sdk-core/core/src/worker/mod.rs +22 -18
- package/sdk-core/core/src/worker/workflow/driven_workflow.rs +10 -19
- package/sdk-core/core/src/worker/workflow/history_update.rs +99 -25
- package/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +1 -5
- package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +1 -5
- package/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +1 -5
- package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +1 -5
- package/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +1 -5
- package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +2 -6
- package/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +1 -5
- package/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +18 -21
- package/sdk-core/core/src/worker/workflow/machines/mod.rs +12 -38
- package/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +178 -0
- package/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +1 -5
- package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +1 -5
- package/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +1 -5
- package/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +8 -2
- package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +1 -5
- package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +232 -216
- package/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +1 -6
- package/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +4 -4
- package/sdk-core/core/src/worker/workflow/managed_run.rs +13 -5
- package/sdk-core/core/src/worker/workflow/mod.rs +61 -9
- package/sdk-core/core/src/worker/workflow/wft_poller.rs +2 -2
- package/sdk-core/core/src/worker/workflow/workflow_stream.rs +56 -11
- package/sdk-core/core-api/Cargo.toml +4 -3
- package/sdk-core/core-api/src/lib.rs +1 -43
- package/sdk-core/core-api/src/telemetry.rs +147 -0
- package/sdk-core/core-api/src/worker.rs +13 -0
- package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +1 -1
- package/sdk-core/histories/evict_while_la_running_no_interference-23_history.bin +0 -0
- package/sdk-core/histories/evict_while_la_running_no_interference-85_history.bin +0 -0
- package/sdk-core/protos/api_upstream/.github/CODEOWNERS +1 -1
- package/sdk-core/protos/api_upstream/buf.yaml +0 -3
- package/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +3 -7
- package/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +8 -0
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +1 -2
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +2 -0
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +3 -0
- package/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +13 -0
- package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +19 -59
- package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +0 -19
- package/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +108 -29
- package/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +1 -0
- package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +47 -8
- package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +15 -1
- package/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +2 -0
- package/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +8 -1
- package/sdk-core/sdk/src/interceptors.rs +36 -3
- package/sdk-core/sdk/src/lib.rs +7 -4
- package/sdk-core/sdk/src/workflow_context.rs +13 -2
- package/sdk-core/sdk-core-protos/src/history_builder.rs +47 -1
- package/sdk-core/sdk-core-protos/src/history_info.rs +22 -22
- package/sdk-core/sdk-core-protos/src/lib.rs +49 -27
- package/sdk-core/test-utils/Cargo.toml +1 -0
- package/sdk-core/test-utils/src/lib.rs +81 -29
- package/sdk-core/tests/integ_tests/metrics_tests.rs +37 -0
- package/sdk-core/tests/integ_tests/polling_tests.rs +0 -13
- package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +145 -4
- package/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +53 -0
- package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +106 -20
- package/sdk-core/tests/integ_tests/workflow_tests.rs +18 -8
- package/sdk-core/tests/main.rs +6 -4
- package/src/conversions.rs +52 -47
- package/src/errors.rs +28 -86
- package/src/helpers.rs +3 -4
- package/src/lib.rs +2 -2
- package/src/runtime.rs +132 -61
- package/src/testing.rs +7 -4
- package/src/worker.rs +67 -50
- package/ts/errors.ts +55 -0
- package/{index.d.ts → ts/index.ts} +121 -15
- package/sdk-core/core/src/log_export.rs +0 -62
- package/sdk-core/core/src/worker/workflow/machines/mutable_side_effect_state_machine.rs +0 -127
- package/sdk-core/core/src/worker/workflow/machines/side_effect_state_machine.rs +0 -71
- package/sdk-core/protos/api_upstream/temporal/api/cluster/v1/message.proto +0 -83
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/cluster.proto +0 -40
|
@@ -13,12 +13,12 @@ crate-type = ["staticlib"]
|
|
|
13
13
|
[dependencies]
|
|
14
14
|
lazy_static = "1.4"
|
|
15
15
|
libc = "0.2"
|
|
16
|
-
log = "0.4"
|
|
17
16
|
prost = "0.11"
|
|
18
17
|
temporal-sdk-core = { version = "0.1", path = "../core" }
|
|
19
18
|
temporal-sdk-core-api = { version = "0.1", path = "../core-api" }
|
|
20
19
|
temporal-sdk-core-protos = { version = "0.1", path = "../sdk-core-protos" }
|
|
21
20
|
tokio = "1"
|
|
21
|
+
tracing = "0.1"
|
|
22
22
|
|
|
23
23
|
[build-dependencies]
|
|
24
24
|
cbindgen = "0.24"
|
|
@@ -121,18 +121,6 @@ void tmprl_worker_shutdown(struct tmprl_worker_t *worker,
|
|
|
121
121
|
void *user_data,
|
|
122
122
|
tmprl_callback callback);
|
|
123
123
|
|
|
124
|
-
/**
|
|
125
|
-
* Initialize process-wide telemetry. Should only be called once, subsequent calls will be ignored
|
|
126
|
-
* by core.
|
|
127
|
-
*
|
|
128
|
-
* Unlike the other functions in this bridge, this blocks until initting is complete, as telemetry
|
|
129
|
-
* should typically be initialized before doing other work.
|
|
130
|
-
*
|
|
131
|
-
* Returns a byte array for a [InitResponse] protobuf message which must be freed via
|
|
132
|
-
* tmprl_bytes_free.
|
|
133
|
-
*/
|
|
134
|
-
const struct tmprl_bytes_t *tmprl_telemetry_init(const uint8_t *req_proto, size_t req_proto_len);
|
|
135
|
-
|
|
136
124
|
/**
|
|
137
125
|
* Initialize a client connection to the Temporal service.
|
|
138
126
|
*
|
|
@@ -234,16 +222,3 @@ void tmprl_request_workflow_eviction(struct tmprl_worker_t *worker,
|
|
|
234
222
|
size_t req_proto_len,
|
|
235
223
|
void *user_data,
|
|
236
224
|
tmprl_callback callback);
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Fetch buffered logs. Blocks until complete. This is still using the callback since we might
|
|
240
|
-
* reasonably change log fetching to be async in the future.
|
|
241
|
-
*
|
|
242
|
-
* The `req_proto` and `req_proto_len` represent a byte array for a
|
|
243
|
-
* [bridge::FetchBufferedLogsRequest] protobuf message. The callback is invoked on completion with
|
|
244
|
-
* a [bridge::FetchBufferedLogsResponse] protobuf message.
|
|
245
|
-
*/
|
|
246
|
-
void tmprl_fetch_buffered_logs(const uint8_t *req_proto,
|
|
247
|
-
size_t req_proto_len,
|
|
248
|
-
void *user_data,
|
|
249
|
-
tmprl_callback callback);
|
|
@@ -17,14 +17,9 @@ mod wrappers;
|
|
|
17
17
|
use bridge::{init_response, CreateWorkerRequest, InitResponse};
|
|
18
18
|
use prost::Message;
|
|
19
19
|
use std::sync::Arc;
|
|
20
|
-
use temporal_sdk_core::{
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
use temporal_sdk_core_api::Worker;
|
|
24
|
-
use temporal_sdk_core_protos::coresdk::{
|
|
25
|
-
bridge,
|
|
26
|
-
bridge::{CreateClientRequest, InitTelemetryRequest},
|
|
27
|
-
};
|
|
20
|
+
use temporal_sdk_core::{Client, ClientOptions, CoreRuntime, RetryClient};
|
|
21
|
+
use temporal_sdk_core_api::{telemetry::TelemetryOptions, Worker};
|
|
22
|
+
use temporal_sdk_core_protos::coresdk::{bridge, bridge::CreateClientRequest};
|
|
28
23
|
|
|
29
24
|
/// A set of bytes owned by Core. No fields within nor any bytes references must
|
|
30
25
|
/// ever be mutated outside of Core. This must always be passed to
|
|
@@ -151,7 +146,7 @@ lazy_static::lazy_static! {
|
|
|
151
146
|
/// currently OK, but that's an implementation detail.
|
|
152
147
|
pub struct tmprl_runtime_t {
|
|
153
148
|
// This is the same runtime shared with worker instances
|
|
154
|
-
|
|
149
|
+
core_runtime: Arc<CoreRuntime>,
|
|
155
150
|
}
|
|
156
151
|
|
|
157
152
|
/// Create a new runtime. The result is never null and must be freed via
|
|
@@ -160,11 +155,12 @@ pub struct tmprl_runtime_t {
|
|
|
160
155
|
pub extern "C" fn tmprl_runtime_new() -> *mut tmprl_runtime_t {
|
|
161
156
|
Box::into_raw(Box::new(tmprl_runtime_t {
|
|
162
157
|
// TODO(cretz): Options to configure thread pool?
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
158
|
+
core_runtime: Arc::new(
|
|
159
|
+
CoreRuntime::new(
|
|
160
|
+
TelemetryOptions::default(),
|
|
161
|
+
tokio::runtime::Builder::new_multi_thread(),
|
|
162
|
+
)
|
|
163
|
+
.expect("Core runtime must initialize"),
|
|
168
164
|
),
|
|
169
165
|
}))
|
|
170
166
|
}
|
|
@@ -182,7 +178,7 @@ pub extern "C" fn tmprl_runtime_free(runtime: *mut tmprl_runtime_t) {
|
|
|
182
178
|
/// A worker instance owned by Core. This must be passed to [tmprl_worker_shutdown]
|
|
183
179
|
/// when no longer in use which will free the resources.
|
|
184
180
|
pub struct tmprl_worker_t {
|
|
185
|
-
|
|
181
|
+
core_runtime: Arc<CoreRuntime>,
|
|
186
182
|
// We are not concerned with the overhead of dynamic dispatch at this time
|
|
187
183
|
worker: Arc<dyn Worker>,
|
|
188
184
|
}
|
|
@@ -240,7 +236,7 @@ pub extern "C" fn tmprl_worker_init(
|
|
|
240
236
|
};
|
|
241
237
|
let user_data = UserDataHandle(user_data);
|
|
242
238
|
match tmprl_worker_t::new(
|
|
243
|
-
runtime.
|
|
239
|
+
runtime.core_runtime.clone(),
|
|
244
240
|
client.client.clone(),
|
|
245
241
|
wrappers::WorkerConfig(req),
|
|
246
242
|
) {
|
|
@@ -287,7 +283,7 @@ pub extern "C" fn tmprl_worker_shutdown(
|
|
|
287
283
|
) {
|
|
288
284
|
let worker = unsafe { Box::from_raw(worker) };
|
|
289
285
|
let user_data = UserDataHandle(user_data);
|
|
290
|
-
worker.
|
|
286
|
+
worker.core_runtime.tokio_handle().spawn(async move {
|
|
291
287
|
worker.shutdown().await;
|
|
292
288
|
unsafe {
|
|
293
289
|
callback(user_data.into(), &*DEFAULT_SHUTDOWN_WORKER_RESPONSE_BYTES);
|
|
@@ -296,43 +292,6 @@ pub extern "C" fn tmprl_worker_shutdown(
|
|
|
296
292
|
});
|
|
297
293
|
}
|
|
298
294
|
|
|
299
|
-
/// Initialize process-wide telemetry. Should only be called once, subsequent calls will be ignored
|
|
300
|
-
/// by core.
|
|
301
|
-
///
|
|
302
|
-
/// Unlike the other functions in this bridge, this blocks until initting is complete, as telemetry
|
|
303
|
-
/// should typically be initialized before doing other work.
|
|
304
|
-
///
|
|
305
|
-
/// Returns a byte array for a [InitResponse] protobuf message which must be freed via
|
|
306
|
-
/// tmprl_bytes_free.
|
|
307
|
-
#[no_mangle]
|
|
308
|
-
pub extern "C" fn tmprl_telemetry_init(
|
|
309
|
-
req_proto: *const u8,
|
|
310
|
-
req_proto_len: libc::size_t,
|
|
311
|
-
) -> *const tmprl_bytes_t {
|
|
312
|
-
let req = match tmprl_worker_t::decode_proto::<InitTelemetryRequest>(req_proto, req_proto_len) {
|
|
313
|
-
Ok(req) => req,
|
|
314
|
-
Err(message) => {
|
|
315
|
-
let resp = InitResponse {
|
|
316
|
-
error: Some(init_response::Error { message }),
|
|
317
|
-
};
|
|
318
|
-
return tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw();
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
match wrappers::InitTelemetryRequest(req)
|
|
323
|
-
.try_into()
|
|
324
|
-
.map(|opts| telemetry_init(&opts))
|
|
325
|
-
{
|
|
326
|
-
Ok(_) => &*DEFAULT_INIT_RESPONSE_BYTES,
|
|
327
|
-
Err(message) => {
|
|
328
|
-
let resp = InitResponse {
|
|
329
|
-
error: Some(init_response::Error { message }),
|
|
330
|
-
};
|
|
331
|
-
tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw()
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
295
|
/// A client instance owned by Core. This must be passed to [tmprl_client_free]
|
|
337
296
|
/// when no longer in use which will free the resources.
|
|
338
297
|
pub struct tmprl_client_t {
|
|
@@ -396,7 +355,7 @@ pub extern "C" fn tmprl_client_init(
|
|
|
396
355
|
};
|
|
397
356
|
|
|
398
357
|
let user_data = UserDataHandle(user_data);
|
|
399
|
-
runtime.
|
|
358
|
+
runtime.core_runtime.tokio_handle().spawn(async move {
|
|
400
359
|
match req.connect(namespace, None, None).await {
|
|
401
360
|
Ok(client) => unsafe {
|
|
402
361
|
callback(
|
|
@@ -449,7 +408,7 @@ pub extern "C" fn tmprl_poll_workflow_activation(
|
|
|
449
408
|
) {
|
|
450
409
|
let worker = unsafe { &mut *worker };
|
|
451
410
|
let user_data = UserDataHandle(user_data);
|
|
452
|
-
worker.
|
|
411
|
+
worker.core_runtime.tokio_handle().spawn(async move {
|
|
453
412
|
let resp = bridge::PollWorkflowActivationResponse {
|
|
454
413
|
response: Some(match worker.poll_workflow_activation().await {
|
|
455
414
|
Ok(act) => bridge::poll_workflow_activation_response::Response::Activation(act),
|
|
@@ -480,7 +439,7 @@ pub extern "C" fn tmprl_poll_activity_task(
|
|
|
480
439
|
) {
|
|
481
440
|
let worker = unsafe { &mut *worker };
|
|
482
441
|
let user_data = UserDataHandle(user_data);
|
|
483
|
-
worker.
|
|
442
|
+
worker.core_runtime.tokio_handle().spawn(async move {
|
|
484
443
|
let resp = bridge::PollActivityTaskResponse {
|
|
485
444
|
response: Some(match worker.poll_activity_task().await {
|
|
486
445
|
Ok(task) => bridge::poll_activity_task_response::Response::Task(task),
|
|
@@ -521,7 +480,7 @@ pub extern "C" fn tmprl_complete_workflow_activation(
|
|
|
521
480
|
}
|
|
522
481
|
};
|
|
523
482
|
let user_data = UserDataHandle(user_data);
|
|
524
|
-
worker.
|
|
483
|
+
worker.core_runtime.tokio_handle().spawn(async move {
|
|
525
484
|
match worker.complete_workflow_activation(req).await {
|
|
526
485
|
Ok(()) => unsafe {
|
|
527
486
|
callback(
|
|
@@ -567,7 +526,7 @@ pub extern "C" fn tmprl_complete_activity_task(
|
|
|
567
526
|
}
|
|
568
527
|
};
|
|
569
528
|
let user_data = UserDataHandle(user_data);
|
|
570
|
-
worker.
|
|
529
|
+
worker.core_runtime.tokio_handle().spawn(async move {
|
|
571
530
|
match worker.complete_activity_task(req).await {
|
|
572
531
|
Ok(()) => unsafe {
|
|
573
532
|
callback(
|
|
@@ -615,7 +574,7 @@ pub extern "C" fn tmprl_record_activity_heartbeat(
|
|
|
615
574
|
let user_data = UserDataHandle(user_data);
|
|
616
575
|
// We intentionally spawn even though the core call is not async so the
|
|
617
576
|
// callback can be made in the tokio runtime
|
|
618
|
-
worker.
|
|
577
|
+
worker.core_runtime.tokio_handle().spawn(async move {
|
|
619
578
|
worker.record_activity_heartbeat(req);
|
|
620
579
|
unsafe {
|
|
621
580
|
callback(
|
|
@@ -658,7 +617,7 @@ pub extern "C" fn tmprl_request_workflow_eviction(
|
|
|
658
617
|
let user_data = UserDataHandle(user_data);
|
|
659
618
|
// We intentionally spawn even though the core call is not async so the
|
|
660
619
|
// callback can be made in the tokio runtime
|
|
661
|
-
worker.
|
|
620
|
+
worker.core_runtime.tokio_handle().spawn(async move {
|
|
662
621
|
worker.request_workflow_eviction(req);
|
|
663
622
|
unsafe {
|
|
664
623
|
callback(
|
|
@@ -669,59 +628,19 @@ pub extern "C" fn tmprl_request_workflow_eviction(
|
|
|
669
628
|
});
|
|
670
629
|
}
|
|
671
630
|
|
|
672
|
-
/// Fetch buffered logs. Blocks until complete. This is still using the callback since we might
|
|
673
|
-
/// reasonably change log fetching to be async in the future.
|
|
674
|
-
///
|
|
675
|
-
/// The `req_proto` and `req_proto_len` represent a byte array for a
|
|
676
|
-
/// [bridge::FetchBufferedLogsRequest] protobuf message. The callback is invoked on completion with
|
|
677
|
-
/// a [bridge::FetchBufferedLogsResponse] protobuf message.
|
|
678
|
-
#[no_mangle]
|
|
679
|
-
pub extern "C" fn tmprl_fetch_buffered_logs(
|
|
680
|
-
#[allow(unused_variables)] // We intentionally ignore the request
|
|
681
|
-
req_proto: *const u8,
|
|
682
|
-
#[allow(unused_variables)] req_proto_len: libc::size_t,
|
|
683
|
-
user_data: *mut libc::c_void,
|
|
684
|
-
callback: tmprl_callback,
|
|
685
|
-
) {
|
|
686
|
-
let user_data = UserDataHandle(user_data);
|
|
687
|
-
// We intentionally spawn even though the core call is not async so the
|
|
688
|
-
// callback can be made in the tokio runtime
|
|
689
|
-
let resp = bridge::FetchBufferedLogsResponse {
|
|
690
|
-
entries: fetch_global_buffered_logs()
|
|
691
|
-
.into_iter()
|
|
692
|
-
.map(|log| bridge::fetch_buffered_logs_response::LogEntry {
|
|
693
|
-
message: log.message,
|
|
694
|
-
timestamp: Some(log.timestamp.into()),
|
|
695
|
-
level: match log.level {
|
|
696
|
-
log::Level::Error => bridge::LogLevel::Error.into(),
|
|
697
|
-
log::Level::Warn => bridge::LogLevel::Warn.into(),
|
|
698
|
-
log::Level::Info => bridge::LogLevel::Info.into(),
|
|
699
|
-
log::Level::Debug => bridge::LogLevel::Debug.into(),
|
|
700
|
-
log::Level::Trace => bridge::LogLevel::Trace.into(),
|
|
701
|
-
},
|
|
702
|
-
})
|
|
703
|
-
.collect(),
|
|
704
|
-
};
|
|
705
|
-
|
|
706
|
-
unsafe {
|
|
707
|
-
callback(
|
|
708
|
-
user_data.into(),
|
|
709
|
-
// TODO: Creates vec every time since no worker/core instance. Can be fixed with a
|
|
710
|
-
// pool if optimizations needed.
|
|
711
|
-
tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw(),
|
|
712
|
-
)
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
|
-
|
|
716
631
|
impl tmprl_worker_t {
|
|
717
632
|
fn new(
|
|
718
|
-
|
|
633
|
+
core_runtime: Arc<CoreRuntime>,
|
|
719
634
|
client: Arc<RetryClient<Client>>,
|
|
720
635
|
opts: wrappers::WorkerConfig,
|
|
721
636
|
) -> Result<tmprl_worker_t, String> {
|
|
637
|
+
let worker = Arc::new(
|
|
638
|
+
temporal_sdk_core::init_worker(&core_runtime, opts.try_into()?, client)
|
|
639
|
+
.map_err(|e| e.to_string())?,
|
|
640
|
+
);
|
|
722
641
|
Ok(tmprl_worker_t {
|
|
723
|
-
|
|
724
|
-
worker
|
|
642
|
+
core_runtime,
|
|
643
|
+
worker,
|
|
725
644
|
})
|
|
726
645
|
}
|
|
727
646
|
|
|
@@ -793,6 +712,8 @@ impl tmprl_worker_t {
|
|
|
793
712
|
self.worker.request_workflow_eviction(&req.run_id);
|
|
794
713
|
}
|
|
795
714
|
|
|
715
|
+
// TODO: Fetch logs
|
|
716
|
+
|
|
796
717
|
fn borrow_buf(&mut self) -> Vec<u8> {
|
|
797
718
|
// We currently do not use a thread-safe byte pool, but if wanted, it
|
|
798
719
|
// can be added here
|
|
@@ -1,40 +1,45 @@
|
|
|
1
|
-
use log::LevelFilter;
|
|
2
1
|
use std::{net::SocketAddr, str::FromStr};
|
|
3
|
-
use temporal_sdk_core::
|
|
4
|
-
|
|
2
|
+
use temporal_sdk_core::Url;
|
|
3
|
+
use temporal_sdk_core_api::telemetry::{
|
|
4
|
+
Logger, MetricsExporter, OtelCollectorOptions, TelemetryOptions, TelemetryOptionsBuilder,
|
|
5
|
+
TraceExportConfig, TraceExporter,
|
|
5
6
|
};
|
|
6
7
|
use temporal_sdk_core_protos::coresdk::bridge;
|
|
7
8
|
|
|
8
9
|
// Present for try-from only
|
|
9
10
|
pub struct InitTelemetryRequest(pub bridge::InitTelemetryRequest);
|
|
10
11
|
|
|
11
|
-
impl TryFrom<InitTelemetryRequest> for
|
|
12
|
+
impl TryFrom<InitTelemetryRequest> for TelemetryOptions {
|
|
12
13
|
type Error = String;
|
|
13
14
|
|
|
14
15
|
fn try_from(InitTelemetryRequest(req): InitTelemetryRequest) -> Result<Self, Self::Error> {
|
|
15
16
|
let mut telemetry_opts = TelemetryOptionsBuilder::default();
|
|
16
|
-
telemetry_opts.tracing_filter(req.tracing_filter.clone());
|
|
17
17
|
match req.logging {
|
|
18
18
|
None => {}
|
|
19
19
|
Some(bridge::init_telemetry_request::Logging::Console(_)) => {
|
|
20
|
-
telemetry_opts.logging(Logger::Console
|
|
20
|
+
telemetry_opts.logging(Logger::Console {
|
|
21
|
+
filter: req.tracing_filter.clone(),
|
|
22
|
+
});
|
|
21
23
|
}
|
|
22
24
|
Some(bridge::init_telemetry_request::Logging::Forward(
|
|
23
25
|
bridge::init_telemetry_request::ForwardLoggerOptions { level },
|
|
24
26
|
)) => {
|
|
25
|
-
if let Some(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
if let Some(_level) = bridge::LogLevel::from_i32(level) {
|
|
28
|
+
// TODO: This is ignored now, but I'm not fixing since we may never use this.
|
|
29
|
+
// let level = match level {
|
|
30
|
+
// bridge::LogLevel::Unspecified => {
|
|
31
|
+
// return Err("Must specify log level".to_string())
|
|
32
|
+
// }
|
|
33
|
+
// bridge::LogLevel::Off => LevelFilter::OFF,
|
|
34
|
+
// bridge::LogLevel::Error => LevelFilter::ERROR,
|
|
35
|
+
// bridge::LogLevel::Warn => LevelFilter::WARN,
|
|
36
|
+
// bridge::LogLevel::Info => LevelFilter::INFO,
|
|
37
|
+
// bridge::LogLevel::Debug => LevelFilter::DEBUG,
|
|
38
|
+
// bridge::LogLevel::Trace => LevelFilter::TRACE,
|
|
39
|
+
// };
|
|
40
|
+
telemetry_opts.logging(Logger::Forward {
|
|
41
|
+
filter: req.tracing_filter.clone(),
|
|
42
|
+
});
|
|
38
43
|
} else {
|
|
39
44
|
return Err(format!("Unknown LogLevel: {}", level));
|
|
40
45
|
}
|
|
@@ -60,6 +65,7 @@ impl TryFrom<InitTelemetryRequest> for temporal_sdk_core::TelemetryOptions {
|
|
|
60
65
|
format!("invalid OpenTelemetry collector URL for metrics: {}", err)
|
|
61
66
|
})?,
|
|
62
67
|
headers,
|
|
68
|
+
metric_periodicity: None,
|
|
63
69
|
}));
|
|
64
70
|
}
|
|
65
71
|
}
|
|
@@ -68,12 +74,16 @@ impl TryFrom<InitTelemetryRequest> for temporal_sdk_core::TelemetryOptions {
|
|
|
68
74
|
Some(bridge::init_telemetry_request::Tracing::OtelTracing(
|
|
69
75
|
bridge::init_telemetry_request::OtelCollectorOptions { url, headers },
|
|
70
76
|
)) => {
|
|
71
|
-
telemetry_opts.tracing(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
telemetry_opts.tracing(TraceExportConfig {
|
|
78
|
+
filter: req.tracing_filter.clone(),
|
|
79
|
+
exporter: TraceExporter::Otel(OtelCollectorOptions {
|
|
80
|
+
url: Url::parse(&url).map_err(|err| {
|
|
81
|
+
format!("invalid OpenTelemetry collector URL for tracing: {}", err)
|
|
82
|
+
})?,
|
|
83
|
+
headers,
|
|
84
|
+
metric_periodicity: None,
|
|
85
|
+
}),
|
|
86
|
+
});
|
|
77
87
|
}
|
|
78
88
|
}
|
|
79
89
|
|
|
@@ -46,13 +46,12 @@ use temporal_sdk_core_protos::{
|
|
|
46
46
|
coresdk::{workflow_commands::QueryResult, IntoPayloadsExt},
|
|
47
47
|
grpc::health::v1::health_client::HealthClient,
|
|
48
48
|
temporal::api::{
|
|
49
|
-
command::v1::Command,
|
|
50
49
|
common::v1::{Header, Payload, Payloads, WorkflowExecution, WorkflowType},
|
|
51
50
|
enums::v1::{TaskQueueKind, WorkflowIdReusePolicy, WorkflowTaskFailedCause},
|
|
52
51
|
failure::v1::Failure,
|
|
53
52
|
operatorservice::v1::operator_service_client::OperatorServiceClient,
|
|
54
53
|
query::v1::WorkflowQuery,
|
|
55
|
-
taskqueue::v1::
|
|
54
|
+
taskqueue::v1::TaskQueue,
|
|
56
55
|
testservice::v1::test_service_client::TestServiceClient,
|
|
57
56
|
workflowservice::v1::{workflow_service_client::WorkflowServiceClient, *},
|
|
58
57
|
},
|
|
@@ -181,6 +180,17 @@ impl RetryConfig {
|
|
|
181
180
|
}
|
|
182
181
|
}
|
|
183
182
|
|
|
183
|
+
pub(crate) const fn throttle_retry_policy() -> Self {
|
|
184
|
+
Self {
|
|
185
|
+
initial_interval: Duration::from_secs(1),
|
|
186
|
+
randomization_factor: 0.2,
|
|
187
|
+
multiplier: 2.0,
|
|
188
|
+
max_interval: Duration::from_secs(10),
|
|
189
|
+
max_elapsed_time: None,
|
|
190
|
+
max_retries: 0,
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
184
194
|
pub(crate) fn into_exp_backoff<C>(self, clock: C) -> exponential::ExponentialBackoff<C> {
|
|
185
195
|
exponential::ExponentialBackoff {
|
|
186
196
|
current_interval: self.initial_interval,
|
|
@@ -362,24 +372,6 @@ impl ClientOptions {
|
|
|
362
372
|
}
|
|
363
373
|
}
|
|
364
374
|
|
|
365
|
-
/// A version of [RespondWorkflowTaskCompletedRequest] that will finish being filled out by the
|
|
366
|
-
/// server client
|
|
367
|
-
#[derive(Debug, Clone, PartialEq)]
|
|
368
|
-
pub struct WorkflowTaskCompletion {
|
|
369
|
-
/// The task token that would've been received from polling for a workflow activation
|
|
370
|
-
pub task_token: TaskToken,
|
|
371
|
-
/// A list of new commands to send to the server, such as starting a timer.
|
|
372
|
-
pub commands: Vec<Command>,
|
|
373
|
-
/// If set, indicate that next task should be queued on sticky queue with given attributes.
|
|
374
|
-
pub sticky_attributes: Option<StickyExecutionAttributes>,
|
|
375
|
-
/// Responses to queries in the `queries` field of the workflow task.
|
|
376
|
-
pub query_responses: Vec<QueryResult>,
|
|
377
|
-
/// Indicate that the task completion should return a new WFT if one is available
|
|
378
|
-
pub return_new_workflow_task: bool,
|
|
379
|
-
/// Force a new WFT to be created after this completion
|
|
380
|
-
pub force_create_new_workflow_task: bool,
|
|
381
|
-
}
|
|
382
|
-
|
|
383
375
|
/// Interceptor which attaches common metadata (like "client-name") to every outgoing call
|
|
384
376
|
#[derive(Clone)]
|
|
385
377
|
pub struct ServiceCallInterceptor {
|
|
@@ -542,6 +542,15 @@ proxier! {
|
|
|
542
542
|
r.extensions_mut().insert(labels);
|
|
543
543
|
}
|
|
544
544
|
);
|
|
545
|
+
(
|
|
546
|
+
delete_workflow_execution,
|
|
547
|
+
DeleteWorkflowExecutionRequest,
|
|
548
|
+
DeleteWorkflowExecutionResponse,
|
|
549
|
+
|r| {
|
|
550
|
+
let labels = AttachMetricLabels::namespace(r.get_ref().namespace.clone());
|
|
551
|
+
r.extensions_mut().insert(labels);
|
|
552
|
+
}
|
|
553
|
+
);
|
|
545
554
|
(
|
|
546
555
|
list_open_workflow_executions,
|
|
547
556
|
ListOpenWorkflowExecutionsRequest,
|
|
@@ -808,17 +817,9 @@ proxier! {
|
|
|
808
817
|
r.extensions_mut().insert(labels);
|
|
809
818
|
}
|
|
810
819
|
);
|
|
811
|
-
(delete_workflow_execution, DeleteWorkflowExecutionRequest, DeleteWorkflowExecutionResponse,
|
|
812
|
-
|r| {
|
|
813
|
-
let labels = AttachMetricLabels::namespace(r.get_ref().namespace.clone());
|
|
814
|
-
r.extensions_mut().insert(labels);
|
|
815
|
-
}
|
|
816
|
-
);
|
|
817
820
|
(add_or_update_remote_cluster, AddOrUpdateRemoteClusterRequest, AddOrUpdateRemoteClusterResponse);
|
|
818
821
|
(remove_remote_cluster, RemoveRemoteClusterRequest, RemoveRemoteClusterResponse);
|
|
819
|
-
(describe_cluster, DescribeClusterRequest, DescribeClusterResponse);
|
|
820
822
|
(list_clusters, ListClustersRequest, ListClustersResponse);
|
|
821
|
-
(list_cluster_members, ListClusterMembersRequest, ListClusterMembersResponse);
|
|
822
823
|
}
|
|
823
824
|
|
|
824
825
|
proxier! {
|