Skip to content
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

Worker environment inheritance via RPC #587

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions golem-api-grpc/proto/golem/worker/invocation_context.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";

package golem.worker;

import "golem/worker/worker_id.proto";

message InvocationContext {
golem.worker.WorkerId parent = 1;
repeated string args = 3;
map<string, string> env = 4;
}
3 changes: 3 additions & 0 deletions golem-api-grpc/proto/golem/worker/worker_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import public "golem/worker/calling_convention.proto";
import public "golem/worker/complete_parameters.proto";
import public "golem/worker/cursor.proto";
import public "golem/worker/idempotency_key.proto";
import public "golem/worker/invocation_context.proto";
import public "golem/worker/invoke_parameters.proto";
import public "golem/worker/invoke_result.proto";
import public "golem/worker/invoke_result_json.proto";
Expand Down Expand Up @@ -105,6 +106,7 @@ message InvokeAndAwaitRequest {
string function = 3;
golem.worker.InvokeParameters invokeParameters = 4;
golem.worker.CallingConvention callingConvention = 5;
optional golem.worker.InvocationContext context = 6;
}

message InvokeAndAwaitResponse {
Expand All @@ -119,6 +121,7 @@ message InvokeRequest {
golem.worker.IdempotencyKey idempotencyKey = 2;
string function = 3;
golem.worker.InvokeParameters invokeParameters = 4;
optional golem.worker.InvocationContext context = 6;
}

message InvokeResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import public "golem/common/account_id.proto";
import public "golem/worker/calling_convention.proto";
import public "golem/common/empty.proto";
import public "golem/worker/idempotency_key.proto";
import public "golem/worker/invocation_context.proto";
import public "golem/worker/log_event.proto";
import public "golem/worker/promise_id.proto";
import public "golem/common/resource_limits.proto";
Expand Down Expand Up @@ -104,6 +105,7 @@ message InvokeAndAwaitWorkerRequest {
golem.worker.CallingConvention calling_convention = 5;
golem.common.AccountId account_id = 6;
golem.common.ResourceLimits account_limits = 7;
optional golem.worker.InvocationContext context = 8;
}

message InvokeAndAwaitWorkerResponse {
Expand All @@ -124,6 +126,7 @@ message InvokeWorkerRequest {
golem.worker.IdempotencyKey idempotency_key = 4;
golem.common.AccountId account_id = 5;
golem.common.ResourceLimits account_limits = 6;
optional golem.worker.InvocationContext context = 7;
}

message ConnectWorkerRequest {
Expand Down
3 changes: 3 additions & 0 deletions golem-common/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ pub struct WorkerMetadata {
pub env: Vec<(String, String)>,
pub account_id: AccountId,
pub created_at: Timestamp,
pub parent: Option<WorkerId>,
pub last_known_status: WorkerStatusRecord,
}

Expand All @@ -712,6 +713,7 @@ impl WorkerMetadata {
env: vec![],
account_id,
created_at: Timestamp::now_utc(),
parent: None,
last_known_status: WorkerStatusRecord::default(),
}
}
Expand Down Expand Up @@ -1962,6 +1964,7 @@ mod tests {
value: "account-1".to_string(),
},
created_at: Timestamp::now_utc(),
parent: None,
last_known_status: WorkerStatusRecord {
component_version: 1,
..WorkerStatusRecord::default()
Expand Down
3 changes: 3 additions & 0 deletions golem-common/src/model/oplog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ pub enum OplogEntry {
args: Vec<String>,
env: Vec<(String, String)>,
account_id: AccountId,
parent: Option<WorkerId>,
},
/// The worker invoked a host function
ImportedFunctionInvoked {
Expand Down Expand Up @@ -221,6 +222,7 @@ impl OplogEntry {
args: Vec<String>,
env: Vec<(String, String)>,
account_id: AccountId,
parent: Option<WorkerId>,
) -> OplogEntry {
OplogEntry::Create {
timestamp: Timestamp::now_utc(),
Expand All @@ -229,6 +231,7 @@ impl OplogEntry {
args,
env,
account_id,
parent,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ impl WorkerService for ForwardingWorkerService {
available_fuel: i64::MAX,
max_memory_per_worker: i64::MAX,
}),
context: request.context,
})
.await
.expect("Failed to call golem-worker-executor")
Expand Down Expand Up @@ -267,6 +268,7 @@ impl WorkerService for ForwardingWorkerService {
available_fuel: i64::MAX,
max_memory_per_worker: i64::MAX,
}),
context: request.context,
})
.await
.expect("Failed to call golem-worker-executor")
Expand Down
4 changes: 4 additions & 0 deletions golem-test-framework/src/dsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ impl<T: TestDependencies + Send + Sync> TestDsl for T {
invoke_parameters: Some(InvokeParameters {
params: params.into_iter().map(|v| v.into()).collect(),
}),
context: None,
})
.await;

