Skip to content

Commit

Permalink
remove direction and error code
Browse files Browse the repository at this point in the history
  • Loading branch information
Thushani-Jayasekera committed May 31, 2024
1 parent e052193 commit a332025
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
24 changes: 3 additions & 21 deletions envoy-filters/mgw-source/filters/http/mgw-wasm-websocket/filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ using google::protobuf::util::JsonParseOptions;
using google::protobuf::util::Status;

using envoy::extensions::filters::http::mgw_wasm_websocket::v3::WebSocketFrameRequest;
using envoy::extensions::filters::http::mgw_wasm_websocket::v3::WebSocketFrameRequest_MessageDirection_HANDSHAKE;
using envoy::extensions::filters::http::mgw_wasm_websocket::v3::WebSocketFrameRequest_MessageDirection_PUBLISH;
using envoy::extensions::filters::http::mgw_wasm_websocket::v3::WebSocketFrameRequest_MessageDirection_SUBSCRIBE;
using envoy::extensions::filters::http::mgw_wasm_websocket::v3::WebSocketFrameResponse;
using envoy::extensions::filters::http::mgw_wasm_websocket::v3::Config;
using envoy::extensions::filters::http::mgw_wasm_websocket::v3::Metadata;
Expand Down Expand Up @@ -153,8 +150,7 @@ FilterHeadersStatus MgwWebSocketContext::onResponseHeaders(uint32_t, bool) {
// Read ext_authz_metadata_ metdata saved as a member variable
*request.mutable_metadata() = *this->metadata_;
request.set_payload("");
request.set_direction(WebSocketFrameRequest_MessageDirection_HANDSHAKE);
request.set_apim_error_code(0);
// TODO (thushani) set direction for analytics
sendEnforcerRequest(this, request);
}
}
Expand Down Expand Up @@ -183,25 +179,22 @@ FilterDataStatus MgwWebSocketContext::onRequestBody(size_t body_buffer_length,
// Read ext_authz_metadata_ metdata saved as a member variable
*request.mutable_metadata() = *this->metadata_;
request.set_payload(std::string(body->view()));
request.set_direction(WebSocketFrameRequest_MessageDirection_PUBLISH);
// TODO (thushani) set direction for analytics

// Perform throttling logic.
// If the throttle state is underlimit and if the gRPC stream is open, send WebSocketFrameRequest.
// If no gRPC stream, try to open a new stream and then send.
if(this->throttle_state_ == ThrottleState::UnderLimit){
request.set_apim_error_code(0);
sendEnforcerRequest(this, request);
return FilterDataStatus::Continue;
// If throttle state is FailureModeAllowed, then try to esatblish a new gRPC stream and
// pass the request to next filter. This state switch happens when the filter-enforcer connection fails.
}else if (this->throttle_state_ == ThrottleState::FailureModeAllowed){
request.set_apim_error_code(0);
sendEnforcerRequest(this, request);
return FilterDataStatus::Continue;
// If throttle state is FailureModeBlocked, then try to establish a new gRPC stream and
// stop interation. This state switch happens when the filter-enforcer connection fails.
}else if(this->throttle_state_ == ThrottleState::FailureModeBlocked){
request.set_apim_error_code(ENFORCER_NOT_REACHABLE_ERROR_CODE);
sendEnforcerRequest(this, request);
return FilterDataStatus::StopIterationNoBuffer;
// If throttle state is overlimit, then check the throttle period before making a decision.
Expand All @@ -216,11 +209,9 @@ FilterDataStatus MgwWebSocketContext::onRequestBody(size_t body_buffer_length,
if(this->throttle_period_ <= now.tv_sec){
this->throttle_state_ = ThrottleState::UnderLimit;
// publish to enforcer
request.set_apim_error_code(0);
sendEnforcerRequest(this, request);
return FilterDataStatus::Continue;
}else{
request.set_apim_error_code(this->apim_error_code_);
sendEnforcerRequest(this, request);
return FilterDataStatus::StopIterationNoBuffer;
}
Expand Down Expand Up @@ -258,25 +249,22 @@ FilterDataStatus MgwWebSocketContext::onResponseBody(size_t body_buffer_length,
// Read ext_authz_metadata_ metdata saved as a member variable
*request.mutable_metadata() = *this->metadata_;
request.set_payload(std::string(body->view()));
request.set_direction(WebSocketFrameRequest_MessageDirection_SUBSCRIBE);
// TODO (thushani) set direction for analytics

// Perform throttling logic.
// If the throttle state is underlimit and if the gRPC stream is open, send WebSocketFrameRequest.
// If no gRPC stream, try to open a new stream and then send.
if(this->throttle_state_ == ThrottleState::UnderLimit){
request.set_apim_error_code(0);
sendEnforcerRequest(this, request);
return FilterDataStatus::Continue;
// If throttle state is FailureModeAllowed, then try to esatblish a new gRPC stream and
// pass the request to next filter.
}else if (this->throttle_state_ == ThrottleState::FailureModeAllowed){
request.set_apim_error_code(0);
sendEnforcerRequest(this, request);
return FilterDataStatus::Continue;
// If throttle state is FailureModeBlocked, then try to establish a new gRPC stream and
// stop interation.
}else if(this->throttle_state_ == ThrottleState::FailureModeBlocked){
request.set_apim_error_code(ENFORCER_NOT_REACHABLE_ERROR_CODE);
sendEnforcerRequest(this, request);
return FilterDataStatus::StopIterationNoBuffer;
// If throttle state is overlimit, then check the throttle period before making a decision.
Expand All @@ -292,11 +280,9 @@ FilterDataStatus MgwWebSocketContext::onResponseBody(size_t body_buffer_length,
if(this->throttle_period_ <= now.tv_sec){
this->throttle_state_ = ThrottleState::UnderLimit;
// publish to enforcer
request.set_apim_error_code(0);
sendEnforcerRequest(this, request);
return FilterDataStatus::Continue;
}else{
request.set_apim_error_code(this->apim_error_code_);
sendEnforcerRequest(this, request);
return FilterDataStatus::StopIterationNoBuffer;
}
Expand Down Expand Up @@ -338,10 +324,6 @@ void MgwWebSocketContext::updateFilterState(ResponseStatus status){
}
}

void MgwWebSocketContext::updateAPIMErrorCode(int code) {
this->apim_error_code_ = code;
}

// Callback used by the handler to update the handler state reference in the filter.
void MgwWebSocketContext::updateHandlerState(HandlerState state){
LOG_TRACE(std::string("updateHandlerState ") + std::to_string(static_cast<int>(state)) + std::string(" : ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class MgwWebSocketContext : public Context ,
void updateFilterState(ResponseStatus status) override;
void updateHandlerState(HandlerState state) override;
void updateThrottlePeriod(const int throttle_period) override;
void updateAPIMErrorCode(int apim_error_code) override;
~MgwWebSocketContext() override;

private:
Expand Down

0 comments on commit a332025

Please sign in to comment.