Skip to content

FilterState: WriteOnce and WriteMany support#4820

Merged
htuch merged 10 commits intoenvoyproxy:masterfrom
rshriram:write_many_filter_state
Oct 24, 2018
Merged

FilterState: WriteOnce and WriteMany support#4820
htuch merged 10 commits intoenvoyproxy:masterfrom
rshriram:write_many_filter_state

Conversation

@rshriram
Copy link
Copy Markdown
Member

Based on the discussions in this design doc:
https://docs.google.com/document/d/101Rcggh7flniYKgsr2T07yHXApywbnXiKj1hIpxX6yQ/edit#

Adds support for storing/retrieving mutable filter state objects, in addition to existing support for immutable filter state objects.

Signed-off-by: Shriram Rajagopalan shriramr@vmware.com

Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Comment thread include/envoy/stream_info/filter_state.h
Comment thread include/envoy/stream_info/filter_state.h
* immutable. This function will fail if the data stored under
* |data_name| cannot be dynamically cast to the type specified.
*/
template <typename T> T& getData(absl::string_view data_name) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to non-const ref/pointer of FilterState will be go here regardless of the data_name (and an exception will be thrown for immutable data), so this should be named differently than the const one above, name this mutableData?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the LHS doesn't matter at all?
const auto& foo = filterState.getData() ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, unless you cast filterState to const. i.e. static_cast<const FilterState&>(filterState).getData()

Shriram Rajagopalan added 3 commits October 22, 2018 22:58
…te_many_filter_state

Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
…te_many_filter_state

Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
@rshriram
Copy link
Copy Markdown
Member Author

I am mainly looking for feedback on whether these interfaces are acceptable. Will add the tests etc. once we agree on the interfaces.

@htuch htuch self-assigned this Oct 23, 2018
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a high-level this seems to match what we discussed last week, so it makes sense to me. I think @curiouserrandy might have a better reading of the interface changes.

Comment thread include/envoy/stream_info/filter_state.h
@htuch htuch requested a review from curiouserrandy October 23, 2018 03:44
Comment thread include/envoy/stream_info/filter_state.h
data_storage_[name] = std::move(data);

std::unique_ptr<FilterStateImpl::FilterObject> filter_object;
filter_object.reset(new FilterStateImpl::FilterObject());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: = make_unique and combine with one line above.

Shriram Rajagopalan added 2 commits October 23, 2018 23:37
…te_many_filter_state

Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
curiouserrandy
curiouserrandy previously approved these changes Oct 24, 2018
*/
virtual void setData(absl::string_view data_name, std::unique_ptr<Object>&& data) PURE;
virtual void setData(absl::string_view data_name, std::unique_ptr<Object>&& data,
StateType state_type) PURE;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My personal preference would be to have two separate interfaces rather than passing in an (effective) boolean (I think it'd be harder to mis-use and easier to audit if a company wanted to forbid one of them) but I am not dead-set on the idea.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping the enum would make things cleaner

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's equally clear if we have setDataImmutable and setDataMutable vs. having the enum. So, I'm on the fence on this one. The enum does support more dynamic reflective behavior, but I don't think that's a strong selling point here. The getters don't use an enum... should we be consistent in naming and signatures?

Comment thread include/envoy/stream_info/filter_state.h
Shriram Rajagopalan added 2 commits October 24, 2018 03:11
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
…te_many_filter_state

Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
lizan
lizan previously approved these changes Oct 24, 2018
Copy link
Copy Markdown
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I'm fine either way with the interface, defer to @htuch for that part.

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interface LGTM. Nice! Will defer to @htuch for complete review.

*/
class FilterState {
public:
enum StateType { ReadOnly, Mutable };
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: enum class

Shriram Rajagopalan added 2 commits October 24, 2018 19:15
nit
Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
…te_many_filter_state

Signed-off-by: Shriram Rajagopalan <shriramr@vmware.com>
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo setter vs. getter consistency comment.

*/
virtual void setData(absl::string_view data_name, std::unique_ptr<Object>&& data) PURE;
virtual void setData(absl::string_view data_name, std::unique_ptr<Object>&& data,
StateType state_type) PURE;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's equally clear if we have setDataImmutable and setDataMutable vs. having the enum. So, I'm on the fence on this one. The enum does support more dynamic reflective behavior, but I don't think that's a strong selling point here. The getters don't use an enum... should we be consistent in naming and signatures?

@rshriram
Copy link
Copy Markdown
Member Author

The getreadonly can get both mutable and immutable (so enum doesn't help here - stateType::ReadOnly looks odd). Also, setReadOnly and getReadOnly are not counter parts because I can get mutable as a readOnly object. The enum leaves the door open for more types in future IMO.

Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rshriram Thanks for the explanation. I'm still not sure what other types you would want to extend to, but I don't feel strongly enough either way to push this.

@htuch htuch merged commit 98d2fdc into envoyproxy:master Oct 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants