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

Allow attaching to running providers #8979

Merged
merged 18 commits into from Apr 19, 2022
Merged

Allow attaching to running providers #8979

merged 18 commits into from Apr 19, 2022

Conversation

Frassle
Copy link
Member

@Frassle Frassle commented Feb 11, 2022

Description

This adds an envvar check to attach to a currently running provider rather than spawning a new provider binary. This lets you start for example the aws provider in a debugger let it start listening in on a port and then running pulumi up with an env var set to use that running provider for aws PULUMI_PROVIDER_AWS=<port>

Engine side part of a fix for #2396

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • Yes, there are changes in this PR that warrants bumping the Pulumi Service API version


// Attach triggers an attach for a currently running provider to the engine
// TODO It would be nice if this was a HostClient rather than the string address but due to dependency ordering we don't have access to declare that here.
Attach(address string) error
Copy link
Member

Choose a reason for hiding this comment

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

Can this be an implementation detail of the gRPC implementation of plugins rather than part of the Plugin type?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe? I thought about maybe having a GrpcProvider that was just Provider + Attach? Is there a more "go" way to do it?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'm wondering whether or not we need to expose Attach at all. I think we could just invoke the gRPC method directly here: https://github.com/pulumi/pulumi/pull/8979/files#diff-4372cd77587542c3e09139fb236d0bce7d0ff31c3c81864950974b1e33e5104eR146

@pgavlin
Copy link
Member

pgavlin commented Feb 11, 2022

Thinking aloud a bit:

Another way to achieve this w/o touching the core plugin host would be to implement this as a proxy host, like we do for the client language runtime that's used for automation API. I don't think that's the best choice for this feature, as we probably do want the changes you're making to apply by default to process-based plugin hosts (and not to other hosts).

I also wonder if the envvar might be more ergonomic if it we a list of (name, version?, port) tuples. Something like

PULUMI_PROVIDERS=aws:12345,gcp@v1.23:12346

One other thing: have you tried this when running an update where multiple instances of a particular provider are needed? I'm not sure how this fits into that scenario, as today each instance of a provider implies a new process.

@Frassle
Copy link
Member Author

Frassle commented Feb 11, 2022

I also wonder if the envvar might be more ergonomic if it we a list of (name, version?, port) tuples. Something like

Yeh happy to change to that style. I'm not sure versions matter here, I see it similar to how if you have like "pulumi-resource-aws" on path we just ignore the version and use the one you've got on path. Which I guess also answers your other question of what happens if you have multiple instances, well you don't. Same as if it was on path.

@codecov
Copy link

codecov bot commented Feb 16, 2022

Codecov Report

Merging #8979 (7d5ff04) into master (766a4d2) will increase coverage by 0.18%.
The diff coverage is 28.27%.

❗ Current head 7d5ff04 differs from pull request most recent head fd2f055. Consider uploading reports for the commit fd2f055 to get more accurate results

@@            Coverage Diff             @@
##           master    #8979      +/-   ##
==========================================
+ Coverage   59.11%   59.30%   +0.18%     
==========================================
  Files         646      643       -3     
  Lines      100254   100073     -181     
  Branches     1420     1427       +7     
==========================================
+ Hits        59262    59345      +83     
+ Misses      37411    37333      -78     
+ Partials     3581     3395     -186     
Impacted Files Coverage Δ
pkg/resource/provider/component_provider.go 0.00% <0.00%> (ø)
pkg/resource/provider/main.go 0.00% <0.00%> (ø)
sdk/go/common/resource/plugin/provider.go 71.42% <ø> (ø)
sdk/go/common/resource/plugin/provider_server.go 19.74% <0.00%> (-0.44%) ⬇️
sdk/nodejs/proto/provider_grpc_pb.js 4.63% <0.00%> (-0.20%) ⬇️
sdk/proto/go/provider.pb.go 33.69% <0.00%> (-0.58%) ⬇️
...dk/python/lib/pulumi/runtime/proto/provider_pb2.py 100.00% <ø> (ø)
sdk/proto/go/plugin.pb.go 36.25% <14.28%> (-7.82%) ⬇️
...thon/lib/pulumi/runtime/proto/provider_pb2_grpc.py 26.04% <20.00%> (-0.34%) ⬇️
sdk/nodejs/proto/plugin_pb.js 26.38% <25.58%> (-0.29%) ⬇️
... and 130 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 766a4d2...fd2f055. Read the comment docs.

@@ -2171,6 +2172,8 @@ type ResourceProviderClient interface {
Cancel(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*empty.Empty, error)
// GetPluginInfo returns generic information about this plugin, like its version.
GetPluginInfo(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*PluginInfo, error)
// Attach sends the engine address to an already running plugin.
Attach(ctx context.Context, in *PluginAttach, opts ...grpc.CallOption) (*empty.Empty, error)
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 is going to break implementers of ResourceProviderClient. Which if we're going to have to push out a break change we may as well change NewProviderServer to take a GrpcProvider as well.

@pgavlin
Copy link
Member

pgavlin commented Apr 7, 2022

One other thing: have you tried this when running an update where multiple instances of a particular provider are needed? I'm not sure how this fits into that scenario, as today each instance of a provider implies a new process.

Still curious about this.

@Frassle
Copy link
Member Author

Frassle commented Apr 7, 2022

Still curious about this.

I'll have a look. I thought we cached processes per provider name, but I'll dig into this more.

@Frassle
Copy link
Member Author

Frassle commented Apr 7, 2022

So with attach it will redial the grpc connection each time and call Attach (with the same engine address). So it would also call Configure multiple times.
Not sure that's an issue, but also not sure what else we could do in this case?

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

3 participants