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

Fix custom timeout handling under PlanResourceChange #2390

Merged
merged 6 commits into from
Sep 4, 2024

Conversation

t0yv0
Copy link
Member

@t0yv0 t0yv0 commented Sep 4, 2024

Under PlanResourceChange the way custom timeout option is handled is not properly communicating the value to the underlying TF provider. This is now fixed and the existing test made to pass.

See also: https://www.pulumi.com/docs/concepts/options/customtimeouts/

Fixes #2386

New warnings are introduced for the case when a user tries to set a customTimeouts option on a resource that does not support it. The customTiemeouts in this case are a no-op. I believe this should be a warning to guide the user but we might also consider downgrading severity to an INFO or debug level message.

Under PlanResourceChange the way custom timeout option is handled is not properly communicating the value to the
underlying TF provider. This is now fixed and the existing test made to pass.

See also: https://www.pulumi.com/docs/concepts/options/customtimeouts/
Copy link

codecov bot commented Sep 4, 2024

Codecov Report

Attention: Patch coverage is 89.01099% with 10 lines in your changes missing coverage. Please review.

Project coverage is 57.10%. Comparing base (bdd39dc) to head (2a89901).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
pkg/tfshim/sdk-v2/provider2.go 86.27% 5 Missing and 2 partials ⚠️
pkg/tests/tfcheck/tfcheck.go 82.35% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2390      +/-   ##
==========================================
+ Coverage   57.08%   57.10%   +0.02%     
==========================================
  Files         368      369       +1     
  Lines       50535    50593      +58     
==========================================
+ Hits        28848    28893      +45     
- Misses      20114    20123       +9     
- Partials     1573     1577       +4     

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

@t0yv0
Copy link
Member Author

t0yv0 commented Sep 4, 2024

https://github.com/pulumi/terraform-plugin-sdk/blob/upstream-v2.33.0/helper/schema/core_schema.go#L320 is the interesting bit that defines the schema for timeouts piecemeal, unless the user already defined "timeouts" attribute or block.

I've not verified how this works in TF but would be interesting:

  • if user specifies a "timeouts" block or attribute, does it just get fully custom handling (i.e. we shouldn't be setting custom timeout overrides at all as that's always a no-op)

  • if user does not specify a "timeouts" block or attribute, but the auto-generated one only support e.g. Create timeouts, is it true that Update timeouts can never work then? Sounds plausible but I've not confirmed in TF.

VenelinMartinov and others added 4 commits September 4, 2024 16:06
This adds cross tests for custom timeouts, comparing our handling of
custom timeouts with terraform's. To do that we've exposed the `plan`
error in tfcheck.

Looks like the TF rules are the following:
- If the schema specifies a timeout for the operation, then the user is
allowed to override that.
- If the schema does not specify a timeout, then the resource is said
not to support timeouts. That makes it a runtime error if the user then
tries to customise the timeout on the resource.

That makes sense conceptually, as not all resources would be implemented
in a way which supports timeouts.

Related to #2386
@t0yv0 t0yv0 marked this pull request as ready for review September 4, 2024 15:55
// Send logs or status logs to the user.
//
// Logged messages are pre-associated with the resource they are called from.
type Logger interface {
Copy link
Member Author

Choose a reason for hiding this comment

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

This needs its own package so that it's usable from tfshim/* modules without imposing a circular pacakge dependency build error.

@t0yv0 t0yv0 requested a review from iwahbe September 4, 2024 15:56
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.

lgtm

@VenelinMartinov
Copy link
Contributor

The current CI failure is due to TestStacktraceDisplayed being flaky: #2388

impliedType cty.Type,
) map[string]any {
config := map[string]any{}
for k, v := range configWithoutTimeouts {
Copy link
Member

Choose a reason for hiding this comment

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

What is configWithoutTimeouts? Is it the TF config translation of the Pulumi config? A comment explaining that would be helpful.

It would be amazing if configWithoutTimeouts was it's own type, but that's a painful pattern in Go.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. I can use ResourceConfig which is what's needed, but I always forget how to construct that. All the helper types aren't quite there yet to be truly usable. Added some commits.

Generally I agree with your sentiment, just qualifying it with this idea that I sweat the signatures a bit less for functions that are private file-local single-use functions, e.g. the smaller the scope the less I worry about this. But I'm quite open to efforts to raise the bar on code quality in this codebase so if you have plans here happy to play along or follow a style guide.

Comment on lines 243 to 244
cfg, err := recoverAndCoerceCtyValueWithSchema(res.CoreConfigSchema(),
p.configWithTimeouts(ctx, config.Config, opts.TimeoutOptions, ty))
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this is only called during Diff. Doesn't this need to be called during update as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah so Update calls Diff again to redo the planning. Part of the test we're recovering here is the gRPC protocol layer test for the Update Pulumi RPC method and that now passes, so I'm pretty confident it's working. I had to fix that test to emulate an actual news!=olds change as not doing that bypasses the timeouts in the upstream impl.

@t0yv0 t0yv0 enabled auto-merge (squash) September 4, 2024 17:47
@t0yv0 t0yv0 merged commit ae899ed into master Sep 4, 2024
11 checks passed
@t0yv0 t0yv0 deleted the t0yv0/fix-prc-custom-timeouts branch September 4, 2024 18:01
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v3.90.0.

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.

PlanResourceChange issue with Create timeout overrides
4 participants