-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Introduces autoloading strategy for service gems #3105
Conversation
This reverts commit 2b8a515.
@Schwad - I've created a pr in aws-sdk-rails: aws/aws-sdk-rails#140 Does this look like the correct/equivalent strategy for eager loading after this PR? |
@alextwoods Thanks for hopping onto this PR! We got it working in the end. :) This looks correct to me:
I haven't manually checked yet, but if you're ever unsure if it's working you can set Sorry, you probably knew that all, just talking this through out loud 😅 |
And this PR is looking even more manageable without all those Railties added. |
I think this is looking pretty good! I've completed testing with all of our internal build systems and everything looks good. I'll discuss with the rest of the team, but I'd love to get this released this week if possible. There are some additional optimizations I'd like to do (particularly around aws-partitions), but those should probably be done as a separate PR. Thanks for the testing suggestion for the aws-sdk-rails change - its good confirmation that what I was doing to test makes sense. Could you review/approve that PR? (I'll also have another other of the SDK developers review, but since you originally wrote the railties here). |
@@ -1,4 +1,5 @@ | |||
require_relative '../../spec_helper' | |||
require 'aws-sdk-core/cbor/cbor_engine' |
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.
Note: These are required because of the way engines are loaded (Ie, we don't just reference the CborEngine, we do a require on the file when trying to determine the default engine. This means it does not play well with autoloads).
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.
Can spec_helper load all the stuff?
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.
Nice so far!
def module_name | ||
@service.module_name | ||
end | ||
|
||
# @return [Boolean] | ||
def customization_file_exists? | ||
File.exist?(File.join(__dir__, "../../../../../gems/aws-sdk-#{gem_name}/lib/aws-sdk-#{gem_name}/customizations/errors.rb")) |
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.
Implementation of this can probably call customization_file_path
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.
cleaned that up in all views + created a helper for the gem lib path.
@@ -18,6 +18,7 @@ def initialize(options) | |||
paginators: options.fetch(:paginators) | |||
) | |||
@custom = options.fetch(:custom) | |||
@name = @module_name.split('::').last.downcase |
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.
Is this gem name? Why do the other classes have a method and this not?
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.
Yeah good call - will refactor it to follow pattern of other modules.
build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/service_module.rb
Outdated
Show resolved
Hide resolved
class_name = File.basename(path).split('.').first.split('_').map(&:capitalize).join | ||
|
||
# Handle the Db -> DB case for AWS database-related constants | ||
class_name = class_name.gsub(/Db(?=[A-Z]|$)/, 'DB') |
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.
There are many inflections that need to be handled.. I don't like this as a one-off. Consider somehow using the inflections from the underscore method and verify nothing bad happens?
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've actually completely changed this method so that it should not need to do this class name inference and hopefully made it more readable.
@@ -1,6 +1,7 @@ | |||
# frozen_string_literal: true | |||
|
|||
require_relative 'spec_helper' | |||
require 'aws-sdk-cloudfront/customizations' |
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.
Do all spec files need to require customizations now? Could instead a generated spec helper (or somehow the shared one) do this?
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 think this was legacy of some other issues that have been fixed. Removed from here.
@@ -1,6 +1,8 @@ | |||
Unreleased Changes | |||
------------------ | |||
|
|||
* Feature - Use autoloading at the service level to load service clients and resources. |
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.
Do all service gems need to be bumped to use this new version of core?
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.
No -I don't think they need to. New service gems can still use the old core without issue (and vice versa).
autoload :Util, 'aws-sdk-core/util' | ||
|
||
# resource classes | ||
module Resources |
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.
Should each of these modules be pushed into a different file? Maybe resources.rb, plugins.rb, log.rb etc?
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.
yeah, thats a good idea. Moved all of these to their own files.
@@ -1,6 +1,7 @@ | |||
# frozen_string_literal: true | |||
|
|||
require_relative '../../spec_helper' | |||
require 'aws-sdk-core/cbor/decoder' |
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 all these required for specs to work?
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.
See other answer about engines. (we do an explicit require in the cbor engine when setting a default. this does not work with autoload).
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.
Mostly nits and maybe you forgot some stuff?
build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/service_module.rb
Show resolved
Hide resolved
@@ -1,6 +1,8 @@ | |||
# frozen_string_literal: true | |||
|
|||
require_relative '../spec_helper' | |||
require 'aws-sdk-core/cbor' |
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.
Extra newline
@@ -1,6 +1,7 @@ | |||
# frozen_string_literal: true | |||
|
|||
require_relative 'spec_helper' | |||
require_relative '../lib/aws-sdk-translate/plugins/translate_document_encoding' |
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.
Is this still necessary to require? Other plugins don't need this so maybe an issue.
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.
Moved this to an autoload in the customizations. (Note, this only impacts cases where the client isn't used before trying to access this custom plugin, as in this test).
I live in the UK so sorry I can't always reply quickly, but the direction of the conversation here looks right to me, no protests or disagreements. I'll throw down a review/approval on the aws-sdk-rails PR 🙇 |
This was released today! New versions of each service gem were published eg: aws-sdk-s3@1.165.0 and aws-sdk-core@3.208.0. Thanks again for a great contribution! I'll work on getting the eager load feature out in aws-sdk-rails over the next few days. |
That's wonderful news!! Thank you for the wonderful collaboration. I truly found this a joy to work on and am so happy with the reception to the contribution. Cheers again! |
We freeze everything to catch malicious self modifying code from user input. Since the Aws SDK started to autoload modules when used, so we need to load them before freezing. aws/aws-sdk-ruby#3105
We freeze everything to catch malicious self modifying code from user input. Since the Aws SDK started to autoload modules when used, so we need to load them before freezing. aws/aws-sdk-ruby#3105
We freeze everything to catch malicious self modifying code from user input. Since the Aws SDK started to autoload modules when used, so we need to load them before freezing. aws/aws-sdk-ruby#3105
We freeze everything to catch malicious self modifying code from user input. Since the Aws SDK started to autoload modules when used, so we need to load them before freezing. aws/aws-sdk-ruby#3105
We freeze everything to catch malicious self modifying code from user input. Since the Aws SDK started to autoload modules when used, so we need to load them before freezing. aws/aws-sdk-ruby#3105
We freeze everything to catch malicious self modifying code from user input. Since the Aws SDK started to autoload modules when used, so we need to load them before freezing. aws/aws-sdk-ruby#3105
Context: #3098
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
To make sure we include your contribution in the release notes, please make sure to add description entry for your changes in the "unreleased changes" section of the
CHANGELOG.md
file (at corresponding gem). For the description entry, please make sure it lives in one line and starts withFeature
orIssue
in the correct format.For generated code changes, please checkout below instructions first:
https://github.com/aws/aws-sdk-ruby/blob/version-3/CONTRIBUTING.md
Thank you for your contribution!