From b610026dfc53a46f534b5689bbf28aef5564188a Mon Sep 17 00:00:00 2001 From: Leechael Yim Date: Wed, 28 May 2025 21:50:19 +0800 Subject: [PATCH] imp: code review feedback. --- gateway/src/proxy.rs | 6 +----- vmm/rpc/proto/vmm_rpc.proto | 6 +++++- vmm/src/main_service.rs | 16 +++++++--------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/gateway/src/proxy.rs b/gateway/src/proxy.rs index 28d4e251f..3501b7af9 100644 --- a/gateway/src/proxy.rs +++ b/gateway/src/proxy.rs @@ -73,11 +73,7 @@ fn parse_destination(sni: &str, dotted_base_domain: &str) -> Result { .strip_suffix(dotted_base_domain) .context("invalid sni format")?; if subdomain.contains('.') { - bail!( - "only one level of subdomain is supported: {}, {}", - sni, - subdomain - ); + bail!("only one level of subdomain is supported, got sni={sni}, subdomain={subdomain}"); } let mut parts = subdomain.split('-'); let app_id = parts.next().context("no app id found")?.to_owned(); diff --git a/vmm/rpc/proto/vmm_rpc.proto b/vmm/rpc/proto/vmm_rpc.proto index 1a258ab9a..b7dae1c0f 100644 --- a/vmm/rpc/proto/vmm_rpc.proto +++ b/vmm/rpc/proto/vmm_rpc.proto @@ -38,6 +38,10 @@ message Id { string id = 1; } +message ComposeHash { + string hash = 1; +} + // Message for creating a VM request message VmConfiguration { // Name of the VM @@ -232,7 +236,7 @@ service Vmm { // RPC to resize a VM rpc ResizeVm(ResizeVmRequest) returns (google.protobuf.Empty); // RPC to compute the compose hash, it's helpful for debugging & developing SDK. - rpc GetComposeHash(VmConfiguration) returns (AppId); + rpc GetComposeHash(VmConfiguration) returns (ComposeHash); // RPC to list all VMs rpc Status(StatusRequest) returns (StatusResponse); diff --git a/vmm/src/main_service.rs b/vmm/src/main_service.rs index ccfb4fd6b..7e41d98dd 100644 --- a/vmm/src/main_service.rs +++ b/vmm/src/main_service.rs @@ -6,10 +6,10 @@ use dstack_types::AppCompose; use dstack_vmm_rpc as rpc; use dstack_vmm_rpc::vmm_server::{VmmRpc, VmmServer}; use dstack_vmm_rpc::{ - AppId, GatewaySettings, GetInfoResponse, GetMetaResponse, Id, ImageInfo as RpcImageInfo, - ImageListResponse, KmsSettings, ListGpusResponse, PublicKeyResponse, ResizeVmRequest, - ResourcesSettings, StatusRequest, StatusResponse, UpgradeAppRequest, VersionResponse, - VmConfiguration, + AppId, ComposeHash as RpcComposeHash, GatewaySettings, GetInfoResponse, GetMetaResponse, Id, + ImageInfo as RpcImageInfo, ImageListResponse, KmsSettings, ListGpusResponse, + PublicKeyResponse, ResizeVmRequest, ResourcesSettings, StatusRequest, StatusResponse, + UpgradeAppRequest, VersionResponse, VmConfiguration, }; use fs_err as fs; use ra_rpc::{CallContext, RpcCall}; @@ -434,15 +434,13 @@ impl VmmRpc for RpcHandler { Ok(ListGpusResponse { gpus }) } - async fn get_compose_hash(self, request: VmConfiguration) -> Result { + async fn get_compose_hash(self, request: VmConfiguration) -> Result { validate_label(&request.name)?; // check the compose file is valid let _app_compose: AppCompose = serde_json::from_str(&request.compose_file).context("Invalid compose file")?; - let app_id = app_id_of(&request.compose_file); - Ok(AppId { - app_id: app_id.into(), - }) + let hash = hex_sha256(&request.compose_file); + Ok(RpcComposeHash { hash }) } }