Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding proto only Request Source Config factory #560

Merged
merged 150 commits into from
Oct 22, 2020

Conversation

wjuan-AFK
Copy link
Contributor

This is a more usable version of the Request Source Config Factory similar to the FIle Based Config Factory which is easier to pass through the CLI.

Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
a global request generator.
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Adding comments.
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
…TestForRequestSourceFactory

Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
request source.
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
@wjuan-AFK wjuan-AFK added the waiting-for-review A PR waiting for a review. label Oct 9, 2020
@wjuan-AFK wjuan-AFK requested a review from eric846 October 9, 2020 16:22
@wjuan-AFK
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

🔨 rebuilding ci/circleci: clang_tidy (failed build)

🐱

Caused by: a #560 (comment) was created by @wjuan-AFK.

see: more, trace.

eric846
eric846 previously approved these changes Oct 13, 2020
Copy link
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

Copy link
Collaborator

@mum4k mum4k left a comment

Choose a reason for hiding this comment

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

Partial review.

// The pluginfactory will load the file located in file_path as long as it is below max_file_size,
// if it's too large it will throw an error.
// if it's too large it will throw an error. This field is optional with a default of 1000000.
Copy link
Collaborator

Choose a reason for hiding this comment

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

(pre-existing) Can we mention the unit? Is it bytes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

// Configuration for StubPluginRequestSource (plugin name: "nighthawk.stub-request-source-plugin")
// The plugin does nothing. This is for testing and comparison of the Request Source Plugin Factory
// mechanism using a minimal version of plugin that does not require a more complicated proto or
// file reading.
message StubPluginConfig {
// test input value which is the only output value in the headers produced from the
// requestGenerator for the StubRequestSource.
// requestGenerator for the StubRequestSource. This field is optional with a default of 0.
Copy link
Collaborator

Choose a reason for hiding this comment

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

(nit) Consider removing the comment addition here, since it falls into the a comment category that just "describes the language". It is obvious from the definition below that the field is optional and what its default value is.

The style guide gives some advice on how to write good comments:
https://google.github.io/styleguide/cppguide.html#Comments

A good advice to follow is to avoid writing comments about obvious things, or comments that just describe the language syntax. We should assume that the reader of the comments is familiar with the syntax and just provide comments on tricky parts or logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

std::string name() const override;
Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override;

// This implementation is not thread safe. There is a race condition because only the first call
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we have discussed this in one of the previous PRs. We shouldn't explain why it isn't thread safe as that is an implementation comment. Also the comment whether a class is or isn't thread safe belongs at class level, not method level.

Let's remove all this and instead add a single sentence at the end of the class docstring:

// This class is not thread safe.
class InLineOptionsListRequestSourceFactory : public virtual  {...}

Edit after looking at the current implementation - the class actually may be thread safe, because it uses a lock around this call, so that doesn't seem to be a race. However let's first discuss what we need as noted in the other comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was trying to add the clarification because of a discussion I had with Eric on this CL. I think the issue may be that I shouldn't be storing the value in the factory itself. I'm a little uncertain on this one. Essentially the problem that has resulted is that by storing the value in the factory itself, although in practice we will always get the same proto passed in from the CLI to each of the workers and thus to each call of the RequestSourcePluginConfigFactory, that technically creates a condition wherein, if multiple calls are made to the same factory with different protos, only the first one is acknowledged. In practice, as I say, this doesn't matter, but in theory this behaviour seems like some kind of race condition.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for the clarification, sounds like all we need to do is adjust the terminology. This class actually is thread-safe. Definition of race condition is clear - a code is racy when there are multiple threads accessing the same memory and at least one of them writes. Such situation isn't possible in this code, since we are using a lock. To address this - let's update the comment at the class level and say "This class is thread-safe".

As for the interesting behavior you are describing, for now we should just document it. Can you update the documentation so that it doesn't refer to a race condition and instead mentions that this function has a specific behavior on the first call? We can choose to remove the premature optimization in a later PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood.


private:
Envoy::Thread::MutexBasicLockable options_list_lock_;
absl::optional<nighthawk::client::RequestOptionsList> options_list_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this field need to be optional? When would we create an instance of InLineOptionsListRequestSourceFactory without an options_list_?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made this optional to indicate the state before and after having saved the options_list_.

Envoy::Http::RequestHeaderMapPtr header) override;

private:
Envoy::Thread::MutexBasicLockable options_list_lock_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we are saying the class is not thread safe, why do we need a lock? Once we proclaim it thread-unsafe, nobody should be calling it from multiple threads.

If we do include a lock, we should use it to its intended purpose which is to make the class thread safe. Maybe I am misunderstanding it, but looks like we are in a hybrid state where we do pay the cost of locking for no benefit.

Taking a step back, we should probably first agree whether we need this class to be thread safe. If you think we do, can you help by describing a scenario where this needs to be accessed by multiple threads? Once we understand that, we can discuss how to design it to be compatible with the intended use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be thread safe. Sorry for the confusion.

Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.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 Oct 21, 2020
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
@wjuan-AFK wjuan-AFK requested a review from mum4k October 22, 2020 05:05
@wjuan-AFK wjuan-AFK 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 Oct 22, 2020
Copy link
Collaborator

@mum4k mum4k left a comment

Choose a reason for hiding this comment

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

Looks good, can you please make sure the automated checks pass?

@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 Oct 22, 2020
@wjuan-AFK
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

🔨 rebuilding ci/circleci: clang_tidy (failed build)

🐱

Caused by: a #560 (comment) was created by @wjuan-AFK.

see: more, trace.

@wjuan-AFK wjuan-AFK 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 Oct 22, 2020
@mum4k mum4k merged commit 578c883 into envoyproxy:master Oct 22, 2020
dubious90 pushed a commit that referenced this pull request Nov 5, 2020
Commit to add RequestSourcePlugin option to the CLI. base PR: #560.
This is necessary to make use of the previous PRs adding the requestsourcepluginfactory via the CLI.

Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com>
@wjuan-AFK wjuan-AFK deleted the AddingProtoOnlyFactory branch June 9, 2021 15:27
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.

4 participants