Add Sink concept plus a filesytem based implementation#624
Add Sink concept plus a filesytem based implementation#624mum4k merged 19 commits intoenvoyproxy:mainfrom
Conversation
This PR has Sink, MockSink, FileSinkImpl & tests. Sink will serve as a backing store for ExecutionResponse proto representations. Context: - Later on a new service will expose storage and lookup methods. - This in turn can be used in a horizontally scaled system as a means to realize a central point to transport results to and from. Part of the horizontal scaling effort. Split out from https://github.com/oschaaf/nighthawk/tree/horizontal-scaling Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
…sink Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
|
@eric846 please review and assign back to me once done. |
…sink Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
eric846
left a comment
There was a problem hiding this comment.
LGTM with some minor points that are all optional.
| namespace { | ||
|
|
||
| absl::Status verifyStringIsGuid(absl::string_view s) { | ||
| Envoy::Random::RandomGeneratorImpl random; |
There was a problem hiding this comment.
Is there a security or performance reason not to put a specific uuid format explicitly in the API contract and replace this logic with a regular expression?
There was a problem hiding this comment.
Well, my idea here is that the sink implementation will be the constraining factor when it comes to determining what is ok and not ok to specify for an execution_id. When initiating a load test, and not specifying an execution id, it will be auto-generated, and that will be a unique identifier.
In this file backed implementation I'm being a bit overly cautious, as a guid will have a reasonable length and contain no characters that would be illegal in a filename. I hope to find a way to easily validate a filename and make sure there's no weird stuff in it.
Later on it will also be possible to manually specify an execution id when initiating an execution, and that might be useful when you want an id that is more easily remembered. As it stands, this implementation will reject that.
test/common/sink_test.cc
Outdated
| nighthawk::client::ExecutionResponse result_to_store; | ||
| *(result_to_store.mutable_execution_id()) = this->executionIdForTest(); | ||
| absl::Status status = sink.StoreExecutionResultPiece(result_to_store); | ||
| ASSERT_EQ(status.ok(), true); |
There was a problem hiding this comment.
nit: If ASSERT_TRUE / ASSERT_FALSE are available, it seems more standard (here and below).
source/common/sink_impl.cc
Outdated
| std::ifstream ifs(it.path(), std::ios_base::binary); | ||
| if (!response.ParseFromIstream(&ifs)) { | ||
| return absl::Status(absl::StatusCode::kInternal, | ||
| fmt::format("Failure reading/parsing '{}'.", it.path())); |
There was a problem hiding this comment.
nit: It could be helpful for debugging to mention ExecutionResponse in this error message.
source/common/sink_impl.cc
Outdated
| FileSinkImpl::LoadExecutionResult(absl::string_view execution_id) const { | ||
| absl::Status status = verifyStringIsGuid(execution_id); | ||
| if (!status.ok()) { | ||
| return status; // |
There was a problem hiding this comment.
nit: Extraneous // or forgotten comment?
source/common/sink_impl.cc
Outdated
| { | ||
| std::ofstream ofs(name_buffer.data(), std::ios_base::out | std::ios_base::binary); | ||
| if (!response.SerializeToOstream(&ofs)) { | ||
| return absl::Status(absl::StatusCode::kNotFound, "Failure writing to temp file"); |
There was a problem hiding this comment.
Not sure if this is status code distinction is intentional.
|
|
||
| TEST(FileSinkTest, CorruptedFile) { | ||
| FileSinkImpl sink; | ||
| const std::string execution_id = "14e75b2a-3e31-4162-9279-add1e54091f9"; |
There was a problem hiding this comment.
Any reason not to use this->executionIdForTest() here?
There was a problem hiding this comment.
Well, this test is different from the others as it doesn't have a fixture. (it's not part of the TEST_P ones)
There was a problem hiding this comment.
Ohh I see. Do we need to clean up the directory separately here?
|
|
||
| template <typename T> class TypedSinkTest : public ::testing::Test { | ||
| public: | ||
| void SetUp() override { uuid_ = random_.uuid(); } |
There was a problem hiding this comment.
Could we automatically clean up "/tmp/nh/" + executionIdForTest() + "/" in TearDown? (if it makes sense)
There was a problem hiding this comment.
Done in 94f7299. It's a little odd to do it here, as this may execute for other sink implementations when the TEST_P suites iterate over their parameterization, and will not write files to that location. But cleaning up is rather nice, and this won't cause trouble.
So it seems pragmatic just add the two lines to clean up here.
…sink Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
|
Thanks for the review @eric846 |
Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
…sink Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
…sink Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
…sink Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
|
Thank you for amending the PR @oschaaf. Just one remaining question in the thread about validating UUIDs. |
Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
…sink Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
This PR has Sink, MockSink, FileSinkImpl & tests.
Sink will serve as a backing store for ExecutionResponse proto representations.
Context:
realize a central point to transport results to and from.
Part of the horizontal scaling effort.
Split out from https://github.com/oschaaf/nighthawk/tree/horizontal-scaling
Signed-off-by: Otto van der Schaaf ovanders@redhat.com