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

Context aware SDK with timeouts #276

Merged
merged 25 commits into from
Jan 31, 2020
Merged

Context aware SDK with timeouts #276

merged 25 commits into from
Jan 31, 2020

Conversation

appilon
Copy link
Contributor

@appilon appilon commented Dec 11, 2019

This change would allow developers to switch CRUD funcs and CustomizeDiff funcs to ones that receives a context.Context, configured with the appropriate timeouts (in the case of CRUD). This PR makes some breaking changes to a few schema.Resource methods by adding the context.Context as the first argument. This likely won't cause problems in the wild because a schema.Resource's Apply/Refresh/etc methods were not really meant to be public (they are not useful to anyone).

This PR also forces cancellation through the new context API, removing the previous StopContext feature (this is a breaking change).

This is a PR against our working version2 branch. That branch I have taken the liberty of privatizing/internalizing and pruning dead code/code never intended for public use (cutting the internalized version for Core, and removing support for protocol 4). The PR represents the first enhancement w/ deliberate breaking change. PRs like this should go through a full review process and not just push directly to that branch.

@appilon
Copy link
Contributor Author

appilon commented Dec 11, 2019

Ignore the first commit of this PR, that is the last commit of the version2 branch I forgot to push... not sure how to get the PR to sync 🤔 fixed

UPDATE: common problem trying the 'Edit' trick
https://stackoverflow.com/questions/16306012/github-pull-request-showing-commits-that-are-already-in-target-branch

@appilon appilon changed the base branch from version2 to master December 11, 2019 03:42
@appilon appilon changed the base branch from master to version2 December 11, 2019 03:42
helper/schema/resource.go Outdated Show resolved Hide resolved
helper/schema/resource.go Show resolved Hide resolved
helper/schema/shims_test.go Outdated Show resolved Hide resolved
helper/schema/provider.go Outdated Show resolved Hide resolved
@paultyng
Copy link
Contributor

We may need the ability to opt out of timeouts, I'm not sure, we should check in with the Azure team and see how it goes with their implementation

@paultyng
Copy link
Contributor

What impact will this have on StopContext? Should it be removed?

@appilon
Copy link
Contributor Author

appilon commented Dec 11, 2019

@paultyng Yes this as its coded doesn't feel just right, as every context has a timeout set even if none was configured (as I believe the timeouts all have some hardcoded 20 min duration if nothing was set?) An opt out would make sense

@appilon
Copy link
Contributor Author

appilon commented Dec 11, 2019

Seems we might have a flaky test:
TestWaitForState_inconsistent_negative Seems to involve randomness and a heuristic or two.. re-running test to ensure it was a one in a hundred thing

@appilon appilon added this to the v2.0.0 milestone Dec 11, 2019
@appilon appilon changed the title Context aware CRUD funcs with timeouts Context aware SDK with timeouts Dec 18, 2019
helper/schema/provider.go Outdated Show resolved Hide resolved
helper/schema/resource.go Outdated Show resolved Hide resolved
@paultyng
Copy link
Contributor

paultyng commented Jan 9, 2020

Is there anyway now that you have been in this code a bit to remove those dead functions with panics?

@appilon
Copy link
Contributor Author

appilon commented Jan 9, 2020

@paultyng As discussed it should be possible, but I'll address it in a follow up PR (maybe I can sneak it in at the end)

helper/schema/resource.go Show resolved Hide resolved
helper/schema/resource.go Outdated Show resolved Hide resolved
@appilon appilon marked this pull request as ready for review January 21, 2020 22:59
Copy link
Member

@kmoe kmoe left a comment

Choose a reason for hiding this comment

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

Approved provided everyone's happy on the timeouts issue, and any other review comments are addressed.

refactor codebase around Contextify()
this drops the need for conditional evaluation
of CRUD w/ context and treats that as the default
codepath. One caveat is if a dev sets a noncontext
and context func, the noncontext func is essentially
ignored. I don't see the need to panic/error if both
are set I think it should be obvious.
force cancellation through ctx API
merge a server instanced context's cancellation
with the GRPC request scoped context's cancellation
make all CustomizeDiff funcs to context aware (breaking change)
remove legacy terraform version as this SDK
can never talk with Terraform < 0.12
placeholders. Made configure context aware
rearrange internal crud funcs happy path
add retroactive deprecated comment to MigrateState
need to decide if the feature should be cut in v2
if this is the cause we should place the deprecated comment
in the next v1 release.
update stop feature tests to have 5 second timeout
this ensures any regressions are caught in tests
otherwise the tests themselves deadlock when the implementation
is broken. Passing tests execute near instantly.
@appilon appilon merged commit 389dc87 into version2 Jan 31, 2020
@appilon appilon deleted the context-crud branch January 31, 2020 21:25
@appilon appilon added the breaking-change Implementation which breaks compatibility or other promises label Feb 6, 2020
appilon added a commit that referenced this pull request Feb 11, 2020
* implement Context aware CRUD(E) functions
* set context timeouts according to CRUD func
* add InternalValidate check for dually set CRUD
* add test cases ensuring context aware funcs are called.
* add NoopContext helper
* add context to shims tests
* breaking change: context aware CustomizeDiff
* remove schema.Provider.StopContext feature
* remove schema.Provider.MetaReset func
* remove legacy terraform version as this SDK can never talk with Terraform < 0.12
* use UnaryInterceptor to configure new stop context
* add deprecated comments to now legacy non context identifiers
* add grpc cancel and Stop messag tests, as well as reset test
* add context support to ImportState
* breaking change: context aware StateUpgraders
* add context support to ConfigureFunc
appilon added a commit that referenced this pull request Feb 13, 2020
* implement Context aware CRUD(E) functions
* set context timeouts according to CRUD func
* add InternalValidate check for dually set CRUD
* add test cases ensuring context aware funcs are called.
* add NoopContext helper
* add context to shims tests
* breaking change: context aware CustomizeDiff
* remove schema.Provider.StopContext feature
* remove schema.Provider.MetaReset func
* remove legacy terraform version as this SDK can never talk with Terraform < 0.12
* use UnaryInterceptor to configure new stop context
* add deprecated comments to now legacy non context identifiers
* add grpc cancel and Stop messag tests, as well as reset test
* add context support to ImportState
* breaking change: context aware StateUpgraders
* add context support to ConfigureFunc
appilon added a commit that referenced this pull request Feb 20, 2020
* implement Context aware CRUD(E) functions
* set context timeouts according to CRUD func
* add InternalValidate check for dually set CRUD
* add test cases ensuring context aware funcs are called.
* add NoopContext helper
* add context to shims tests
* breaking change: context aware CustomizeDiff
* remove schema.Provider.StopContext feature
* remove schema.Provider.MetaReset func
* remove legacy terraform version as this SDK can never talk with Terraform < 0.12
* use UnaryInterceptor to configure new stop context
* add deprecated comments to now legacy non context identifiers
* add grpc cancel and Stop messag tests, as well as reset test
* add context support to ImportState
* breaking change: context aware StateUpgraders
* add context support to ConfigureFunc
@ghost
Copy link

ghost commented Mar 2, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking-change Implementation which breaks compatibility or other promises
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants