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

Reduce memory usage from aws-partitions #3122

Merged
merged 24 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d9e6e1a
Reduce memory usage from aws-partitions
alextwoods Oct 7, 2024
b345948
Merge branch 'version-3' into optimize_partitions
alextwoods Oct 7, 2024
32a3e8e
fix whitespace
alextwoods Oct 7, 2024
167dc31
Fix issue in new aws_partition method
alextwoods Oct 7, 2024
3b43d7c
Fix failures
alextwoods Oct 7, 2024
25b35fc
Update partition metadata method to match v4
alextwoods Oct 8, 2024
2c38cd7
Merge branch 'version-3' into optimize_partitions
alextwoods Oct 8, 2024
b9a04ed
Remove commented out code
alextwoods Oct 8, 2024
13f2c57
DEMO ALTERNATIVE: use cfg.endpoint_resolver to resolve config.endpoint
alextwoods Oct 9, 2024
b539c55
Revert "DEMO ALTERNATIVE: use cfg.endpoint_resolver to resolve config…
alextwoods Oct 9, 2024
61e8de1
Update min partition version
alextwoods Oct 9, 2024
5516a5a
Add struct attr_reader on DefaultResolver
alextwoods Oct 9, 2024
3074fce
Remove endpoint plugin from ep2.0 services
alextwoods Oct 9, 2024
5d7415d
Merge remote-tracking branch 'origin/version-3' into optimize_partitions
alextwoods Oct 9, 2024
f8b9164
Revert "Remove endpoint plugin from ep2.0 services"
alextwoods Oct 9, 2024
3ea1baf
New approach - use the EndpointProvider (ep2) to resolve a default en…
alextwoods Oct 9, 2024
d47a8c5
Revert changes to searhose endpoint plugin
alextwoods Oct 10, 2024
a17e870
Fix tests
alextwoods Oct 10, 2024
1e9ffce
Merge branch 'version-3' into optimize_partitions
alextwoods Oct 15, 2024
f329550
New approach, change endpoint generation and add create class method
alextwoods Oct 15, 2024
bc78ca6
Merge branch 'version-3' into optimize_partitions
alextwoods Oct 15, 2024
8f903a3
PR cleanups
alextwoods Oct 16, 2024
01a729c
Bump mincore versions
alextwoods Oct 16, 2024
2d04869
Merge branch 'version-3' into optimize_partitions
alextwoods Oct 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gems/aws-partitions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Feature - Add partition metadata module, allowing access without loading entire partitions.json.

1.987.0 (2024-10-08)
------------------

Expand Down
1 change: 1 addition & 0 deletions gems/aws-partitions/lib/aws-partitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_relative 'aws-partitions/partition_list'
require_relative 'aws-partitions/region'
require_relative 'aws-partitions/service'
require_relative 'aws-partitions/metadata'

require 'json'

Expand Down
32 changes: 32 additions & 0 deletions gems/aws-partitions/lib/aws-partitions/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

module Aws
module Partitions
# @api private
module Metadata
class << self

# aws.partition(region: string) Option<Partition>
def partition(region)
partition =
partitions.find { |p| p['regions']&.fetch(region, nil) } ||
partitions.find { |p| region.match(p['regionRegex']) } ||
partitions.find { |p| p['id'] == 'aws' }

return nil unless partition

partition['outputs']
end

def partitions
@partitions ||= default_partition_metadata
end

def default_partition_metadata
path = File.expand_path('../../../partitions-metadata.json', __FILE__)
JSON.parse(File.read(path), freeze: true)['partitions']
end
end
end
end
end
2 changes: 2 additions & 0 deletions gems/aws-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Feature - reduce memory usage by not using legacy endpoint data unless required.

3.209.1 (2024-09-25)
------------------

Expand Down
2 changes: 1 addition & 1 deletion gems/aws-sdk-core/aws-sdk-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
spec.files = Dir['LICENSE.txt', 'CHANGELOG.md', 'VERSION', 'lib/**/*.rb', 'sig/**/*.rbs', 'ca-bundle.crt']

spec.add_dependency('jmespath', '~> 1', '>= 1.6.1') # necessary for secure jmespath JSON parsing
spec.add_dependency('aws-partitions', '~> 1', '>= 1.651.0') # necessary for new endpoint resolution
spec.add_dependency('aws-partitions', '~> 1', '>= 1.988.0') # necessary for new endpoint resolution
spec.add_dependency('aws-sigv4', '~> 1.9') # necessary for s3 express auth/native sigv4a support
spec.add_dependency('aws-eventstream', '~> 1', '>= 1.3.0') # necessary for binary eventstream

Expand Down
9 changes: 1 addition & 8 deletions gems/aws-sdk-core/lib/aws-sdk-core/endpoints/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,7 @@ def self.valid_host_label?(value, allow_sub_domains = false)

# aws.partition(value: string) Option<Partition>
def self.aws_partition(value)
partition =
Aws::Partitions.find { |p| p.region?(value) } ||
Aws::Partitions.find { |p| value.match(p.region_regex) } ||
Aws::Partitions.find { |p| p.name == 'aws' }

