-
Notifications
You must be signed in to change notification settings - Fork 85
Add access to upstreamfilterstate in WasmStateWrapper #394
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -348,32 +348,29 @@ WasmResult serializeValue(Filters::Common::Expr::CelValue value, std::string* re | |
| class WasmStateWrapper : public google::api::expr::runtime::CelMap { | ||
| public: | ||
| WasmStateWrapper(const StreamInfo::FilterState& filter_state, | ||
| const StreamInfo::FilterState* connection_filter_state) | ||
| : filter_state_(filter_state), connection_filter_state_(connection_filter_state) {} | ||
| WasmStateWrapper(const StreamInfo::FilterState& filter_state) | ||
| : filter_state_(filter_state), connection_filter_state_(nullptr) {} | ||
| const StreamInfo::FilterState* upstream_connection_filter_state) | ||
| : filter_state_(filter_state), | ||
| upstream_connection_filter_state_(upstream_connection_filter_state) {} | ||
| absl::optional<google::api::expr::runtime::CelValue> | ||
| operator[](google::api::expr::runtime::CelValue key) const override { | ||
| if (!key.IsString()) { | ||
| return {}; | ||
| } | ||
| auto value = key.StringOrDie().value(); | ||
| try { | ||
| if (filter_state_.hasData<WasmState>(value)) { | ||
| const WasmState& result = filter_state_.getDataReadOnly<WasmState>(value); | ||
| return google::api::expr::runtime::CelValue::CreateBytes(&result.value()); | ||
| } catch (const EnvoyException& e) { | ||
| // If doesn't exist in request filter state, try looking up in connection filter state. | ||
| try { | ||
| if (connection_filter_state_) { | ||
| const WasmState& result = connection_filter_state_->getDataReadOnly<WasmState>(value); | ||
| return google::api::expr::runtime::CelValue::CreateBytes(&result.value()); | ||
| } | ||
| } catch (const EnvoyException& e) { | ||
| return {}; | ||
| } | ||
| return {}; | ||
| } | ||
|
|
||
| if (upstream_connection_filter_state_ && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was the outcome of the discussion for the fallback of the filter state to upstream connection filter state?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think we discussed that...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a shared_ptr so the state will outlive the upstream connection. But we should be careful to clear it in the wasm context eventually.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My question was about filter_state itself falling through to upstream connection filter state. E.g. make it try HTTP, downstream TCP, then upstream TCP.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, didnt try to make filter_state itself fall through to upstream TCP
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Talked offline.. will simplify in a different pr.. |
||
| upstream_connection_filter_state_->hasData<WasmState>(value)) { | ||
| const WasmState& result = | ||
| upstream_connection_filter_state_->getDataReadOnly<WasmState>(value); | ||
| return google::api::expr::runtime::CelValue::CreateBytes(&result.value()); | ||
| } | ||
| return {}; | ||
| } | ||
|
|
||
| int size() const override { NOT_IMPLEMENTED_GCOVR_EXCL_LINE; } | ||
| bool empty() const override { NOT_IMPLEMENTED_GCOVR_EXCL_LINE; } | ||
| const google::api::expr::runtime::CelList* ListKeys() const override { | ||
|
|
@@ -382,7 +379,7 @@ class WasmStateWrapper : public google::api::expr::runtime::CelMap { | |
|
|
||
| private: | ||
| const StreamInfo::FilterState& filter_state_; | ||
| const StreamInfo::FilterState* connection_filter_state_; | ||
| const StreamInfo::FilterState* upstream_connection_filter_state_; | ||
| }; | ||
|
|
||
| #define PROPERTY_TOKENS(_f) \ | ||
|
|
@@ -423,14 +420,9 @@ Context::FindValue(absl::string_view name, Protobuf::Arena* arena) const { | |
| break; | ||
| case PropertyToken::FILTER_STATE: | ||
| if (info) { | ||
| const Envoy::Network::Connection* connection = getConnection(); | ||
| if (connection) { | ||
| return CelValue::CreateMap(Protobuf::Arena::Create<WasmStateWrapper>( | ||
| arena, info->filterState(), &connection->streamInfo().filterState())); | ||
| } else { | ||
| return CelValue::CreateMap( | ||
| Protobuf::Arena::Create<WasmStateWrapper>(arena, info->filterState())); | ||
| } | ||
|
|
||
| return CelValue::CreateMap(Protobuf::Arena::Create<WasmStateWrapper>( | ||
| arena, info->filterState(), info->upstreamFilterState().get())); | ||
| } | ||
| break; | ||
| case PropertyToken::REQUEST: | ||
|
|
@@ -1004,6 +996,10 @@ const Network::Connection* Context::getConnection() const { | |
| return encoder_callbacks_->connection(); | ||
| } else if (decoder_callbacks_) { | ||
| return decoder_callbacks_->connection(); | ||
| } else if (network_read_filter_callbacks_) { | ||
| return &network_read_filter_callbacks_->connection(); | ||
| } else if (network_write_filter_callbacks_) { | ||
| return &network_write_filter_callbacks_->connection(); | ||
| } | ||
| return nullptr; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this being upstreamed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will after getting feedback from our team...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jplevyak : John removed tcp proxy change her and added to envoy only first, will merge here after that... envoyproxy/envoy#9949
Can you please help merge this PR?