Expand Down Expand Up @@ -361,6 +362,7 @@ impl<T: TestDependencies + Send + Sync> TestDsl for T {
invoke_parameters: Some(InvokeParameters {
params: params.into_iter().map(|v| v.into()).collect(),
}),
context: None,
})
.await;

Expand Down Expand Up @@ -480,6 +482,7 @@ impl<T: TestDependencies + Send + Sync> TestDsl for T {
params: params.into_iter().map(|v| v.into()).collect(),
}),
calling_convention: cc.into(),
context: None,
})
.await;

Expand Down Expand Up @@ -967,6 +970,7 @@ pub fn to_worker_metadata(
current_idempotency_key: None,
component_version: metadata.component_version,
},
parent: None,
}
}

Expand Down
10 changes: 9 additions & 1 deletion golem-worker-executor-base/src/durable_host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,15 @@ impl<Ctx: WorkerCtx + DurableWorkerCtxView<Ctx>> ExternalOperations<Ctx> for Dur

match decision {
RecoveryDecision::Immediate => {
let _ = Worker::get_or_create_running(this, &owned_worker_id).await?;
let _ = Worker::get_or_create_running(
this,
&owned_worker_id,
None,
None,
None,
None,
)
.await?;
}
RecoveryDecision::Delayed(_) => {
panic!("Delayed recovery on startup is not supported currently")
Expand Down
11 changes: 11 additions & 0 deletions golem-worker-executor-base/src/durable_host/wasm_rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use std::str::FromStr;
use tracing::{debug, error};
use uuid::Uuid;
use wasmtime::component::Resource;
use wasmtime_wasi::preview2::bindings::cli::environment::Host;

#[async_trait]
impl<Ctx: WorkerCtx> HostWasmRpc for DurableWorkerCtx<Ctx> {
Expand Down Expand Up @@ -84,6 +85,8 @@ impl<Ctx: WorkerCtx> HostWasmRpc for DurableWorkerCtx<Ctx> {
.await?;
let idempotency_key = IdempotencyKey::from_uuid(uuid);

let args = self.get_arguments().await?;
let env = self.get_environment().await?;
let result = Durability::<Ctx, WitValue, SerializableError>::wrap(
self,
WrappedFunctionType::WriteRemote,
Expand All @@ -96,6 +99,9 @@ impl<Ctx: WorkerCtx> HostWasmRpc for DurableWorkerCtx<Ctx> {
Some(idempotency_key),
function_name,
function_params,
ctx.worker_id(),
&args,
&env,
)
.await
})
Expand Down Expand Up @@ -145,6 +151,8 @@ impl<Ctx: WorkerCtx> HostWasmRpc for DurableWorkerCtx<Ctx> {
.await?;
let idempotency_key = IdempotencyKey::from_uuid(uuid);

let args = self.get_arguments().await?;
let env = self.get_environment().await?;
let result = Durability::<Ctx, (), SerializableError>::wrap(
self,
WrappedFunctionType::WriteRemote,
Expand All @@ -157,6 +165,9 @@ impl<Ctx: WorkerCtx> HostWasmRpc for DurableWorkerCtx<Ctx> {
Some(idempotency_key),
function_name,
function_params,
ctx.worker_id(),
&args,
&env,
)
.await
})
Expand Down
Loading
Loading