-
Notifications
You must be signed in to change notification settings - Fork 98
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
Conversation
… 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.
internal/fwserver/server.go
Outdated
|
||
if s.providerSchema != nil { | ||
s.providerSchemaMutex.Unlock() | ||
return s.providerSchema, nil |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
internal/fwserver/server.go
Outdated
s.providerSchemaMutex.Lock() | ||
|
||
if s.providerSchema != nil { | ||
s.providerSchemaMutex.Unlock() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this 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.
…e returned in (Server).ProviderSchema()
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. |
Reference: #215
One particular quirk that this implementation shows is that it is not entirely possible to avoid working with
tfsdk
/fwserver
bits inproto6server
as the current data types within the framework (Config
,Plan
,State
) require theSchema
so data can be appropriately converted from the protocol to the framework. To support this effort and prevent repetitively executing the provider definedGetSchema
method, afwserver
method is introduced that caches theSchema
andDiagnostics
results on first use. This methodology can also be applied in the future to resolve the existing #299.