Skip to content

Add Sink concept plus a filesytem based implementation#624

Merged
mum4k merged 19 commits intoenvoyproxy:mainfrom
oschaaf:horizontal-scaling-sink
Mar 2, 2021
Merged

Add Sink concept plus a filesytem based implementation#624
mum4k merged 19 commits intoenvoyproxy:mainfrom
oschaaf:horizontal-scaling-sink

Conversation

@oschaaf
Copy link
Copy Markdown
Member

@oschaaf oschaaf commented Feb 6, 2021

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

Otto van der Schaaf added 7 commits February 6, 2021 20:22
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>
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>
@oschaaf oschaaf marked this pull request as ready for review February 13, 2021 22:17
@oschaaf oschaaf added the waiting-for-review A PR waiting for a review. label Feb 13, 2021
@mum4k mum4k requested a review from eric846 February 15, 2021 04:23
@mum4k
Copy link
Copy Markdown
Collaborator

mum4k commented Feb 15, 2021

@eric846 please review and assign back to me once done.

…sink

Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
eric846
eric846 previously approved these changes Feb 18, 2021
Copy link
Copy Markdown
Contributor

@eric846 eric846 left a comment

Choose a reason for hiding this comment

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

LGTM with some minor points that are all optional.

namespace {

absl::Status verifyStringIsGuid(absl::string_view s) {
Envoy::Random::RandomGeneratorImpl random;
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.

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?

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.

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.

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);
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.

nit: If ASSERT_TRUE / ASSERT_FALSE are available, it seems more standard (here and below).

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.

done: 00ebf87

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()));
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.

nit: It could be helpful for debugging to mention ExecutionResponse in this error message.

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.

done: 94f7299

FileSinkImpl::LoadExecutionResult(absl::string_view execution_id) const {
absl::Status status = verifyStringIsGuid(execution_id);
if (!status.ok()) {
return status; //
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.

nit: Extraneous // or forgotten comment?

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.

removed in 94f7299

{
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");
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.

Not sure if this is status code distinction is intentional.

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.

No it wasn't, good catch. Changed in 94f7299


TEST(FileSinkTest, CorruptedFile) {
FileSinkImpl sink;
const std::string execution_id = "14e75b2a-3e31-4162-9279-add1e54091f9";
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.

Any reason not to use this->executionIdForTest() here?

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.

Well, this test is different from the others as it doesn't have a fixture. (it's not part of the TEST_P ones)

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.

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(); }
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.

Could we automatically clean up "/tmp/nh/" + executionIdForTest() + "/" in TearDown? (if it makes sense)

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.

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.

Otto van der Schaaf added 3 commits February 18, 2021 20:54
…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>
@oschaaf
Copy link
Copy Markdown
Member Author

oschaaf commented Feb 18, 2021

Thanks for the review @eric846

Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
@mum4k mum4k added waiting-for-changes A PR waiting for comments to be resolved and changes to be applied. and removed waiting-for-review A PR waiting for a review. labels Feb 19, 2021
Otto van der Schaaf added 5 commits February 19, 2021 09:57
…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>
@oschaaf oschaaf added waiting-for-review A PR waiting for a review. and removed waiting-for-changes A PR waiting for comments to be resolved and changes to be applied. labels Feb 27, 2021
@mum4k
Copy link
Copy Markdown
Collaborator

mum4k commented Mar 1, 2021

Thank you for amending the PR @oschaaf. Just one remaining question in the thread about validating UUIDs.

@mum4k mum4k added waiting-for-changes A PR waiting for comments to be resolved and changes to be applied. and removed waiting-for-review A PR waiting for a review. labels Mar 1, 2021
Otto van der Schaaf added 2 commits March 2, 2021 10:36
Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
…sink

Signed-off-by: Otto van der Schaaf <ovanders@redhat.com>
@oschaaf oschaaf added waiting-for-review A PR waiting for a review. and removed waiting-for-changes A PR waiting for comments to be resolved and changes to be applied. labels Mar 2, 2021
@mum4k mum4k merged commit 261abb6 into envoyproxy:main Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-for-review A PR waiting for a review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants