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
[sdk/*] Add support for resource source positions #13449
Conversation
Changelog[uncommitted] (2023-07-13)Features
|
de1cf9d
to
fe93795
Compare
Updated the CHANGELOG. I've structured these changes s.t. the changes to each SDK are in separate commits. Hopefully this makes it easier to review. |
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.
LGTM otherwise
assert.strictEqual(sourcePosition.line, 2); | ||
break; | ||
case "component": | ||
assert.strictEqual(sourcePosition.line, 2); | ||
break; |
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.
Why are these line 2? Isn't it 16 and 17?
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.
I am confused by this as well. I've had correct results from Typescript files but I haven't tried JS outside of the test harness. I'm wondering if this is related to the harness or if we'll always see this for JS.
One question, that I didn't get a chance to ask on #13437. From reading the changes in #13437, when a user is creating an MLC, it looks like we won't record the position of where the user created the MLC, but rather, the position where the component is created inside the MLC provider. Is that correct? If so, should we consider making it so that it records the position of where the user is instantiating the MLC instead? |
Ooooh, that is an excellent catch--I believe you're correct about that. Offhand it seems like we could either include the original source position in the construct request and leave it up to the MLC or we could inform the resource monitor about the actual source position and let it handle things. The latter is probably moderately more complex to implement in the engine, but seems like it is likely to be simpler and less error prone overall. Thoughts? cc @Frassle as well. |
The latter approach would be my preference, if we can make it all work in the engine. That way we don't have to go through all the hassle of propagating the value through the construct request and having to update each SDK (that has APIs for defining MLC providers) to handle it. |
Agree with Justin. If when doing a Construct we spawn a new resource monitor that just overrides the SourcePosition of any RegisterResourceRequests that come through it before propagating to the original resource monitor then this is purely an engine side change and MLCs in every language will just work. |
31a7c5a
to
556a2b5
Compare
I like the idea of spawning new resource monitors. I'm not sure about overriding all child resources of a remote component. I think that there's value in deep linking into component sources, especially if we can go from a component source position to the component's package to its sources. I think we can start with your suggestion, though, and implement the rest later. |
(I'll follow up MLC bits in another PR) |
bors merge |
13449: [sdk/*] Add support for resource source positions r=pgavlin a=pgavlin Add support to the core SDKs for reporting resource source positions. In each SDK, this is implemented by crawling the stack when a resource is registered in order to determine the position of the user code that registered the resource. This is somewhat brittle in that it expects a call stack of the form: - Resource class constructor - abstract Resource subclass constructor - concrete Resource subclass constructor - user code This stack reflects the expected class hierarchy of "cloud resource / component resource < customresource/componentresource < resource". For example, consider the AWS S3 Bucket resource. When user code instantiates a Bucket, the stack will look like this in NodeJS: new Resource (/path/to/resource.ts:123:45) new CustomResource (/path/to/resource.ts:678:90) new Bucket (/path/to/bucket.ts:987:65) <user code> (/path/to/index.ts:4:3) In order to determine the source position, we locate the fourth frame (the `<user code>` frame). Co-authored-by: Pat Gavlin <pat@pulumi.com>
556a2b5
to
f950465
Compare
Canceled. |
That was my intent. Not to totally override the sub-resources SourcePositions but just to fix them up to be "package://" style. |
f548229
to
b504e55
Compare
Add support to the core SDKs for reporting resource source positions. In each SDK, this is implemented by crawling the stack when a resource is registered in order to determine the position of the user code that registered the resource. This is somewhat brittle in that it expects a call stack of the form: - Resource class constructor - abstract Resource subclass constructor - concrete Resource subclass constructor - user code This stack reflects the expected class hierarchy of "cloud resource / component resource < customresource/componentresource < resource". For example, consider the AWS S3 Bucket resource. When user code instantiates a Bucket, the stack will look like this in NodeJS: new Resource (/path/to/resource.ts:123:45) new CustomResource (/path/to/resource.ts:678:90) new Bucket (/path/to/bucket.ts:987:65) <user code> (/path/to/index.ts:4:3) In order to determine the source position, we locate the fourth frame (the `<user code>` frame).
b504e55
to
248f78b
Compare
bors merge |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page.
|
Add support to the core SDKs for reporting resource source positions.
In each SDK, this is implemented by crawling the stack when a resource
is registered in order to determine the position of the user code that
registered the resource.
This is somewhat brittle in that it expects a call stack of the form:
This stack reflects the expected class hierarchy of "cloud resource / component resource < customresource/componentresource < resource".
For example, consider the AWS S3 Bucket resource. When user code instantiates a Bucket, the stack will look like
this in NodeJS:
In order to determine the source position, we locate the fourth frame (the
<user code>
frame).