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

feat: standardize plugin naming, add getMiddleware fn [WIP] #402

Closed
wants to merge 10 commits into from

Conversation

srchase
Copy link
Contributor

@srchase srchase commented Oct 17, 2019

Standardizes naming of plugins. Use resolveConfig and getMiddleware.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@srchase srchase added the smithy-codegen Changes regarding supporting smithy model. Will be merged to smithy-codegen branch label Oct 17, 2019
@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@codecov-io
Copy link

codecov-io commented Oct 17, 2019

Codecov Report

Merging #402 into smithy-codegen will increase coverage by 0.25%.
The diff coverage is 73.33%.

Impacted file tree graph

@@                Coverage Diff                 @@
##           smithy-codegen     #402      +/-   ##
==================================================
+ Coverage           96.72%   96.97%   +0.25%     
==================================================
  Files                  69       69              
  Lines                1161     1158       -3     
  Branches              214      214              
==================================================
  Hits                 1123     1123              
+ Misses                 38       35       -3
Impacted Files Coverage Δ
packages/middleware-retry/src/constants.ts 100% <ø> (ø)
packages/middleware-retry/src/defaultStrategy.ts 100% <ø> (ø)
packages/middleware-retry/src/delayDecider.ts 100% <ø> (ø)
packages/middleware-retry/src/retryDecider.ts 100% <ø> (ø)
packages/middleware-signing/src/middleware.ts 100% <100%> (ø)
packages/middleware-retry/src/retryMiddleware.ts 100% <100%> (ø)
packages/middleware-retry/src/configurations.ts 66.66% <50%> (ø)

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 1bb6e37...a6939dd. Read the comment docs.

@AllanZhengYP
Copy link
Contributor

Can you keep the CHANGELOG untouched? So we have a clue on what they are renamed from.

let _config_5 = UserAgentConfig.resolve(_config_4);
super(_config_5);
this.config = _config_5;
super.use(AwsAuthConfig.getMiddleware(this.config));
Copy link
Contributor

@AllanZhengYP AllanZhengYP Oct 17, 2019

Choose a reason for hiding this comment

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

I'm not a fan of getMiddleware(), because it doesn't give you a middleware. It in-fact mutates the client's middleware stack. Also the all namespace XXXConfig doesn't make sense because they are not really Config. I still prefer the naming convention of client config component's named XXXConfig. If they have middleware to insert, then it should export a XXXPlugin. If destroy method is required, then it should export a method called destroyXXX()

Copy link
Contributor Author

@srchase srchase Oct 18, 2019

Choose a reason for hiding this comment

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

I removed the Config suffix and switched to resolveConfig and setMiddleware to make this more clear. Using the name for a plugin, along with same function for resolveConfig, destroy, etc will be easier to codegen.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of getMiddleware(), because it doesn't give you a middleware. It in-fact mutates the client's middleware stack.

Is this true? Or is this going to be true after some future changes? This code looks like it's getting a list of middleware to inject into this.use by calling getMiddleware.

I still prefer the naming convention of client config component's named XXXConfig. If they have middleware to insert, then it should export a XXXPlugin. If destroy method is required, then it should export a method called destroyXXX()

Can you give concrete examples?

Copy link
Contributor

@AllanZhengYP AllanZhengYP Oct 19, 2019

Choose a reason for hiding this comment

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

@mtdowling

This code looks like it's getting a list of middleware to inject into this.use by calling getMiddleware

I updated the use interface recently which takes in a function mutating the middleware stack, see here, and here.
A runtime plugin is not just a list of middleware, it may also include mutating existing middleware stack and even delete some middleware if exist. This interface allows more extensibility than only allowing injecting new middleware.
Using setMiddleware here is better than getMiddleware. I will propose getPlugin as it better describe the function.

Can you give concrete examples?

  • AwsAuth customization has input config interface, so ClientConfiguration contains AwsAuthInput, and AwsAuth.Resolved. The resolveConfig should also be called.
  • AwsAuth customization has middleware stack customization(runtime plugin), so client should use the plugin. But here I suggest renaming it to super.use(AwsAuth.getPlugin(this.config))).
  • AwsAuth doesn't have a destroy so take ProtocolConfig as an example, because it contains handler. The client destroy() will look like:
destroy(): void {
    ClientProtocol.destroy(this.config);
}

The destroy function will call the destroy function on this.config.protocol and hence destroy the handler. The this.config is supplied to function because destroyable resources are in the client's resolved config

Copy link
Member

Choose a reason for hiding this comment

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

I updated the use interface recently which takes in a function mutating the middleware stack, see here, and here.

👍

Using setMiddleware here is better than getMiddleware

👍

I will propose getPlugin as it better describe the function.

I think setMiddleware of updateMiddleware makes more sense. It says exactly what the function does. getPlugin doesn't convey anything really, and it makes the term "plugin" more ambiguous in the SDK. We need to be really deliberate with how we describe things across codegen and runtime packages.

AwsAuth customization has input config interface, so ClientConfiguration contains AwsAuthInput, and AwsAuth.Resolved. The resolveConfig should also be called.

Why the difference between AwsAuthInput and AwsAuth.Resolved? Seems like a strange pattern. If there's some technical limitation in IDEs, then we should standardize on AwsAuthInput and AwsAuthResolved instead to make this less surprising.

If we do that, then we should get rid of the namespacing altogether and do something like:

  1. AwsAuthConfigInput interface
  2. AwsAuthConfigResolved interface
  3. resolveAwsAuthConfig() function
  4. updateAwsAuthMiddleware() function

My biggest gripe with the above code is that it's leaning way too much on convention and spreading the responsibility out across so many different disconnected things.

Alternatively we could have a different convention for bridging codegen and runtime code references. For example we could provide a set of interfaces that have generic parameters for the input type, resolved type, and methods for resolveConfig and updateMiddleware.

Copy link
Contributor

@AllanZhengYP AllanZhengYP Oct 21, 2019

Choose a reason for hiding this comment

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

Why the difference between AwsAuthInput and AwsAuth.Resolved? Seems like a strange pattern.

Yes. It is an IDE limitation. It makes sense to get rid of namespace.

I'm still a little concern about the updateAwsAuthMiddleware. It sounds like it takes a parameter that is a middleware to be updated. In fact the Injectable interface is the "Plugin" interface we expose(I think we should rename it to Pluggable). The updateAwsAuthMiddleware() is actually a getter of a Pluggable, this is why I suggest getPlugin.

we could provide a set of interfaces that have generic parameters for the input type, resolved type, and methods for resolveConfig and updateMiddleware.

I prefer using convention over interface because by using interface, these config and middleware plugins will be attached to a single object. If you import one of them in client, you import all of them. But for customizations that requires client config and middleware in the commands(there are many), we don't want to import middleware plugin in the client. This will increase the size of the client.

Basically the config and middleware plugin are better to be decoupled.

@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@srchase srchase changed the title feat: standardize Config naming, add getMiddleware fn feat: standardize Config naming, add setMiddleware fn Oct 18, 2019
@srchase srchase changed the title feat: standardize Config naming, add setMiddleware fn feat: standardize plugin naming, add getMiddleware fn Oct 18, 2019
@trivikr trivikr self-assigned this Oct 18, 2019
@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@srchase srchase changed the title feat: standardize plugin naming, add getMiddleware fn feat: standardize plugin naming, add getMiddleware fn [WIP] Oct 24, 2019
@AllanZhengYP
Copy link
Contributor

This PR has been replaced to #422

@lock
Copy link

lock bot commented Nov 4, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
smithy-codegen Changes regarding supporting smithy model. Will be merged to smithy-codegen branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants