Skip to content

api: Put Event::TimeSystem& into API and plumb that instead of TimeSystem in various places.#5660

Merged
jmarantz merged 30 commits intoenvoyproxy:masterfrom
jmarantz:plumb-time-source-thru-api
Feb 5, 2019
Merged

api: Put Event::TimeSystem& into API and plumb that instead of TimeSystem in various places.#5660
jmarantz merged 30 commits intoenvoyproxy:masterfrom
jmarantz:plumb-time-source-thru-api

Conversation

@jmarantz
Copy link
Contributor

@jmarantz jmarantz commented Jan 18, 2019

Description: It's better to tunnel more global structures through the API interface rather than passing tons of of global state everywhere, as it makes it much easier to add state as needed, such as Filesystem::Instance (@sesmith177) or Stats::SymbolTable in the futre. This PR puts an Event::TimeSystem& accessor into Api::Api and plumbs that through where needed.

Risk Level: low this is a straight refactor.
Testing: //test/...
Docs Changes: n/a
Release Notes: n/a

…in various places.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
@jmarantz jmarantz changed the title WiP api: Put Event::TimeSystem& into API and plumb that instead of TimeSystem in various places. api: Put Event::TimeSystem& into API and plumb that instead of TimeSystem in various places. Jan 19, 2019
@jmarantz jmarantz requested a review from sesmith177 January 19, 2019 02:58
@jmarantz jmarantz changed the title api: Put Event::TimeSystem& into API and plumb that instead of TimeSystem in various places. WiP api: Put Event::TimeSystem& into API and plumb that instead of TimeSystem in various places. Jan 19, 2019
@jmarantz jmarantz changed the title WiP api: Put Event::TimeSystem& into API and plumb that instead of TimeSystem in various places. api: Put Event::TimeSystem& into API and plumb that instead of TimeSystem in various places. Jan 19, 2019
@jmarantz
Copy link
Contributor Author

hold off on review; I found a way to simplify this.

…ough mocks.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
@jmarantz jmarantz changed the title api: Put Event::TimeSystem& into API and plumb that instead of TimeSystem in various places. RFC: api: Put Event::TimeSystem& into API and plumb that instead of TimeSystem in various places. Jan 22, 2019
@jmarantz
Copy link
Contributor Author

I think this is probably too big to review but I'd love to get any feedback anyone has. My thinking is that there are 2-3 PRs to split out here:

  1. Use Global to ensure there's only one time-system in tests, but that are reset on every test method.
  2. Carry TimeSystem& around in API.
  3. Remove all uses of DeprecatedDangerousTestTime.

I'm also thinking of another grand test-refactor which is make most non-trivial tests in Envoy derive from a single class. This class would also be a good place to assert that all Global are cleaned up, which is currently only done at the end of all tests.

@sesmith177
Copy link
Member

When passing the Filesystem::Instance& through the API, we found that we'd have to expose the API from the FactoryContext as well, so there is some overlap there (at least for the carrying the TimeSystem& around in the API) part.

We also gave the "all tests that use threads/filesystem derive from a single class" pattern a look -- as one might guess it turned into a pretty enormous change so we decided to put it down.

@mattklein123
Copy link
Member

@jmarantz SGTM. In general I do like the idea of carrying around Api everywhere as ultimately we are going to have to do this so we can have a stable API for extensions. I.e., from Api you can get an HttpApi and from there create a header map, etc. so I think this is super valuable work.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
@dnoe
Copy link
Contributor

dnoe commented Jan 28, 2019

I am very much in favor of using Api::Api for this, I think it's the best of all options for these global items like time and filesystem.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Still failing:

//test/common/network:connection_impl_test                               FAILED in 2.2s

[ RUN      ] IpVersions/ConnectionImplDeathTest.BadFd/IPv4
test/common/network/connection_impl_test.cc:91: Failure
Death test: ConnectionImpl(dispatcher, std::make_unique<ConnectionSocketImpl>(std::move(io_handle), nullptr, nullptr), Network::Test::createRawBufferSocket(), false)
    Result: died but not with expected error.
  Expected: contains regular expression ".*assert failure: ioHandle\\(\\).fd\\(\\) != -1.*"
Actual msg:

Will investigate after master-merge.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
@jmarantz jmarantz changed the title RFC: api: Put Event::TimeSystem& into API and plumb that instead of TimeSystem in various places. api: Put Event::TimeSystem& into API and plumb that instead of TimeSystem in various places. Jan 29, 2019
@jmarantz
Copy link
Contributor Author

@sesmith177 @dnoe I think this is ready for a look.

@jmarantz
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

🔨 rebuilding ci/circleci: release (failed build)

🐱

Caused by: a #5660 (comment) was created by @jmarantz.

see: more, trace.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
@jmarantz
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

🔨 rebuilding ci/circleci: mac (failed build)
🔨 rebuilding ci/circleci: coverage (failed build)

🐱

Caused by: a #5660 (comment) was created by @jmarantz.

see: more, trace.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Copy link
Contributor

@dnoe dnoe left a comment

Choose a reason for hiding this comment

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

I think you can remove an argument from the GuardDogImpl constructor, since it currently takes both a TimeSystem and an Api:

https://github.com/envoyproxy/envoy/blob/master/source/server/guarddog_impl.h#L43

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
…th explicit TimeSystem arg.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
/**
* @return a reference to the TimeSystem
*/
virtual Event::TimeSystem& timeSystem() PURE;
Copy link
Member

Choose a reason for hiding this comment

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

Per discussion, WDYT about just making this return a TimeSource in this PR? We can still take a TimeSystem in the constructor and not change anything else until a follow up, but this would get us closer to where we want to be?

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 think that would expand this PR significantly because there are a few places in the PR where an existing timeSystem() interface is implemented using API::timeSystem(). If that disappeared I'd have to change a bunch of call-sites. This would be trivial but it would make the PR a lot larger, and there is some semantic content here. So I'd prefer to do that in a separate PR. That OK?

I have this practice of trying to make semantically interesting PRs as small as possible, and letting trivial renaming or type-change PRs go large if needed.

Copy link
Member

Choose a reason for hiding this comment

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

Sure SGTM. I think we are on the same page and heading in the right direction so 👍

@mattklein123 mattklein123 self-assigned this Feb 3, 2019
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
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.

Awesome cleanup!

@jmarantz jmarantz merged commit ed05163 into envoyproxy:master Feb 5, 2019
@jmarantz jmarantz deleted the plumb-time-source-thru-api branch February 5, 2019 17:27
fredlas pushed a commit to fredlas/envoy that referenced this pull request Mar 5, 2019
…stem in various places. (envoyproxy#5660)

* Put Event::TimeSystem& into API and plumb that instead of TimeSystem in various places.

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.

4 participants