Skip to content

internal: Migrate ValidateProviderConfig RPC to fromproto6, fwserver, and toproto6 #320

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

Merged
merged 4 commits into from
May 11, 2022

Conversation

bflad
Copy link
Contributor

@bflad bflad commented May 9, 2022

Reference: #215

One particular quirk that this implementation shows is that it is not entirely possible to avoid working with tfsdk/fwserver bits in proto6server as the current data types within the framework (Config, Plan, State) require the Schema so data can be appropriately converted from the protocol to the framework. To support this effort and prevent repetitively executing the provider defined GetSchema method, a fwserver method is introduced that caches the Schema and Diagnostics results on first use. This methodology can also be applied in the future to resolve the existing #299.

… and toproto6

Reference: #215

One particular quirk that this implementation shows is that it is not entirely possible to avoid working with `tfsdk`/`fwserver` bits in `proto6server` as the current data types within the framework (`Config`, `Plan`, `State`) require the `Schema` so data can be appropriately converted from the protocol to the framework. To support this effort and prevent repetitively executing the provider defined `GetSchema` method, a `fwserver` method is introduced that caches the `Schema` and `Diagnostics` results on first use. This methodology can also be applied in the future to resolve #299.
@bflad bflad added the tech-debt Issues tracking technical debt that we're carrying. label May 9, 2022
@bflad bflad requested a review from a team as a code owner May 9, 2022 18:04
@bflad bflad changed the title internal: Migrate ValidateProviderConfig RPC to fromproto6, fwserver, and tfproto6 internal: Migrate ValidateProviderConfig RPC to fromproto6, fwserver, and toproto6 May 9, 2022

if s.providerSchema != nil {
s.providerSchemaMutex.Unlock()
return s.providerSchema, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this return also s.ProviderSchemaDiags?

Unless the intention is to report potential diag-reported warnings/errors, only the first time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it should, thanks for noticing!

s.providerSchemaMutex.Lock()

if s.providerSchema != nil {
s.providerSchemaMutex.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

To ensure future code doesn't break the needs of the mutex to be unlocked, I have seen a slightly different usage pattern (that I like). Something like:

s.ProviderSchemaMutex.Lock()
defer s.ProviderSchemaMutex.Unlock()
...

This way, whatever branching of the logic we take (the memoized one or not), the locking bit is handled safely and consistently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for this suggestion, it's a great one and one I'll implement!

Copy link
Contributor

@detro detro left a comment

Choose a reason for hiding this comment

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

Just a suggestion around the way the mutex gets unlocked.

Mostly is moving things to the new structure, so LGTM.

@bflad bflad added this to the v0.9.0 milestone May 11, 2022
@bflad bflad merged commit 25f29d3 into main May 11, 2022
@bflad bflad deleted the bflad-fwserver-validateproviderconfig branch May 11, 2022 18:26
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
tech-debt Issues tracking technical debt that we're carrying.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants