Skip to content

Commit

Permalink
Handle failuremode in operation die
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Cattermole <acatterm@redhat.com>
  • Loading branch information
adam-cattermole committed Jan 16, 2025
1 parent faa0375 commit 8a76515
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/filter/kuadrant_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ impl KuadrantFilter {
let next_op = {
let (req, receiver_op) = sender_op.build_receiver_operation();
match self.send_grpc_request(req) {
Ok(_token) => receiver_op,
Ok(_token) => Operation::AwaitGrpcResponse(receiver_op),
Err(status) => {
debug!("handle_operation: failed to send grpc request `{status:?}`");
Operation::Die(GrpcErrResponse::new_internal_server_error())
receiver_op.fail()
}
}
};
Expand Down
25 changes: 16 additions & 9 deletions src/filter/operations.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::configuration::FailureMode;
use crate::filter::operations::Operation::SendGrpcRequest;
use crate::runtime_action_set::RuntimeActionSet;
use crate::service::{GrpcErrResponse, GrpcRequest, Headers, IndexedGrpcRequest};
Expand Down Expand Up @@ -28,14 +29,11 @@ impl GrpcMessageSenderOperation {
}
}

pub fn build_receiver_operation(self) -> (GrpcRequest, Operation) {
pub fn build_receiver_operation(self) -> (GrpcRequest, GrpcMessageReceiverOperation) {
let index = self.grpc_request.index();
(
self.grpc_request.request(),
Operation::AwaitGrpcResponse(GrpcMessageReceiverOperation::new(
self.runtime_action_set,
index,
)),
GrpcMessageReceiverOperation::new(self.runtime_action_set, index),
)
}
}
Expand Down Expand Up @@ -78,10 +76,19 @@ impl GrpcMessageReceiverOperation {
}

pub fn fail(self) -> Operation {
//todo(adam-cattermole): should this take into account failure mode?
// these errors occurred at filter layer,
// i.e. error response / failed to read buffer / failed serdes
Operation::Die(GrpcErrResponse::new_internal_server_error())
match self.runtime_action_set.runtime_actions[self.current_index].get_failure_mode() {
FailureMode::Deny => Operation::Die(GrpcErrResponse::new_internal_server_error()),
FailureMode::Allow => match self
.runtime_action_set
.find_next_grpc_request(self.current_index + 1)
{
None => Operation::Done(),
Some(indexed_req) => Operation::SendGrpcRequest(GrpcMessageSenderOperation::new(
self.runtime_action_set,
indexed_req,
)),
},
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime_action_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl RuntimeActionSet {
self.find_next_grpc_request(0)
}

fn find_next_grpc_request(&self, start: usize) -> Option<IndexedGrpcRequest> {
pub fn find_next_grpc_request(&self, start: usize) -> Option<IndexedGrpcRequest> {
self.runtime_actions
.iter()
.skip(start)
Expand Down

0 comments on commit 8a76515

Please sign in to comment.