Refactoring the connection class to create buffers via factory#1234
Refactoring the connection class to create buffers via factory#1234mattklein123 merged 8 commits intoenvoyproxy:masterfrom
Conversation
Adding buffer factories for connection read/write buffers
mattklein123
left a comment
There was a problem hiding this comment.
overall very nice. Some quick comments. @dnoe can you also take a look at this one?
| virtual ~Factory() {} | ||
|
|
||
| /** | ||
| * Creates and returns a unique pointer to a new buffer. |
There was a problem hiding this comment.
nit: @return ... (trying to use doxygen for new stuff).
include/envoy/event/dispatcher.h
Outdated
| * Optionally sets a custom buffer factory for the dispatcher. This factory may be used by new | ||
| * connections on connection creation. | ||
| */ | ||
| virtual void setBufferFactory(Buffer::FactoryPtr&& factory) PURE; |
There was a problem hiding this comment.
Do you think it's worth having a setter on the interface? Seems like the factory could just be passed to the constructor of DispatcherImpl and then we avoid leaking the abstraction for changing it?
There was a problem hiding this comment.
This would allow changing the factory to one with different behavior at runtime, but I'm not sure if that would ever be useful.
There was a problem hiding this comment.
Ah, I thought it'd be useful for consistency but I'm happy to remove it - with a bit of test cleanup I don't think it needs to be set at runtime.
|
|
||
| class OwnedImplFactory : public Factory { | ||
| public: | ||
| InstancePtr create() override; |
There was a problem hiding this comment.
nit: // Buffer::Factory above this line.
include/envoy/event/dispatcher.h
Outdated
| virtual void setBufferFactory(Buffer::FactoryPtr&& factory) PURE; | ||
|
|
||
| /** | ||
| * Returns the buffer factory for this dispatcher. |
|
|
||
| Network::ListenerPtr listener = dispatcher.createSslListener( | ||
| connection_handler, *server_ctx, socket, listener_callbacks, stats_store, | ||
| void Initialize(uint32_t read_buffer_limit) { |
There was a problem hiding this comment.
nit: initialize (lower case)
test/mocks/buffer/mocks.h
Outdated
| MOCK_METHOD2(move, void(Instance& rhs, uint64_t length)); | ||
| MOCK_METHOD1(drain, void(uint64_t size)); | ||
|
|
||
| void BaseMove(Instance& rhs) { Buffer::OwnedImpl::move(rhs); } |
There was a problem hiding this comment.
nit: lower case for method name start all through this class.
There was a problem hiding this comment.
Ironically I reread the style guide before sending this one out but Google3 style habits are so hard to break :-P
|
|
||
| namespace Envoy { | ||
|
|
||
| class MockBuffer : public Buffer::OwnedImpl { |
test/mocks/buffer/mocks.h
Outdated
| return bytes_written; | ||
| } | ||
|
|
||
| int FailWrite(int) { |
There was a problem hiding this comment.
Is this called? Not quite sure how it works?
There was a problem hiding this comment.
It's used in the other CL to force writes to "fail" and data to be buffered in the connection (eventually going over watermarks).
I'll remove it from this one since it's not currently used.
There was a problem hiding this comment.
If it's meant for testing only the usual convention is to name the method something like failWriteForTest(). This doesn't appear to be in the style doc, I'll create a PR that mentions this convention.
include/envoy/event/dispatcher.h
Outdated
| * Optionally sets a custom buffer factory for the dispatcher. This factory may be used by new | ||
| * connections on connection creation. | ||
| */ | ||
| virtual void setBufferFactory(Buffer::FactoryPtr&& factory) PURE; |
There was a problem hiding this comment.
This would allow changing the factory to one with different behavior at runtime, but I'm not sure if that would ever be useful.
| // Network::BufferSource | ||
| Buffer::Instance& getReadBuffer() override { return read_buffer_; } | ||
| Buffer::Instance& getReadBuffer() override { return *read_buffer_; } | ||
| Buffer::Instance& getWriteBuffer() override { return *current_write_buffer_; } |
There was a problem hiding this comment.
There's both a write_buffer_ and a current_write_buffer_. write_buffer_ is initialized via factory, but current_write_buffer_ is not (in fact it looks to me like it's always nullptr, so this line seems especially odd). This isn't a line changed in this PR, but it would be good to clarify...
@mattklein123 any idea what current_write_buffer_ was supposed to be for?
There was a problem hiding this comment.
It's set in the cc file right before fitler_manager_.onWrite and cleared right after. There's a note that it's a bit of a hack to provide access under the stack of that call :-)
There was a problem hiding this comment.
Yeah, that whole situation is not great but per @alyssawilk the comment should have the details.
test/mocks/event/mocks.h
Outdated
| MOCK_METHOD1(post, void(std::function<void()> callback)); | ||
| MOCK_METHOD1(run, void(RunType type)); | ||
| Buffer::Factory& getBufferFactory() override { return *buffer_factory_; } | ||
| void setBufferFactory(Buffer::FactoryPtr&& factory) override { |
There was a problem hiding this comment.
Is this only needed for the tests?
dnoe
left a comment
There was a problem hiding this comment.
LGTM if @mattklein123 also approves
Automatic merge from submit-queue. Add notification for duplication **What this PR does / why we need it**: **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note ``` Add notification to match istio/istio#4358
Description: This tool was meant to be a bazel implementation detail so its public accessor was removed in bazelbuild/bazel@f8b51ff Using the cc API from bazel we can dynamically get this. This is still a bit of a hack because we're writing our own args for this. We might be able to fetch the args, based on bazel's crosstool, dynamically as well, but ideally we remove this rule instead. Fixes envoyproxy/envoy-mobile#1233 Signed-off-by: Keith Smiley <keithbsmiley@gmail.com> Signed-off-by: JP Simard <jp@jpsim.com>
Description: This tool was meant to be a bazel implementation detail so its public accessor was removed in bazelbuild/bazel@f8b51ff Using the cc API from bazel we can dynamically get this. This is still a bit of a hack because we're writing our own args for this. We might be able to fetch the args, based on bazel's crosstool, dynamically as well, but ideally we remove this rule instead. Fixes envoyproxy/envoy-mobile#1233 Signed-off-by: Keith Smiley <keithbsmiley@gmail.com> Signed-off-by: JP Simard <jp@jpsim.com>
**Description** This updates the Go version used here as well as some Go dependencies. --------- Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
This plus substantial refactors to the connection tests for code reuse, and some new tests using the new factories.
pulling this out from #1217 since it's well over 700 lines on its own.
Also did the read buffer along with the write buffer for consistency. Someone may need it some day and they shouldn't have to rewrite all the existing connection tests when they do.