Skip to content

Commit

Permalink
apply coderabbit suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
datelier committed Jan 22, 2025
1 parent d6f9cbc commit 259bae6
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 46 deletions.
31 changes: 22 additions & 9 deletions rust/bin/agent/src/handler/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@ impl insert_server::Insert for super::Agent {
) -> std::result::Result<tonic::Response<object::Location>, tonic::Status> {
println!("Recieved a request from {:?}", request.remote_addr());
let req = request.get_ref();
let config = req.config.clone().unwrap();
let config = match req.config.clone() {
Some(cfg) => cfg,
None => return Err(Status::invalid_argument("Missing configuration in request")),
};
let hostname = cargo::util::hostname()?;
let domain = hostname.to_str().unwrap();
{
let mut s = self.s.write().await;
let vec = req.vector.clone().unwrap();
let vec = match req.vector.clone() {
Some(v) => v,
None => return Err(Status::invalid_argument("Missing vector in request")),
};
if vec.vector.len() != s.get_dimension_size() {
let err = Error::IncompatibleDimensionSize {
got: vec.vector.len(),
Expand All @@ -47,8 +53,11 @@ impl insert_server::Insert for super::Agent {
let resource_type = self.resource_type.clone() + "/qbg.Insert";
let resource_name = format!("{}: {}({})", self.api_name, self.name, self.ip);
err_details.set_error_info(err.to_string(), domain, metadata);
err_details
.set_request_info(vec.id, String::from_utf8(req.encode_to_vec()).unwrap());
err_details.set_request_info(
vec.id,
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_bad_request(vec![FieldViolation::new(
"vector dimension size",
err.to_string(),
Expand All @@ -73,17 +82,19 @@ impl insert_server::Insert for super::Agent {
err_details.set_error_info(err.to_string(), domain, metadata);
err_details.set_request_info(
vec.id,
String::from_utf8(req.encode_to_vec()).unwrap(),
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_resource_info(resource_type, resource_name, "", "");
Status::with_error_details(Code::Aborted, "Insert API aborted to process insert request due to flushing indices is in progress", err_details)
}
Error::UUIDAlreadyExists { id: _ } => {
Error::UUIDAlreadyExists { uuid: _ } => {
let mut err_details = ErrorDetails::new();
err_details.set_error_info(err.to_string(), domain, metadata);
err_details.set_request_info(
vec.id.clone(),
String::from_utf8(req.encode_to_vec()).unwrap(),
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_resource_info(resource_type, resource_name, "", "");
Status::with_error_details(
Expand All @@ -97,7 +108,8 @@ impl insert_server::Insert for super::Agent {
err_details.set_error_info(err.to_string(), domain, metadata);
err_details.set_request_info(
vec.id.clone(),
String::from_utf8(req.encode_to_vec()).unwrap(),
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_bad_request(vec![FieldViolation::new(
"uuid",
Expand All @@ -118,7 +130,8 @@ impl insert_server::Insert for super::Agent {
err_details.set_error_info(err.to_string(), domain, metadata);
err_details.set_request_info(
vec.id,
String::from_utf8(req.encode_to_vec()).unwrap(),
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_resource_info(resource_type, resource_name, "", "");
Status::with_error_details(
Expand Down
10 changes: 7 additions & 3 deletions rust/bin/agent/src/handler/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ impl object_server::Object for super::Agent {
) -> std::result::Result<tonic::Response<object::Vector>, tonic::Status> {
println!("Recieved a request from {:?}", request.remote_addr());
let req = request.get_ref();
let id = req.id.clone().unwrap();
let uuid = id.id.clone();
let id = match req.id.clone() {
Some(id) => id,
None => return Err(Status::invalid_argument("Missing ID in request")),
};
let uuid = id.id;
let hostname = cargo::util::hostname()?;
let domain = hostname.to_str().unwrap();
{
Expand All @@ -49,7 +52,8 @@ impl object_server::Object for super::Agent {
err_details.set_error_info(err.to_string(), domain, metadata);
err_details.set_request_info(
uuid.clone(),
String::from_utf8(req.encode_to_vec()).unwrap(),
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_bad_request(vec![FieldViolation::new("uuid", err.to_string())]);
err_details.set_resource_info(resource_type, resource_name, "", "");
Expand Down
25 changes: 18 additions & 7 deletions rust/bin/agent/src/handler/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ impl remove_server::Remove for super::Agent {
) -> std::result::Result<tonic::Response<object::Location>, tonic::Status> {
println!("Recieved a request from {:?}", request.remote_addr());
let req = request.get_ref();
let config = req.config.clone().unwrap();
let id = req.id.clone().unwrap();
let config = match req.config.clone() {
Some(cfg) => cfg,
None => return Err(Status::invalid_argument("Missing configuration in request")),
};
let id = match req.id.clone() {
Some(id) => id,
None => return Err(Status::invalid_argument("Missing ID in request")),
};
let uuid = id.id;
let hostname = cargo::util::hostname()?;
let domain = hostname.to_str().unwrap();
Expand All @@ -47,7 +53,8 @@ impl remove_server::Remove for super::Agent {
err_details.set_error_info(err.to_string(), domain, metadata);
err_details.set_request_info(
uuid.clone(),
String::from_utf8(req.encode_to_vec()).unwrap(),
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_bad_request(vec![FieldViolation::new("uuid", err.to_string())]);
err_details.set_resource_info(resource_type, resource_name, "", "");
Expand All @@ -70,7 +77,8 @@ impl remove_server::Remove for super::Agent {
err_details.set_error_info(err.to_string(), domain, metadata);
err_details.set_request_info(
uuid,
String::from_utf8(req.encode_to_vec()).unwrap(),
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_resource_info(resource_type, resource_name, "", "");
Status::with_error_details(Code::Aborted, "Remove API aborted to process remove request due to flushing indices is in progress", err_details)
Expand All @@ -80,7 +88,8 @@ impl remove_server::Remove for super::Agent {
err_details.set_error_info(err.to_string(), domain, metadata);
err_details.set_request_info(
uuid.clone(),
String::from_utf8(req.encode_to_vec()).unwrap(),
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_resource_info(resource_type, resource_name, "", "");
Status::with_error_details(
Expand All @@ -94,7 +103,8 @@ impl remove_server::Remove for super::Agent {
err_details.set_error_info(err.to_string(), domain, metadata);
err_details.set_request_info(
uuid.clone(),
String::from_utf8(req.encode_to_vec()).unwrap(),
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_bad_request(vec![FieldViolation::new(
"uuid",
Expand All @@ -115,7 +125,8 @@ impl remove_server::Remove for super::Agent {
err_details.set_error_info(err.to_string(), domain, metadata);
err_details.set_request_info(
uuid,
String::from_utf8(req.encode_to_vec()).unwrap(),
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_resource_info(resource_type, resource_name, "", "");
Status::with_error_details(
Expand Down
23 changes: 16 additions & 7 deletions rust/bin/agent/src/handler/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ impl search_server::Search for super::Agent {
) -> Result<tonic::Response<search::Response>, Status> {
println!("Recieved a request from {:?}", request.remote_addr());
let req = request.get_ref();
let config = req.config.clone().unwrap();
let config = match req.config.clone() {
Some(cfg) => cfg,
None => return Err(Status::invalid_argument("Missing configuration in request")),
};
let hostname = cargo::util::hostname()?;
let domain = hostname.to_str().unwrap();
{
Expand All @@ -45,7 +48,8 @@ impl search_server::Search for super::Agent {
err_details.set_error_info(err.to_string(), domain, metadata);
err_details.set_request_info(
config.request_id,
String::from_utf8(req.encode_to_vec()).unwrap(),
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_bad_request(vec![FieldViolation::new(
"vector dimension size",
Expand Down Expand Up @@ -76,7 +80,8 @@ impl search_server::Search for super::Agent {
err_details.set_error_info(err.to_string(), domain, metadata);
err_details.set_request_info(
config.request_id,
String::from_utf8(req.encode_to_vec()).unwrap(),
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_resource_info(resource_type, resource_name, "", "");
Status::with_error_details(Code::Aborted, "Search API aborted to process search request due to creating indices is in progress", err_details)
Expand All @@ -86,7 +91,8 @@ impl search_server::Search for super::Agent {
err_details.set_error_info(err.to_string(), domain, metadata);
err_details.set_request_info(
config.request_id,
String::from_utf8(req.encode_to_vec()).unwrap(),
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_resource_info(resource_type, resource_name, "", "");
Status::with_error_details(Code::Aborted, "Search API aborted to process search request due to flushing indices is in progress", err_details)
Expand All @@ -97,7 +103,8 @@ impl search_server::Search for super::Agent {
err_details.set_error_info(err.to_string(), domain, metadata);
err_details.set_request_info(
&request_id,
String::from_utf8(req.encode_to_vec()).unwrap(),
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_resource_info(resource_type, resource_name, "", "");
Status::with_error_details(
Expand All @@ -114,7 +121,8 @@ impl search_server::Search for super::Agent {
err_details.set_error_info(err.to_string(), domain, metadata);
err_details.set_request_info(
config.request_id,
String::from_utf8(req.encode_to_vec()).unwrap(),
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_resource_info(resource_type, resource_name, "", "");
err_details.set_bad_request(vec![FieldViolation::new(
Expand All @@ -132,7 +140,8 @@ impl search_server::Search for super::Agent {
err_details.set_error_info(err.to_string(), domain, metadata);
err_details.set_request_info(
config.request_id,
String::from_utf8(req.encode_to_vec()).unwrap(),
String::from_utf8(req.encode_to_vec())
.unwrap_or_else(|_| "<invalid UTF-8>".to_string()),
);
err_details.set_resource_info(resource_type, resource_name, "", "");
Status::with_error_details(
Expand Down
Loading

0 comments on commit 259bae6

Please sign in to comment.