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

Instrument DecodePropertyMap failures to assist root-causing refresh issues in Plugin Framework #1920

Merged
merged 9 commits into from
May 2, 2024

Conversation

t0yv0
Copy link
Member

@t0yv0 t0yv0 commented May 1, 2024

Investigating #1919

DecodePropertyMap called from Read fails because it decoded something to a null but a PropertyMap is expected. It appears it should never happen because Read will not call DecodePropertyMap with a tftypes.Value=nil but instead short-circuit the "resource not found path".

resp.State.RemoveResource(ctx) likewise seems to work correctly.

Testing this further, still unable to reproduce the scenario in test. Instead, opting for adding some more debugging instrumentation around the line that emits the error, and doing some conservative code tightening around this code path.

Copy link

codecov bot commented May 1, 2024

Codecov Report

Attention: Patch coverage is 30.35714% with 39 lines in your changes are missing coverage. Please review.

Project coverage is 60.30%. Comparing base (875f071) to head (c6a85c3).
Report is 2 commits behind head on master.

Files Patch % Lines
...f/tests/internal/providerbuilder/build_resource.go 10.00% 17 Missing and 1 partial ⚠️
pkg/convert/convert.go 11.11% 8 Missing ⚠️
pf/tfbridge/provider_read.go 0.00% 5 Missing ⚠️
pf/tfbridge/resource_state.go 81.25% 3 Missing ⚠️
pf/tfbridge/provider_create.go 0.00% 2 Missing ⚠️
pf/tfbridge/provider_update.go 0.00% 2 Missing ⚠️
pf/tfbridge/provider_invoke.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1920      +/-   ##
==========================================
+ Coverage   60.24%   60.30%   +0.05%     
==========================================
  Files         328      328              
  Lines       44342    44335       -7     
==========================================
+ Hits        26715    26736      +21     
+ Misses      16131    16100      -31     
- Partials     1496     1499       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -141,22 +141,17 @@ func (p *provider) readResource(
return plugin.ReadResult{}, nil
}

// TF interpretes a null new state as an indication that the resource does not
// exist in the cloud provider.
newStateNull, err := resp.NewState.IsNull()
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously IsNull check was done on the DynamicValue domain, and after the change it's done on the tftypes.Value domain. There's a very slim chance the issue was there, namely that there were values that return IsNull() = false on DynamicValue domain that then translate to Null values on tftypes.Value domain.

readState, err := parseResourceStateFromTF(ctx, rh, resp.NewState, resp.Private)
if err != nil {
return plugin.ReadResult{}, fmt.Errorf("parsing resource state: %w", err)
}

readStateMap, err := readState.ToPropertyMap(rh)
// TF interprets a null new state as an indication that the resource does not exist in the cloud provider.
Copy link
Member Author

Choose a reason for hiding this comment

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

I still believe this is how TF works.

Private: private,
}}, nil
}
if state == nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

Tightening to also handle physical nulls, probably unnecessary but just in case.

pv, err := dec.toPropertyValue(v)
if err != nil {
return nil, err
}
if !pv.IsObject() {
return nil, fmt.Errorf("Expected an Object, got: %v", pv.String())
details := fmt.Sprintf(`DecodePropertyMap expected the decoder to return an Object
Copy link
Member Author

Choose a reason for hiding this comment

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

Emitting a little more information in the debug log. Not returning it as an err in case it is printed on stdout since the values may be sensitive.

@t0yv0 t0yv0 changed the title WIP: exploring not-found result from Read in Plugin Framework. Instrument DecodePropertyMap failures to assist root-causing refresh issues in Plugin Framework May 2, 2024
@t0yv0 t0yv0 marked this pull request as ready for review May 2, 2024 15:40
Copy link
Contributor

@VenelinMartinov VenelinMartinov left a comment

Choose a reason for hiding this comment

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

Seems sensible, sounds like it should handle the reported error.

@t0yv0 t0yv0 enabled auto-merge (squash) May 2, 2024 17:26
@t0yv0 t0yv0 merged commit b467adc into master May 2, 2024
11 checks passed
@t0yv0 t0yv0 deleted the t0yv0/fix-pf-read-not-found branch May 2, 2024 17:41
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.

None yet

2 participants