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

Add a ThreadFactory class for creating threads #5055

Merged
merged 10 commits into from
Nov 20, 2018

Conversation

eziskind
Copy link
Contributor

@eziskind eziskind commented Nov 15, 2018

Description: This change modifies ApiImpl to delegate thread creation to a ThreadFactory instance and enables injecting a custom thread factory into the envoy server by wiring one in through MainCommonBase
Risk Level: low (mostly code refactoring)
Testing: unit and integration tests

Signed-off-by: Elisha Ziskind eziskind@google.com

This enables injecting a custom thread factory into the envoy server

Signed-off-by: Elisha Ziskind <eziskind@google.com>
@mattklein123
Copy link
Member

@jmarantz PTAL since you had concerns with our previous approach.

Signed-off-by: Elisha Ziskind <eziskind@google.com>
Signed-off-by: Elisha Ziskind <eziskind@google.com>
Signed-off-by: Elisha Ziskind <eziskind@google.com>
Signed-off-by: Elisha Ziskind <eziskind@google.com>
@eziskind
Copy link
Contributor Author

mac failure is a flake:
//test/integration:http2_upstream_integration_test FAILED in 2 out of 2 in 28.4s

Signed-off-by: Elisha Ziskind <eziskind@google.com>
@eziskind
Copy link
Contributor Author

Sigh, more flakes, under ipv6 this time:
//test/integration:header_integration_test FAILED in 4.0s
//test/integration:http2_integration_test FAILED in 18.2s

Copy link
Contributor

@jmarantz jmarantz left a comment

Choose a reason for hiding this comment

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

nice, thanks for doing this.

jmarantz
jmarantz previously approved these changes Nov 19, 2018
Signed-off-by: Elisha Ziskind <eziskind@google.com>
@mattklein123 mattklein123 self-assigned this Nov 20, 2018
Signed-off-by: Elisha Ziskind <eziskind@google.com>
Signed-off-by: Elisha Ziskind <eziskind@google.com>
mattklein123
mattklein123 previously approved these changes Nov 20, 2018
Copy link
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.

Thanks, LGTM. Optional name change suggestion.

Signed-off-by: Elisha Ziskind <eziskind@google.com>
@eziskind eziskind changed the title Add a ThreadSystem class for creating threads Add a ThreadFactory class for creating threads Nov 20, 2018
Copy link
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.

Thanks!

@mattklein123 mattklein123 merged commit 46e1411 into envoyproxy:master Nov 20, 2018
@eziskind eziskind deleted the threadfactory branch November 21, 2018 00:55
htuch pushed a commit that referenced this pull request Nov 21, 2018
For the record, I am against singletons in general, and believe it's more maintainable to pass context objects through the call/instantiation stack, as is done in Envoy production code. However the test system employs a deep system of mocks that are constructed without context. As a result, any new context that may be needed in the future (e.g. SymbolTable in #4980, ThreadSystem in #5055 and #5072 and FileSystem in #5031) need a mechanism to plumb data into the system as instantiated during tests. I believe Api::OsSysCalls() is another example that might benefit from this.

This class provides a mechanism to have a bounded-scope singleton, such that anywhere an instance of a type T is desired, the same instance will be available. Once all references to a Global go out of scope, the shared instance is destroyed and the pointer to it nulled.

Thus, this singleton pattern has the property that between tests, the state will be completely reset, as long as there are no memory leaks.

The new class, Test::Global, creates a potential conflict with tests that had declared using testing::Test;, so this PR also cleans those up and adds a format check to avoid having that pattern re-occur.

Risk Level: the main risk here is that this class will be abused and used in lieu of proper object passing when that's most appropriate. However, the new library is declared as a bazel test library and is in the test/... tree, so hopefully -- with proper code reviews, the usage will be limited.
Testing: //test/...

Signed-off-by: Joshua Marantz <jmarantz@google.com>
fredlas pushed a commit to fredlas/envoy that referenced this pull request Mar 5, 2019
This enables injecting a custom thread factory into the envoy server

Signed-off-by: Elisha Ziskind <eziskind@google.com>
Signed-off-by: Fred Douglas <fredlas@google.com>
fredlas pushed a commit to fredlas/envoy that referenced this pull request Mar 5, 2019
For the record, I am against singletons in general, and believe it's more maintainable to pass context objects through the call/instantiation stack, as is done in Envoy production code. However the test system employs a deep system of mocks that are constructed without context. As a result, any new context that may be needed in the future (e.g. SymbolTable in envoyproxy#4980, ThreadSystem in envoyproxy#5055 and envoyproxy#5072 and FileSystem in envoyproxy#5031) need a mechanism to plumb data into the system as instantiated during tests. I believe Api::OsSysCalls() is another example that might benefit from this.

This class provides a mechanism to have a bounded-scope singleton, such that anywhere an instance of a type T is desired, the same instance will be available. Once all references to a Global go out of scope, the shared instance is destroyed and the pointer to it nulled.

Thus, this singleton pattern has the property that between tests, the state will be completely reset, as long as there are no memory leaks.

The new class, Test::Global, creates a potential conflict with tests that had declared using testing::Test;, so this PR also cleans those up and adds a format check to avoid having that pattern re-occur.

Risk Level: the main risk here is that this class will be abused and used in lieu of proper object passing when that's most appropriate. However, the new library is declared as a bazel test library and is in the test/... tree, so hopefully -- with proper code reviews, the usage will be limited.
Testing: //test/...

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Fred Douglas <fredlas@google.com>
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.

3 participants