From 07d07ba9c36d898f0af238167c5506716ddc56dc Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Tue, 3 Sep 2024 15:24:20 +0900 Subject: [PATCH] bug fix Signed-off-by: Kosuke Morimoto --- rust/bin/agent/src/handler/search.rs | 4 ++-- rust/bin/agent/src/main.rs | 28 ++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/rust/bin/agent/src/handler/search.rs b/rust/bin/agent/src/handler/search.rs index 8824a00ac65..06e072f0bfc 100644 --- a/rust/bin/agent/src/handler/search.rs +++ b/rust/bin/agent/src/handler/search.rs @@ -28,7 +28,6 @@ impl search_server::Search for super::Agent { &self, request: tonic::Request, ) -> Result, Status> { - println!("Recieved a request from {:?}", request.remote_addr()); let req = request.get_ref(); let config = req.config.clone().unwrap(); let hostname = cargo::util::hostname()?; @@ -37,7 +36,8 @@ impl search_server::Search for super::Agent { let err = Error::IncompatibleDimensionSize{ got: req.vector.len(), want: self.s.get_dimension_size()}; let mut err_details = ErrorDetails::new(); err_details.set_error_info(err.to_string(), domain, HashMap::new()); - err_details.set_request_info(config.request_id, String::from_utf8(req.encode_to_vec()).unwrap()); + let serving_data = ""; + err_details.set_request_info(config.request_id, serving_data.to_string()); err_details.set_bad_request(vec![FieldViolation::new("vector dimension size", err.to_string())]); err_details.set_resource_info(self.resource_type.clone() + "/ngt.Search", "", "", ""); let status = Status::with_error_details(Code::InvalidArgument, "Search API Incombatible Dimension Size detedted", err_details); diff --git a/rust/bin/agent/src/main.rs b/rust/bin/agent/src/main.rs index d8755fc3438..78a679e2b69 100644 --- a/rust/bin/agent/src/main.rs +++ b/rust/bin/agent/src/main.rs @@ -13,10 +13,12 @@ // See the License for the specific language governing permissions and // limitations under the License. // +use std::{thread::sleep, time::Duration}; use algorithm::Error; use anyhow::Result; -use proto::payload::v1::search; +use proto::{payload::v1::search, vald::v1::{search_client::SearchClient, search_server::SearchServer}}; +use tonic::transport::Server; mod handler; @@ -37,14 +39,28 @@ impl algorithm::ANN for MockService { #[tokio::main] async fn main() -> Result<(), Box> { - let addr = "0.0.0.0:8081".parse()?; + let addr = "[::1]:8081".parse().unwrap(); + let service = MockService{ dim: 42 }; let agent = handler::Agent::new(service, "agent-ngt", "127.0.0.1", "vald/internal/core/algorithm", "vald-agent"); - tonic::transport::Server::builder() - .add_service(proto::core::v1::agent_server::AgentServer::new(agent)) - .serve(addr) - .await?; + tokio::spawn(async move { + Server::builder() + .add_service(SearchServer::new(agent)) + .serve(addr) + .await + }); + + sleep(Duration::from_secs(3)); + + let mut client = SearchClient::connect("http://[::1]:8081").await?; + + let cfg = search::Config::default(); + let request = tonic::Request::new(search::Request { vector: vec![0.0], config: Some(cfg) }); + + let response = client.search(request).await?; + + println!("RESPONSE={:?}", response); Ok(()) }