From a4cd3615667b45f17f5ceb672ac451a25cd8248e Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Fri, 6 Sep 2024 11:23:30 -0400 Subject: [PATCH 1/7] Additional metrics collection --- .../views/endpoints_module.rb | 6 +----- .../views/spec/endpoint_provider_spec_class.rb | 13 +++++++------ .../templates/endpoints_module.mustache | 5 ----- .../templates/endpoints_plugin.mustache | 8 +++++++- .../spec/endpoint_provider_spec_class.mustache | 2 +- build_tools/services.rb | 4 ++-- gems/aws-sdk-core/CHANGELOG.md | 2 ++ .../aws-sdk-core/plugins/regional_endpoint.rb | 1 + .../lib/aws-sdk-core/plugins/sign.rb | 8 +++++++- .../lib/aws-sdk-core/plugins/user_agent.rb | 5 ++++- .../lib/aws-sdk-core/rpc_v2/handler.rb | 6 +++++- .../aws/plugins/request_compression_spec.rb | 14 -------------- .../aws/plugins/retry_errors_legacy_spec.rb | 9 --------- .../spec/aws/plugins/retry_errors_spec.rb | 18 ------------------ .../spec/plugins/express_session_auth_spec.rb | 7 ------- 15 files changed, 37 insertions(+), 71 deletions(-) diff --git a/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/endpoints_module.rb b/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/endpoints_module.rb index 1dfab1d7550..cc075d0af08 100644 --- a/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/endpoints_module.rb +++ b/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/endpoints_module.rb @@ -42,10 +42,6 @@ def initialize(options) # @return [Array] attr_reader :parameters - - def has_endpoint_built_in? - parameters.any? { |p| p.param_data['builtIn'] == 'SDK::Endpoint' } - end end class EndpointParameter @@ -155,7 +151,7 @@ def built_in_client_context_param_value(param_data) when 'AWS::S3::DisableMultiRegionAccessPoints' 'context.config.s3_disable_multiregion_access_points' when 'SDK::Endpoint' - 'endpoint' + 'context.config.regional_endpoint ? nil : context.config.endpoint.to_s' end end diff --git a/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/spec/endpoint_provider_spec_class.rb b/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/spec/endpoint_provider_spec_class.rb index 4b5dee46a59..69bbb10a877 100644 --- a/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/spec/endpoint_provider_spec_class.rb +++ b/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/spec/endpoint_provider_spec_class.rb @@ -51,9 +51,9 @@ def initialize(options) operation_name: Underscore.underscore( operation_inputs_test['operationName'] ), - operation_params: operation_inputs_test['operationParams'] || [], - built_in_params: operation_inputs_test['builtInParams'] || [], - client_params: operation_inputs_test['clientParams'] || [] + operation_params: operation_inputs_test['operationParams'] || {}, + built_in_params: operation_inputs_test['builtInParams'] || {}, + client_params: operation_inputs_test['clientParams'] || {} ) end end @@ -117,12 +117,13 @@ def initialize(options) @client_params = options[:client_params].map do |k,v| Param.new(Underscore.underscore(k), v) end - @client_params += options[:built_in_params].map do |k,v| built_in_to_param(k, v) end - # the expected default of UseGlobalEndpoint does not match the SDK's default value - if @service.identifier == 's3' && !options[:built_in_params].include?('AWS::S3::UseGlobalEndpoint') + # the expected default of UseGlobalEndpoint in rules + # does not match the Ruby SDK's default value + if @service.identifier == 's3' && + !options[:built_in_params].include?('AWS::S3::UseGlobalEndpoint') @client_params << built_in_to_param('AWS::S3::UseGlobalEndpoint', false) end end diff --git a/build_tools/aws-sdk-code-generator/templates/endpoints_module.mustache b/build_tools/aws-sdk-code-generator/templates/endpoints_module.mustache index 7ae625341e5..a93a5860b8a 100644 --- a/build_tools/aws-sdk-code-generator/templates/endpoints_module.mustache +++ b/build_tools/aws-sdk-code-generator/templates/endpoints_module.mustache @@ -11,11 +11,6 @@ module {{module_name}} {{#endpoint_classes}} class {{name}} def self.build(context) - {{#has_endpoint_built_in?}} - unless context.config.regional_endpoint - endpoint = context.config.endpoint.to_s - end - {{/has_endpoint_built_in?}} {{module_name}}::EndpointParameters.new( {{#parameters}} {{#static_string?}} diff --git a/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache b/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache index 6bdef3195e6..be262787e97 100644 --- a/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache +++ b/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache @@ -44,11 +44,17 @@ module {{module_name}} context[:auth_scheme] = Aws::Endpoints.resolve_auth_scheme(context, endpoint) - @handler.call(context) + with_metric(context[:endpoint_params]) { @handler.call(context) } end private + def with_metric(params, &block) + return block.call unless params && params.endpoint + + Aws::Endpoints.with_metric('ENDPOINT_OVERRIDE', &block) + end + def apply_endpoint_headers(context, headers) headers.each do |key, values| value = values diff --git a/build_tools/aws-sdk-code-generator/templates/spec/endpoint_provider_spec_class.mustache b/build_tools/aws-sdk-code-generator/templates/spec/endpoint_provider_spec_class.mustache index 1a3e9536d2c..b86ebcfc4e6 100644 --- a/build_tools/aws-sdk-code-generator/templates/spec/endpoint_provider_spec_class.mustache +++ b/build_tools/aws-sdk-code-generator/templates/spec/endpoint_provider_spec_class.mustache @@ -11,7 +11,7 @@ module {{module_name}} subject { {{module_name}}::EndpointProvider.new } {{#endpoint_tests}} - context '{{documentation}}' do + context "{{{documentation}}}" do let(:expected) do {{{expect}}} end diff --git a/build_tools/services.rb b/build_tools/services.rb index 0909815bc96..9973da7b128 100644 --- a/build_tools/services.rb +++ b/build_tools/services.rb @@ -10,10 +10,10 @@ class ServiceEnumerator MANIFEST_PATH = File.expand_path('../../services.json', __FILE__) # Minimum `aws-sdk-core` version for new gem builds - MINIMUM_CORE_VERSION = "3.203.0" + MINIMUM_CORE_VERSION = "3.203.1" # Minimum `aws-sdk-core` version for new S3 gem builds - MINIMUM_CORE_VERSION_S3 = "3.203.0" + MINIMUM_CORE_VERSION_S3 = "3.203.1" EVENTSTREAM_PLUGIN = "Aws::Plugins::EventStreamConfiguration" diff --git a/gems/aws-sdk-core/CHANGELOG.md b/gems/aws-sdk-core/CHANGELOG.md index 67f220208fa..31270215f88 100644 --- a/gems/aws-sdk-core/CHANGELOG.md +++ b/gems/aws-sdk-core/CHANGELOG.md @@ -1,6 +1,8 @@ Unreleased Changes ------------------ +* Issue - Additional metrics collection in the User-Agent plugin. + 3.203.0 (2024-09-03) ------------------ diff --git a/gems/aws-sdk-core/lib/aws-sdk-core/plugins/regional_endpoint.rb b/gems/aws-sdk-core/lib/aws-sdk-core/plugins/regional_endpoint.rb index dd82bf90421..ede2b2d8b6c 100644 --- a/gems/aws-sdk-core/lib/aws-sdk-core/plugins/regional_endpoint.rb +++ b/gems/aws-sdk-core/lib/aws-sdk-core/plugins/regional_endpoint.rb @@ -205,6 +205,7 @@ def handle_legacy_pseudo_regions(cfg) cfg.override_config(:region, new_region) end end + # set a default endpoint in config using legacy (endpoints.json) resolver def resolve_legacy_endpoint(cfg) endpoint_prefix = cfg.api.metadata['endpointPrefix'] diff --git a/gems/aws-sdk-core/lib/aws-sdk-core/plugins/sign.rb b/gems/aws-sdk-core/lib/aws-sdk-core/plugins/sign.rb index 5a447707222..3c5755a5d60 100644 --- a/gems/aws-sdk-core/lib/aws-sdk-core/plugins/sign.rb +++ b/gems/aws-sdk-core/lib/aws-sdk-core/plugins/sign.rb @@ -50,11 +50,17 @@ def call(context) ) signer.sign(context) end - @handler.call(context) + with_metric(context[:auth_scheme]) { @handler.call(context) } end private + def with_metric(auth_scheme, &block) + return block.call unless auth_scheme && auth_scheme['name'] == 'sigv4a' + + Aws::Plugins::UserAgent.metric('SIGV4A_SIGNING', &block) + end + def v2_signing?(config) # 's3' is legacy signing, 'v4' is default config.respond_to?(:signature_version) && diff --git a/gems/aws-sdk-core/lib/aws-sdk-core/plugins/user_agent.rb b/gems/aws-sdk-core/lib/aws-sdk-core/plugins/user_agent.rb index df7d94e1bd4..ceaca7a960b 100644 --- a/gems/aws-sdk-core/lib/aws-sdk-core/plugins/user_agent.rb +++ b/gems/aws-sdk-core/lib/aws-sdk-core/plugins/user_agent.rb @@ -17,7 +17,10 @@ class UserAgent < Seahorse::Client::Plugin "S3_CRYPTO_V2": "I", "S3_EXPRESS_BUCKET": "J", "S3_ACCESS_GRANTS": "K", - "GZIP_REQUEST_COMPRESSION": "L" + "GZIP_REQUEST_COMPRESSION": "L", + "PROTOCOL_RPC_V2_CBOR": "M", + "ENDPOINT_OVERRIDE": "N", + "SIGV4A_SIGNING": "S" } METRICS diff --git a/gems/aws-sdk-core/lib/aws-sdk-core/rpc_v2/handler.rb b/gems/aws-sdk-core/lib/aws-sdk-core/rpc_v2/handler.rb index 278daee7f57..0e0d4049184 100644 --- a/gems/aws-sdk-core/lib/aws-sdk-core/rpc_v2/handler.rb +++ b/gems/aws-sdk-core/lib/aws-sdk-core/rpc_v2/handler.rb @@ -7,7 +7,7 @@ class Handler < Seahorse::Client::Handler # @return [Seahorse::Client::Response] def call(context) build_request(context) - response = @handler.call(context) + response = with_metric { @handler.call(context) } response.on(200..299) { |resp| resp.data = parse_body(context) } response.on(200..599) { |_resp| apply_request_id(context) } response @@ -15,6 +15,10 @@ def call(context) private + def with_metric(&block) + Aws::Plugins::UserAgent.metric('PROTOCOL_RPC_V2_CBOR', &block) + end + def build_request(context) context.http_request.headers['smithy-protocol'] = 'rpc-v2-cbor' context.http_request.http_method = 'POST' diff --git a/gems/aws-sdk-core/spec/aws/plugins/request_compression_spec.rb b/gems/aws-sdk-core/spec/aws/plugins/request_compression_spec.rb index 897b1a7ef8a..48f61ae884b 100644 --- a/gems/aws-sdk-core/spec/aws/plugins/request_compression_spec.rb +++ b/gems/aws-sdk-core/spec/aws/plugins/request_compression_spec.rb @@ -121,13 +121,6 @@ def expect_uncompressed_body(resp, body) end context 'request compression operation' do - it 'sets user-agent metric for the operation' do - resp = client.some_operation(body: uncompressed_body) - metric = Aws::Plugins::UserAgent::METRICS['GZIP_REQUEST_COMPRESSION'] - expect(resp.context.http_request.headers['User-Agent']) - .to include("m/#{metric}") - end - it 'compresses the body and sets the content-encoding header' do resp = client.some_operation(body: uncompressed_body) expect(resp.context.http_request.headers['Content-Encoding']).to eq('gzip') @@ -165,13 +158,6 @@ def expect_uncompressed_body(resp, body) expect_uncompressed_body(resp, small_body) end - it 'sets user-agent metric for a streaming operation' do - resp = client.operation_streaming(body: 'body') - metric = Aws::Plugins::UserAgent::METRICS['GZIP_REQUEST_COMPRESSION'] - expect(resp.context.http_request.headers['User-Agent']) - .to include("m/#{metric}") - end - it 'compresses a large streaming body' do large_body = StringIO.new('.' * 16_385) client.stub_responses(:operation_streaming, -> (context) do diff --git a/gems/aws-sdk-core/spec/aws/plugins/retry_errors_legacy_spec.rb b/gems/aws-sdk-core/spec/aws/plugins/retry_errors_legacy_spec.rb index 13f66c5ab3f..067231e8004 100644 --- a/gems/aws-sdk-core/spec/aws/plugins/retry_errors_legacy_spec.rb +++ b/gems/aws-sdk-core/spec/aws/plugins/retry_errors_legacy_spec.rb @@ -32,15 +32,6 @@ module Plugins client = RetryErrorsSvc::Client.new(retry_mode: 'legacy', region: 'us-west-2') expect(client.handlers.entries.map(&:handler_class)).to include(RetryErrors::LegacyHandler) end - - it 'sets user-agent metric' do - client = RetryErrorsSvc::Client.new(retry_mode: 'legacy', region: 'us-west-2') - stub_request(:post, client.config.endpoint) - resp = client.example_operation - metric = Aws::Plugins::UserAgent::METRICS['RETRY_MODE_LEGACY'] - expect(resp.context.http_request.headers['User-Agent']) - .to include("m/#{metric}") - end end describe RetryErrors::LegacyHandler do diff --git a/gems/aws-sdk-core/spec/aws/plugins/retry_errors_spec.rb b/gems/aws-sdk-core/spec/aws/plugins/retry_errors_spec.rb index 82838e29bdd..9b56972f352 100644 --- a/gems/aws-sdk-core/spec/aws/plugins/retry_errors_spec.rb +++ b/gems/aws-sdk-core/spec/aws/plugins/retry_errors_spec.rb @@ -106,24 +106,6 @@ module Plugins .to receive(:correct_clock_skew).and_return('true') expect(client.config.correct_clock_skew).to eq(true) end - - it 'sets user-agent metric for standard' do - client = RetryErrorsSvc::Client.new(retry_mode: 'standard', region: 'us-west-2') - stub_request(:post, client.config.endpoint) - resp = client.example_operation - metric = Aws::Plugins::UserAgent::METRICS['RETRY_MODE_STANDARD'] - expect(resp.context.http_request.headers['User-Agent']) - .to include("m/#{metric}") - end - - it 'sets user-agent metric for adaptive' do - client = RetryErrorsSvc::Client.new(retry_mode: 'adaptive', region: 'us-west-2') - stub_request(:post, client.config.endpoint) - resp = client.example_operation - metric = Aws::Plugins::UserAgent::METRICS['RETRY_MODE_ADAPTIVE'] - expect(resp.context.http_request.headers['User-Agent']) - .to include("m/#{metric}") - end end describe RetryErrors::Handler do diff --git a/gems/aws-sdk-s3/spec/plugins/express_session_auth_spec.rb b/gems/aws-sdk-s3/spec/plugins/express_session_auth_spec.rb index f2ffd887b86..60d165a3237 100644 --- a/gems/aws-sdk-s3/spec/plugins/express_session_auth_spec.rb +++ b/gems/aws-sdk-s3/spec/plugins/express_session_auth_spec.rb @@ -128,13 +128,6 @@ module S3 end client.get_object(bucket: bucket, key: 'key') end - - it 'sets user-agent metric' do - resp = client.get_object(bucket: 'bucket--use1-az2--x-s3', key: 'key') - metric = Aws::Plugins::UserAgent::METRICS['S3_EXPRESS_BUCKET'] - expect(resp.context.http_request.headers['User-Agent']) - .to include("m/#{metric}") - end end # does not have http checksum trait, but requires a checksum (md5) From 70351d5cf1a3d2da71b77ac2e150c06f8892e374 Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Fri, 6 Sep 2024 11:36:23 -0400 Subject: [PATCH 2/7] Fix failing tests --- .../aws-sdk-code-generator/templates/endpoints_plugin.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache b/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache index be262787e97..6c465a9ba75 100644 --- a/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache +++ b/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache @@ -50,7 +50,7 @@ module {{module_name}} private def with_metric(params, &block) - return block.call unless params && params.endpoint + return block.call unless params && params[:endpoint] Aws::Endpoints.with_metric('ENDPOINT_OVERRIDE', &block) end From 5e8cafd4c8cb34476e8946b111e5444d76fafbdb Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Fri, 6 Sep 2024 11:47:51 -0400 Subject: [PATCH 3/7] Fix typo --- .../aws-sdk-code-generator/templates/endpoints_plugin.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache b/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache index 6c465a9ba75..4ef6e5bf274 100644 --- a/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache +++ b/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache @@ -52,7 +52,7 @@ module {{module_name}} def with_metric(params, &block) return block.call unless params && params[:endpoint] - Aws::Endpoints.with_metric('ENDPOINT_OVERRIDE', &block) + Aws::Plugins::UserAgent.metric('ENDPOINT_OVERRIDE', &block) end def apply_endpoint_headers(context, headers) From 0cdb3ddd2c6dc60b1410593e3cf3ba87704fb0b1 Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Fri, 6 Sep 2024 12:04:07 -0400 Subject: [PATCH 4/7] Move sigv4a metric to endpoints plugin --- .../templates/endpoints_plugin.mustache | 16 +++++++++++++--- .../lib/aws-sdk-core/plugins/sign.rb | 8 +------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache b/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache index 4ef6e5bf274..6cd71aa0281 100644 --- a/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache +++ b/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache @@ -44,17 +44,27 @@ module {{module_name}} context[:auth_scheme] = Aws::Endpoints.resolve_auth_scheme(context, endpoint) - with_metric(context[:endpoint_params]) { @handler.call(context) } + with_endpoint_metric(context[:endpoint_params]) do + with_sigv4a_metric(context[:auth_scheme]) do + @handler.call(context) + end + end end private - def with_metric(params, &block) - return block.call unless params && params[:endpoint] + def with_endpoint_metric(endpoint_params, &block) + return block.call unless endpoint_params && endpoint_params[:endpoint] Aws::Plugins::UserAgent.metric('ENDPOINT_OVERRIDE', &block) end + def with_sigv4a_metric(auth_scheme, &block) + return block.call unless auth_scheme && auth_scheme['name'] == 'sigv4a' + + Aws::Plugins::UserAgent.metric('SIGV4A_SIGNING', &block) + end + def apply_endpoint_headers(context, headers) headers.each do |key, values| value = values diff --git a/gems/aws-sdk-core/lib/aws-sdk-core/plugins/sign.rb b/gems/aws-sdk-core/lib/aws-sdk-core/plugins/sign.rb index 3c5755a5d60..5a447707222 100644 --- a/gems/aws-sdk-core/lib/aws-sdk-core/plugins/sign.rb +++ b/gems/aws-sdk-core/lib/aws-sdk-core/plugins/sign.rb @@ -50,17 +50,11 @@ def call(context) ) signer.sign(context) end - with_metric(context[:auth_scheme]) { @handler.call(context) } + @handler.call(context) end private - def with_metric(auth_scheme, &block) - return block.call unless auth_scheme && auth_scheme['name'] == 'sigv4a' - - Aws::Plugins::UserAgent.metric('SIGV4A_SIGNING', &block) - end - def v2_signing?(config) # 's3' is legacy signing, 'v4' is default config.respond_to?(:signature_version) && From 856caf24b1829fa2e52134fe39c57c8cebceb0ff Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Fri, 6 Sep 2024 12:26:01 -0400 Subject: [PATCH 5/7] Use regional endpoint config for setting metric --- .../templates/endpoints_plugin.mustache | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache b/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache index 6cd71aa0281..a01193347d7 100644 --- a/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache +++ b/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache @@ -44,7 +44,7 @@ module {{module_name}} context[:auth_scheme] = Aws::Endpoints.resolve_auth_scheme(context, endpoint) - with_endpoint_metric(context[:endpoint_params]) do + with_endpoint_metric(context.config) do with_sigv4a_metric(context[:auth_scheme]) do @handler.call(context) end @@ -53,8 +53,8 @@ module {{module_name}} private - def with_endpoint_metric(endpoint_params, &block) - return block.call unless endpoint_params && endpoint_params[:endpoint] + def with_endpoint_metric(config, &block) + return block.call if config.regional_endpoint Aws::Plugins::UserAgent.metric('ENDPOINT_OVERRIDE', &block) end From b5eba79c825be16c39ee2a941a781fc06bd776fb Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Tue, 10 Sep 2024 21:06:18 -0400 Subject: [PATCH 6/7] PR feedback --- .../templates/endpoints_plugin.mustache | 23 +++++++------------ build_tools/services.rb | 4 ++-- .../lib/aws-sdk-core/plugins/user_agent.rb | 15 ++++++------ 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache b/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache index a01193347d7..834fb111a36 100644 --- a/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache +++ b/build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache @@ -44,25 +44,18 @@ module {{module_name}} context[:auth_scheme] = Aws::Endpoints.resolve_auth_scheme(context, endpoint) - with_endpoint_metric(context.config) do - with_sigv4a_metric(context[:auth_scheme]) do - @handler.call(context) - end - end + with_metrics(context) { @handler.call(context) } end private - def with_endpoint_metric(config, &block) - return block.call if config.regional_endpoint - - Aws::Plugins::UserAgent.metric('ENDPOINT_OVERRIDE', &block) - end - - def with_sigv4a_metric(auth_scheme, &block) - return block.call unless auth_scheme && auth_scheme['name'] == 'sigv4a' - - Aws::Plugins::UserAgent.metric('SIGV4A_SIGNING', &block) + def with_metrics(context, &block) + metrics = [] + metrics << 'ENDPOINT_OVERRIDE' unless context.config.regional_endpoint + if context[:auth_scheme] && context[:auth_scheme]['name'] == 'sigv4a' + metrics << 'SIGV4A_SIGNING' + end + Aws::Plugins::UserAgent.metric(*metrics, &block) end def apply_endpoint_headers(context, headers) diff --git a/build_tools/services.rb b/build_tools/services.rb index 9973da7b128..e68d393bea6 100644 --- a/build_tools/services.rb +++ b/build_tools/services.rb @@ -10,10 +10,10 @@ class ServiceEnumerator MANIFEST_PATH = File.expand_path('../../services.json', __FILE__) # Minimum `aws-sdk-core` version for new gem builds - MINIMUM_CORE_VERSION = "3.203.1" + MINIMUM_CORE_VERSION = "3.204.1" # Minimum `aws-sdk-core` version for new S3 gem builds - MINIMUM_CORE_VERSION_S3 = "3.203.1" + MINIMUM_CORE_VERSION_S3 = "3.204.1" EVENTSTREAM_PLUGIN = "Aws::Plugins::EventStreamConfiguration" diff --git a/gems/aws-sdk-core/lib/aws-sdk-core/plugins/user_agent.rb b/gems/aws-sdk-core/lib/aws-sdk-core/plugins/user_agent.rb index ceaca7a960b..0acec623f1d 100644 --- a/gems/aws-sdk-core/lib/aws-sdk-core/plugins/user_agent.rb +++ b/gems/aws-sdk-core/lib/aws-sdk-core/plugins/user_agent.rb @@ -48,15 +48,13 @@ def self.feature(_feature, &block) block.call end - def self.metric(metric, &block) + def self.metric(*metrics, &block) Thread.current[:aws_sdk_core_user_agent_metric] ||= [] - Thread.current[:aws_sdk_core_user_agent_metric] << METRICS[metric] + metrics = metrics.map { |metric| METRICS[metric] } + Thread.current[:aws_sdk_core_user_agent_metric].concat(metrics) block.call ensure - Thread.current[:aws_sdk_core_user_agent_metric].pop - if Thread.current[:aws_sdk_core_user_agent_metric].empty? - Thread.current[:aws_sdk_core_user_agent_metric] = nil - end + Thread.current[:aws_sdk_core_user_agent_metric].pop(metrics.size) end # @api private @@ -169,7 +167,10 @@ def framework_metadata end def metric_metadata - return unless Thread.current[:aws_sdk_core_user_agent_metric] + if Thread.current[:aws_sdk_core_user_agent_metric].nil? || + Thread.current[:aws_sdk_core_user_agent_metric].empty? + return + end metrics = Thread.current[:aws_sdk_core_user_agent_metric].join(',') # Metric metadata is limited to 1024 bytes From d0f22b2968338485f7ef7ced7ee661ecae797032 Mon Sep 17 00:00:00 2001 From: Matt Muller Date: Wed, 11 Sep 2024 12:14:38 -0400 Subject: [PATCH 7/7] PR feedback --- gems/aws-sdk-core/lib/aws-sdk-core/plugins/user_agent.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gems/aws-sdk-core/lib/aws-sdk-core/plugins/user_agent.rb b/gems/aws-sdk-core/lib/aws-sdk-core/plugins/user_agent.rb index 0acec623f1d..ac39fcbc37e 100644 --- a/gems/aws-sdk-core/lib/aws-sdk-core/plugins/user_agent.rb +++ b/gems/aws-sdk-core/lib/aws-sdk-core/plugins/user_agent.rb @@ -50,7 +50,7 @@ def self.feature(_feature, &block) def self.metric(*metrics, &block) Thread.current[:aws_sdk_core_user_agent_metric] ||= [] - metrics = metrics.map { |metric| METRICS[metric] } + metrics = metrics.map { |metric| METRICS[metric] }.compact Thread.current[:aws_sdk_core_user_agent_metric].concat(metrics) block.call ensure