return nil unless partition

partition.metadata
Aws::Partitions::Metadata.partition(value)
end

# aws.parseArn(value: string) Option<ARN>
Expand Down
28 changes: 20 additions & 8 deletions gems/aws-sdk-core/lib/aws-sdk-core/plugins/regional_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RegionalEndpoint < Seahorse::Client::Plugin
* `ENV['AWS_DEFAULT_REGION']`
* `~/.aws/credentials`
* `~/.aws/config`
DOCS
DOCS
resolve_region(cfg)
end

Expand All @@ -35,7 +35,7 @@ class RegionalEndpoint < Seahorse::Client::Plugin
* `Aws.config[:sigv4a_signing_region_set]`
* `ENV['AWS_SIGV4A_SIGNING_REGION_SET']`
* `~/.aws/config`
DOCS
DOCS
resolve_sigv4a_signing_region_set(cfg)
end

Expand All @@ -44,7 +44,7 @@ class RegionalEndpoint < Seahorse::Client::Plugin
docstring: <<-DOCS) do |cfg|
When set to `true`, dualstack enabled endpoints (with `.aws` TLD)
will be used if available.
DOCS
DOCS
resolve_use_dualstack_endpoint(cfg)
end

Expand All @@ -54,7 +54,7 @@ class RegionalEndpoint < Seahorse::Client::Plugin
When set to `true`, fips compatible endpoints will be used if available.
When a `fips` region is used, the region is normalized and this config
is set to `true`.
DOCS
DOCS
resolve_use_fips_endpoint(cfg)
end

Expand All @@ -67,15 +67,15 @@ class RegionalEndpoint < Seahorse::Client::Plugin
docstring: <<-DOCS) do |cfg|
Setting to true disables use of endpoint URLs provided via environment
variables and the shared configuration file.
DOCS
DOCS
resolve_ignore_configured_endpoint_urls(cfg)
end

option(:endpoint, doc_type: String, docstring: <<-DOCS) do |cfg|
The client endpoint is normally constructed from the `:region`
option. You should only configure an `:endpoint` when connecting
to test or custom endpoints. This should be a valid HTTP(S) URI.
DOCS
DOCS
resolve_endpoint(cfg)
end

Expand Down Expand Up @@ -150,7 +150,18 @@ def resolve_endpoint(cfg)
# that a custom endpoint has NOT been configured by the user
cfg.override_config(:regional_endpoint, true)
alextwoods marked this conversation as resolved.
Show resolved Hide resolved

resolve_legacy_endpoint(cfg)
# preserve legacy (pre EP2) client.config.endpoint still resolves a value
# when needed.
struct = cfg.instance_variable_get(:@struct)
alextwoods marked this conversation as resolved.
Show resolved Hide resolved
if struct
# need a separate proc to get namespace/private access to resolve_legacy_endpoint
alextwoods marked this conversation as resolved.
Show resolved Hide resolved
b = proc { resolve_legacy_endpoint(struct) }
struct.define_singleton_method(:endpoint) { @endpoint ||= b.call }
nil
else
# backup in case internal details of config resolver change
resolve_legacy_endpoint(cfg)
end
end

# get a custom configured endpoint from ENV or configuration
Expand Down Expand Up @@ -213,7 +224,7 @@ def resolve_legacy_endpoint(cfg)
sts_regional = cfg.sts_regional_endpoints
end

Aws::Partitions::EndpointProvider.resolve(
endpoint = Aws::Partitions::EndpointProvider.resolve(
alextwoods marked this conversation as resolved.
Show resolved Hide resolved
cfg.region,
endpoint_prefix,
sts_regional,
Expand All @@ -222,6 +233,7 @@ def resolve_legacy_endpoint(cfg)
fips: cfg.use_fips_endpoint
}
)
URI(endpoint)
end
end
end
Expand Down
14 changes: 8 additions & 6 deletions gems/aws-sdk-core/lib/seahorse/client/plugins/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ def add_handlers(handlers, config)
end

def after_initialize(client)
endpoint = client.config.endpoint
if endpoint.nil?
msg = "missing required option `:endpoint'"
raise ArgumentError, msg
end
# validate endpoint only if user set a custom endpoint
return if client.config.respond_to?(:regional_endpoint) && client.config.regional_endpoint

endpoint = client.config.endpoint
endpoint = URI.parse(endpoint.to_s)
if URI::HTTPS === endpoint or URI::HTTP === endpoint
client.config.endpoint = endpoint
Expand All @@ -42,7 +40,11 @@ def after_initialize(client)
class Handler < Client::Handler

def call(context)
context.http_request.endpoint = URI.parse(context.config.endpoint.to_s)
if !context.config.respond_to?(:regional_endpoint) || # generic
alextwoods marked this conversation as resolved.
Show resolved Hide resolved
!context.config.regional_endpoint || # custom endpoint
!context.config.respond_to?(:endpoint_provider) # legacy/pre-ep2/no rules
context.http_request.endpoint = URI.parse(context.config.endpoint.to_s)
end
@handler.call(context)
end

Expand Down
Loading