From 3fe7d4b990acc8839843f0771fc2570b2e3d7cf2 Mon Sep 17 00:00:00 2001 From: Richard Wang Date: Thu, 3 Jul 2025 11:41:32 -0700 Subject: [PATCH 01/13] Add user agent plugin and test --- .../lib/smithy-client/plugins/user_agent.rb | 59 +++++++++++++++++++ .../smithy-client/plugins/user_agent_spec.rb | 32 ++++++++++ gems/smithy/lib/smithy/welds/plugins.rb | 4 +- 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 gems/smithy-client/lib/smithy-client/plugins/user_agent.rb create mode 100644 gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb diff --git a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb new file mode 100644 index 000000000..378ef7c3e --- /dev/null +++ b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +module Smithy + module Client + module Plugins + class UserAgent < Plugin + class Handler < Client::Handler + def call(context) + set_user_agent(context) + @handler.call(context) + end + + def set_user_agent(context) + context.http_request.headers['User-Agent'] = UserAgent.new(context).to_s + end + + class UserAgent + def initialize(context) + @context = context + end + + def to_s + ua = "smithy-ruby/#{File.read(File.expand_path('../../../VERSION', __dir__)).strip}" + ua += " #{os_metadata}" + ua += " #{language_metadata}" + ua.strip + end + + private + + def os_metadata + os = + case RbConfig::CONFIG['host_os'] + when /mac|darwin/ + 'macos' + when /linux|cygwin/ + 'linux' + when /mingw|mswin/ + 'windows' + else + 'other' + end + metadata = "os/#{os}" + local_version = Gem::Platform.local.version + metadata += "##{local_version}" if local_version + metadata + " md/#{RbConfig::CONFIG['host_cpu']}" + end + + def language_metadata + "lang/#{RUBY_ENGINE}##{RUBY_ENGINE_VERSION} md/#{RUBY_VERSION}" + end + end + end + + handler(Handler, step: :sign, priority: 5) + end + end + end +end diff --git a/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb new file mode 100644 index 000000000..098053978 --- /dev/null +++ b/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require_relative '../../spec_helper' + +require 'smithy-client/plugins/user_agent' + +module Smithy + module Client + module Plugins + describe UserAgent do + let(:client_class) do + client_class = ClientHelper.sample_client.const_get(:Client) + client_class.clear_plugins + client_class.add_plugin(DummySendPlugin) + client_class.add_plugin(UserAgent) + client_class + end + + let(:client) { client_class.new } + + it 'adds user agent header to request' do + resp = client.operation + ua_header = resp.context.http_request.headers['user-agent'] + expect(ua_header).to_not be_nil + expect(ua_header).to include('smithy-ruby') + expect(ua_header).to include('os') + expect(ua_header).to include('lang/ruby') + end + end + end + end +end \ No newline at end of file diff --git a/gems/smithy/lib/smithy/welds/plugins.rb b/gems/smithy/lib/smithy/welds/plugins.rb index c84ce6380..305901547 100644 --- a/gems/smithy/lib/smithy/welds/plugins.rb +++ b/gems/smithy/lib/smithy/welds/plugins.rb @@ -17,6 +17,7 @@ require 'smithy-client/plugins/retry_errors' require 'smithy-client/plugins/sign_requests' require 'smithy-client/plugins/stub_responses' +require 'smithy-client/plugins/user_agent' module Smithy module Welds @@ -46,7 +47,8 @@ def add_plugins Smithy::Client::Plugins::ResponseTarget => { require_path: "#{base_path}/response_target" }, Smithy::Client::Plugins::RetryErrors => { require_path: "#{base_path}/retry_errors" }, Smithy::Client::Plugins::SignRequests => { require_path: "#{base_path}/sign_requests" }, - Smithy::Client::Plugins::StubResponses => { require_path: "#{base_path}/stub_responses" } + Smithy::Client::Plugins::StubResponses => { require_path: "#{base_path}/stub_responses" }, + Smithy::Client::Plugins::UserAgent => { require_path: "#{base_path}/user_agent" } } end end From ce6a7c0807c1d6c81ae7f77a810e4bd925067715 Mon Sep 17 00:00:00 2001 From: Richard Wang Date: Mon, 7 Jul 2025 09:37:17 -0700 Subject: [PATCH 02/13] Reformat header --- .../lib/smithy-client/plugins/user_agent.rb | 14 +++++++------- .../spec/smithy-client/plugins/user_agent_spec.rb | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb index 378ef7c3e..95ab6a3aa 100644 --- a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb +++ b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb @@ -11,7 +11,7 @@ def call(context) end def set_user_agent(context) - context.http_request.headers['User-Agent'] = UserAgent.new(context).to_s + context.http_request.headers['User-Agent'] = UserAgent.new(context) end class UserAgent @@ -20,8 +20,8 @@ def initialize(context) end def to_s - ua = "smithy-ruby/#{File.read(File.expand_path('../../../VERSION', __dir__)).strip}" - ua += " #{os_metadata}" + ua = "smithy-ruby/#{Smithy::Client::VERSION}" + ua += " (#{os_metadata})" ua += " #{language_metadata}" ua.strip end @@ -40,14 +40,14 @@ def os_metadata else 'other' end - metadata = "os/#{os}" + metadata = os.to_s local_version = Gem::Platform.local.version - metadata += "##{local_version}" if local_version - metadata + " md/#{RbConfig::CONFIG['host_cpu']}" + metadata += " #{local_version}" if local_version + metadata + "; #{RbConfig::CONFIG['host_cpu']}" end def language_metadata - "lang/#{RUBY_ENGINE}##{RUBY_ENGINE_VERSION} md/#{RUBY_VERSION}" + "ruby/#{RUBY_VERSION}" end end end diff --git a/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb index 098053978..9ef204b7d 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb @@ -23,8 +23,8 @@ module Plugins ua_header = resp.context.http_request.headers['user-agent'] expect(ua_header).to_not be_nil expect(ua_header).to include('smithy-ruby') - expect(ua_header).to include('os') - expect(ua_header).to include('lang/ruby') + expect(ua_header).to include('macos').or include('linux').or include('windows').or include('other') + expect(ua_header).to include('ruby') end end end From 90a5dfe415415f93e85bb55719a4f7e8144a0179 Mon Sep 17 00:00:00 2001 From: Richard Wang Date: Mon, 7 Jul 2025 11:31:57 -0700 Subject: [PATCH 03/13] Reformat --- gems/smithy-client/lib/smithy-client/plugins/user_agent.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb index 95ab6a3aa..986c01f69 100644 --- a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb +++ b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb @@ -21,8 +21,8 @@ def initialize(context) def to_s ua = "smithy-ruby/#{Smithy::Client::VERSION}" - ua += " (#{os_metadata})" - ua += " #{language_metadata}" + ua += " (#{os_metadata};" + ua += " #{language_metadata})" ua.strip end From 70d742171893078ee9f19699f965aa0ca5e35bc2 Mon Sep 17 00:00:00 2001 From: Richard Wang Date: Tue, 8 Jul 2025 08:37:29 -0700 Subject: [PATCH 04/13] Fix weld plugins after merge --- gems/smithy/lib/smithy/welds/plugins.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/gems/smithy/lib/smithy/welds/plugins.rb b/gems/smithy/lib/smithy/welds/plugins.rb index a297dedf9..ffc2cb583 100644 --- a/gems/smithy/lib/smithy/welds/plugins.rb +++ b/gems/smithy/lib/smithy/welds/plugins.rb @@ -47,7 +47,6 @@ def add_plugins Smithy::Client::Plugins::ResolveAuth => { require_path: "#{base_path}/resolve_auth" }, Smithy::Client::Plugins::ResponseTarget => { require_path: "#{base_path}/response_target" }, Smithy::Client::Plugins::RetryErrors => { require_path: "#{base_path}/retry_errors" }, - Smithy::Client::Plugins::SignRequests => { require_path: "#{base_path}/sign_requests" }, Smithy::Client::Plugins::StubResponses => { require_path: "#{base_path}/stub_responses" }, Smithy::Client::Plugins::UserAgent => { require_path: "#{base_path}/user_agent" } } From d5ce19ba50bc12c4ea7141fe693e2294cbf8e719 Mon Sep 17 00:00:00 2001 From: Richard Wang Date: Wed, 9 Jul 2025 13:50:45 -0700 Subject: [PATCH 05/13] Add user agent suffix --- gems/smithy-client/lib/smithy-client/plugins/user_agent.rb | 3 +++ .../spec/smithy-client/plugins/user_agent_spec.rb | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb index 986c01f69..661fb5198 100644 --- a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb +++ b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb @@ -4,6 +4,8 @@ module Smithy module Client module Plugins class UserAgent < Plugin + option(:user_agent_suffix) + class Handler < Client::Handler def call(context) set_user_agent(context) @@ -23,6 +25,7 @@ def to_s ua = "smithy-ruby/#{Smithy::Client::VERSION}" ua += " (#{os_metadata};" ua += " #{language_metadata})" + ua += " #{@context.config.user_agent_suffix}" if @context.config.user_agent_suffix ua.strip end diff --git a/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb index 9ef204b7d..997fb5312 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb @@ -26,6 +26,13 @@ module Plugins expect(ua_header).to include('macos').or include('linux').or include('windows').or include('other') expect(ua_header).to include('ruby') end + + it 'adds user agent suffix to user agent string when configured' do + client = client_class.new(user_agent_suffix: 'test-suffix') + resp = client.operation + ua_header = resp.context.http_request.headers['user-agent'] + expect(ua_header).to end_with('test-suffix') + end end end end From fcd5ab774009569d0a948919dc9dbcca62f0a1f4 Mon Sep 17 00:00:00 2001 From: Richard Wang Date: Thu, 10 Jul 2025 09:10:07 -0700 Subject: [PATCH 06/13] PR comments --- .../lib/smithy-client/plugins/user_agent.rb | 15 +++++++++------ .../smithy-client/plugins/user_agent_spec.rb | 19 ++++++------------- gems/smithy/lib/smithy/welds/plugins.rb | 2 +- projections/shapes/lib/shapes/client.rb | 4 ++++ projections/shapes/sig/shapes/client.rbs | 1 + projections/weather/lib/weather/client.rb | 4 ++++ projections/weather/sig/weather/client.rbs | 1 + 7 files changed, 26 insertions(+), 20 deletions(-) diff --git a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb index 661fb5198..41578d69a 100644 --- a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb +++ b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb @@ -3,19 +3,22 @@ module Smithy module Client module Plugins + # @api private class UserAgent < Plugin - option(:user_agent_suffix) + option( + :user_agent_suffix, + doc_type: String, + docstring: 'The suffix appended to the user agent string.' + ) + # @api private class Handler < Client::Handler def call(context) - set_user_agent(context) + context.http_request.headers['User-Agent'] = UserAgent.new(context).to_s @handler.call(context) end - def set_user_agent(context) - context.http_request.headers['User-Agent'] = UserAgent.new(context) - end - + # @api private class UserAgent def initialize(context) @context = context diff --git a/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb index 997fb5312..2efe720f7 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb @@ -8,17 +8,10 @@ module Smithy module Client module Plugins describe UserAgent do - let(:client_class) do - client_class = ClientHelper.sample_client.const_get(:Client) - client_class.clear_plugins - client_class.add_plugin(DummySendPlugin) - client_class.add_plugin(UserAgent) - client_class - end - - let(:client) { client_class.new } + let(:client_class) { ClientHelper.sample_client.const_get(:Client) } + let(:client) { client_class.new(stub_responses: true) } - it 'adds user agent header to request' do + it 'adds a user agent header to request' do resp = client.operation ua_header = resp.context.http_request.headers['user-agent'] expect(ua_header).to_not be_nil @@ -27,8 +20,8 @@ module Plugins expect(ua_header).to include('ruby') end - it 'adds user agent suffix to user agent string when configured' do - client = client_class.new(user_agent_suffix: 'test-suffix') + it 'adds a user agent suffix to user agent string when configured' do + client = client_class.new(user_agent_suffix: 'test-suffix', stub_responses: true) resp = client.operation ua_header = resp.context.http_request.headers['user-agent'] expect(ua_header).to end_with('test-suffix') @@ -36,4 +29,4 @@ module Plugins end end end -end \ No newline at end of file +end diff --git a/gems/smithy/lib/smithy/welds/plugins.rb b/gems/smithy/lib/smithy/welds/plugins.rb index ffc2cb583..f6e8c451c 100644 --- a/gems/smithy/lib/smithy/welds/plugins.rb +++ b/gems/smithy/lib/smithy/welds/plugins.rb @@ -28,7 +28,7 @@ def for?(_service) true end - def add_plugins + def add_plugins # rubocop:disable Metrics/MethodLength base_path = 'smithy-client/plugins' { Smithy::Client::Plugins::ChecksumRequired => { require_path: "#{base_path}/checksum_required" }, diff --git a/projections/shapes/lib/shapes/client.rb b/projections/shapes/lib/shapes/client.rb index 6f518b2a5..0dd0b843f 100644 --- a/projections/shapes/lib/shapes/client.rb +++ b/projections/shapes/lib/shapes/client.rb @@ -20,6 +20,7 @@ require 'smithy-client/plugins/response_target' require 'smithy-client/plugins/retry_errors' require 'smithy-client/plugins/stub_responses' +require 'smithy-client/plugins/user_agent' module ShapeService # An API client for ShapeService. @@ -47,6 +48,7 @@ class Client < Smithy::Client::Base add_plugin(Smithy::Client::Plugins::ResponseTarget) add_plugin(Smithy::Client::Plugins::RetryErrors) add_plugin(Smithy::Client::Plugins::StubResponses) + add_plugin(Smithy::Client::Plugins::UserAgent) # @param options [Hash] Client options # @option options [Boolean] :adaptive_retry_wait_to_fill (true) @@ -158,6 +160,8 @@ class Client < Smithy::Client::Base # By default fake responses are generated and returned. You can specify the response data # to return or errors to raise by calling {Stubs#stub_responses}. # @see Stubs + # @option options [String] :user_agent_suffix + # The suffix appended to the user agent string. # @option options [Boolean] :validate_params (true) # When `true`, request parameters are validated before sending the request. def initialize(*options) diff --git a/projections/shapes/sig/shapes/client.rbs b/projections/shapes/sig/shapes/client.rbs index 9fa100136..ec08f21b4 100644 --- a/projections/shapes/sig/shapes/client.rbs +++ b/projections/shapes/sig/shapes/client.rbs @@ -34,6 +34,7 @@ module ShapeService ?retry_max_attempts: Integer, ?retry_strategy: String | Class, ?stub_responses: bool, + ?user_agent_suffix: String, ?validate_params: bool, ) -> void | (?Hash[Symbol, untyped]) -> void diff --git a/projections/weather/lib/weather/client.rb b/projections/weather/lib/weather/client.rb index 231a2f2bc..ebedf0a50 100644 --- a/projections/weather/lib/weather/client.rb +++ b/projections/weather/lib/weather/client.rb @@ -20,6 +20,7 @@ require 'smithy-client/plugins/response_target' require 'smithy-client/plugins/retry_errors' require 'smithy-client/plugins/stub_responses' +require 'smithy-client/plugins/user_agent' module Weather # An API client for Weather. @@ -47,6 +48,7 @@ class Client < Smithy::Client::Base add_plugin(Smithy::Client::Plugins::ResponseTarget) add_plugin(Smithy::Client::Plugins::RetryErrors) add_plugin(Smithy::Client::Plugins::StubResponses) + add_plugin(Smithy::Client::Plugins::UserAgent) # @param options [Hash] Client options # @option options [Boolean] :adaptive_retry_wait_to_fill (true) @@ -158,6 +160,8 @@ class Client < Smithy::Client::Base # By default fake responses are generated and returned. You can specify the response data # to return or errors to raise by calling {Stubs#stub_responses}. # @see Stubs + # @option options [String] :user_agent_suffix + # The suffix appended to the user agent string. # @option options [Boolean] :validate_params (true) # When `true`, request parameters are validated before sending the request. def initialize(*options) diff --git a/projections/weather/sig/weather/client.rbs b/projections/weather/sig/weather/client.rbs index 9dbfa5cec..79293ecdc 100644 --- a/projections/weather/sig/weather/client.rbs +++ b/projections/weather/sig/weather/client.rbs @@ -34,6 +34,7 @@ module Weather ?retry_max_attempts: Integer, ?retry_strategy: String | Class, ?stub_responses: bool, + ?user_agent_suffix: String, ?validate_params: bool, ) -> void | (?Hash[Symbol, untyped]) -> void From 921460562b6fd819014f2334274d2728f817b1c7 Mon Sep 17 00:00:00 2001 From: Richard Wang Date: Thu, 10 Jul 2025 09:54:34 -0700 Subject: [PATCH 07/13] Change doc type --- gems/smithy-client/lib/smithy-client/plugins/user_agent.rb | 2 +- .../smithy-client/spec/smithy-client/plugins/user_agent_spec.rb | 2 -- projections/shapes/lib/shapes/client.rb | 2 +- projections/shapes/sig/shapes/client.rbs | 2 +- projections/weather/lib/weather/client.rb | 2 +- projections/weather/sig/weather/client.rbs | 2 +- 6 files changed, 5 insertions(+), 7 deletions(-) diff --git a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb index 41578d69a..ed471f15e 100644 --- a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb +++ b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb @@ -7,7 +7,7 @@ module Plugins class UserAgent < Plugin option( :user_agent_suffix, - doc_type: String, + doc_type: 'header', docstring: 'The suffix appended to the user agent string.' ) diff --git a/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb b/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb index 2efe720f7..c7d8db060 100644 --- a/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb +++ b/gems/smithy-client/spec/smithy-client/plugins/user_agent_spec.rb @@ -2,8 +2,6 @@ require_relative '../../spec_helper' -require 'smithy-client/plugins/user_agent' - module Smithy module Client module Plugins diff --git a/projections/shapes/lib/shapes/client.rb b/projections/shapes/lib/shapes/client.rb index 0dd0b843f..b0c1bda67 100644 --- a/projections/shapes/lib/shapes/client.rb +++ b/projections/shapes/lib/shapes/client.rb @@ -160,7 +160,7 @@ class Client < Smithy::Client::Base # By default fake responses are generated and returned. You can specify the response data # to return or errors to raise by calling {Stubs#stub_responses}. # @see Stubs - # @option options [String] :user_agent_suffix + # @option options [header] :user_agent_suffix # The suffix appended to the user agent string. # @option options [Boolean] :validate_params (true) # When `true`, request parameters are validated before sending the request. diff --git a/projections/shapes/sig/shapes/client.rbs b/projections/shapes/sig/shapes/client.rbs index ec08f21b4..0d477415b 100644 --- a/projections/shapes/sig/shapes/client.rbs +++ b/projections/shapes/sig/shapes/client.rbs @@ -34,7 +34,7 @@ module ShapeService ?retry_max_attempts: Integer, ?retry_strategy: String | Class, ?stub_responses: bool, - ?user_agent_suffix: String, + ?user_agent_suffix: header, ?validate_params: bool, ) -> void | (?Hash[Symbol, untyped]) -> void diff --git a/projections/weather/lib/weather/client.rb b/projections/weather/lib/weather/client.rb index ebedf0a50..01c2be082 100644 --- a/projections/weather/lib/weather/client.rb +++ b/projections/weather/lib/weather/client.rb @@ -160,7 +160,7 @@ class Client < Smithy::Client::Base # By default fake responses are generated and returned. You can specify the response data # to return or errors to raise by calling {Stubs#stub_responses}. # @see Stubs - # @option options [String] :user_agent_suffix + # @option options [header] :user_agent_suffix # The suffix appended to the user agent string. # @option options [Boolean] :validate_params (true) # When `true`, request parameters are validated before sending the request. diff --git a/projections/weather/sig/weather/client.rbs b/projections/weather/sig/weather/client.rbs index 79293ecdc..1824fe2fe 100644 --- a/projections/weather/sig/weather/client.rbs +++ b/projections/weather/sig/weather/client.rbs @@ -34,7 +34,7 @@ module Weather ?retry_max_attempts: Integer, ?retry_strategy: String | Class, ?stub_responses: bool, - ?user_agent_suffix: String, + ?user_agent_suffix: header, ?validate_params: bool, ) -> void | (?Hash[Symbol, untyped]) -> void From 2ac88b2d7dee6a972c7b9d36f81bb5eb3264a0e9 Mon Sep 17 00:00:00 2001 From: Richard Wang Date: Thu, 10 Jul 2025 10:21:33 -0700 Subject: [PATCH 08/13] Fix docstring --- gems/smithy-client/lib/smithy-client/plugins/user_agent.rb | 4 ++-- projections/shapes/lib/shapes/client.rb | 4 ++-- projections/shapes/sig/shapes/client.rbs | 2 +- projections/weather/lib/weather/client.rb | 4 ++-- projections/weather/sig/weather/client.rbs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb index ed471f15e..2b2c3cb4f 100644 --- a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb +++ b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb @@ -7,8 +7,8 @@ module Plugins class UserAgent < Plugin option( :user_agent_suffix, - doc_type: 'header', - docstring: 'The suffix appended to the user agent string.' + doc_type: String, + docstring: 'The suffix appended to the user agent header.' ) # @api private diff --git a/projections/shapes/lib/shapes/client.rb b/projections/shapes/lib/shapes/client.rb index b0c1bda67..5470d5806 100644 --- a/projections/shapes/lib/shapes/client.rb +++ b/projections/shapes/lib/shapes/client.rb @@ -160,8 +160,8 @@ class Client < Smithy::Client::Base # By default fake responses are generated and returned. You can specify the response data # to return or errors to raise by calling {Stubs#stub_responses}. # @see Stubs - # @option options [header] :user_agent_suffix - # The suffix appended to the user agent string. + # @option options [String] :user_agent_suffix + # The suffix appended to the user agent header. # @option options [Boolean] :validate_params (true) # When `true`, request parameters are validated before sending the request. def initialize(*options) diff --git a/projections/shapes/sig/shapes/client.rbs b/projections/shapes/sig/shapes/client.rbs index 0d477415b..ec08f21b4 100644 --- a/projections/shapes/sig/shapes/client.rbs +++ b/projections/shapes/sig/shapes/client.rbs @@ -34,7 +34,7 @@ module ShapeService ?retry_max_attempts: Integer, ?retry_strategy: String | Class, ?stub_responses: bool, - ?user_agent_suffix: header, + ?user_agent_suffix: String, ?validate_params: bool, ) -> void | (?Hash[Symbol, untyped]) -> void diff --git a/projections/weather/lib/weather/client.rb b/projections/weather/lib/weather/client.rb index 01c2be082..7072043c0 100644 --- a/projections/weather/lib/weather/client.rb +++ b/projections/weather/lib/weather/client.rb @@ -160,8 +160,8 @@ class Client < Smithy::Client::Base # By default fake responses are generated and returned. You can specify the response data # to return or errors to raise by calling {Stubs#stub_responses}. # @see Stubs - # @option options [header] :user_agent_suffix - # The suffix appended to the user agent string. + # @option options [String] :user_agent_suffix + # The suffix appended to the user agent header. # @option options [Boolean] :validate_params (true) # When `true`, request parameters are validated before sending the request. def initialize(*options) diff --git a/projections/weather/sig/weather/client.rbs b/projections/weather/sig/weather/client.rbs index 1824fe2fe..79293ecdc 100644 --- a/projections/weather/sig/weather/client.rbs +++ b/projections/weather/sig/weather/client.rbs @@ -34,7 +34,7 @@ module Weather ?retry_max_attempts: Integer, ?retry_strategy: String | Class, ?stub_responses: bool, - ?user_agent_suffix: header, + ?user_agent_suffix: String, ?validate_params: bool, ) -> void | (?Hash[Symbol, untyped]) -> void From d79939bf8e84bffb0fe6a6ba9feba6c8a2c90832 Mon Sep 17 00:00:00 2001 From: Richard Wang Date: Thu, 10 Jul 2025 12:15:02 -0700 Subject: [PATCH 09/13] Update docstring --- gems/smithy-client/lib/smithy-client/plugins/user_agent.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb index 2b2c3cb4f..d8779f650 100644 --- a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb +++ b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb @@ -8,8 +8,11 @@ class UserAgent < Plugin option( :user_agent_suffix, doc_type: String, - docstring: 'The suffix appended to the user agent header.' - ) + docstring: <<~DOCS) + An optional string that is appended to the User-Agent header. + The default User-Agent includes the smithy-client version, + the ruby platform and version, and host OS information. + DOCS # @api private class Handler < Client::Handler From e5cb6ab5392bb99dbcdd1d246bee6936b647ca60 Mon Sep 17 00:00:00 2001 From: Richard Wang Date: Thu, 10 Jul 2025 13:15:56 -0700 Subject: [PATCH 10/13] Add feature id tracking --- .../lib/smithy-client/pageable_response.rb | 10 +++++++++- .../lib/smithy-client/waiters/poller.rb | 12 +++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/gems/smithy-client/lib/smithy-client/pageable_response.rb b/gems/smithy-client/lib/smithy-client/pageable_response.rb index 99b5e8844..f3f16b4dc 100644 --- a/gems/smithy-client/lib/smithy-client/pageable_response.rb +++ b/gems/smithy-client/lib/smithy-client/pageable_response.rb @@ -92,7 +92,7 @@ def next_page(params = {}) raise LastPageError, self if last_page? params = next_page_params(params) - context.client.send(context.operation_name, params) + with_metric { context.client.send(context.operation_name, params) } end # Yields the current and each following response to the given block. @@ -133,6 +133,14 @@ def next_page_params(params) new_params = context.params.except(*prev_tokens) new_params.merge!(@paginator.next_tokens(data).merge(params)) end + + def with_metric(&block) + Thread.current[:aws_sdk_core_user_agent_metric] ||= [] + Thread.current[:aws_sdk_core_user_agent_metric] << 'C' + block.call + ensure + Thread.current[:aws_sdk_core_user_agent_metric].pop + end end end end diff --git a/gems/smithy-client/lib/smithy-client/waiters/poller.rb b/gems/smithy-client/lib/smithy-client/waiters/poller.rb index 3fdd25649..18842af35 100644 --- a/gems/smithy-client/lib/smithy-client/waiters/poller.rb +++ b/gems/smithy-client/lib/smithy-client/waiters/poller.rb @@ -15,7 +15,9 @@ def call(client, params) @input = params request = client.build_request(@operation_name, params) request.handlers.remove(Plugins::RaiseResponseErrors::Handler) - response = request.send_request + response = with_metric do + request.send_request + end status = evaluate_acceptors(response) [response, status.to_sym] end @@ -87,6 +89,14 @@ def anyStringEquals?(actual, expected) actual.any? { |value| value == expected } end # rubocop:enable Naming/MethodName + + def with_metric(&block) + Thread.current[:aws_sdk_core_user_agent_metric] ||= [] + Thread.current[:aws_sdk_core_user_agent_metric] << 'B' + block.call + ensure + Thread.current[:aws_sdk_core_user_agent_metric].pop + end end end end From 2277c362fb50a3fe7ad5abdf36ad52209ab91b75 Mon Sep 17 00:00:00 2001 From: Richard Wang Date: Thu, 10 Jul 2025 13:18:44 -0700 Subject: [PATCH 11/13] Regenerate projections --- projections/shapes/lib/shapes/client.rb | 4 +++- projections/weather/lib/weather/client.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/projections/shapes/lib/shapes/client.rb b/projections/shapes/lib/shapes/client.rb index 5470d5806..889aef27e 100644 --- a/projections/shapes/lib/shapes/client.rb +++ b/projections/shapes/lib/shapes/client.rb @@ -161,7 +161,9 @@ class Client < Smithy::Client::Base # to return or errors to raise by calling {Stubs#stub_responses}. # @see Stubs # @option options [String] :user_agent_suffix - # The suffix appended to the user agent header. + # An optional string that is appended to the User-Agent header. + # The default User-Agent includes the smithy-client version, + # the ruby platform and version, and host OS information. # @option options [Boolean] :validate_params (true) # When `true`, request parameters are validated before sending the request. def initialize(*options) diff --git a/projections/weather/lib/weather/client.rb b/projections/weather/lib/weather/client.rb index 7072043c0..9dbe1532e 100644 --- a/projections/weather/lib/weather/client.rb +++ b/projections/weather/lib/weather/client.rb @@ -161,7 +161,9 @@ class Client < Smithy::Client::Base # to return or errors to raise by calling {Stubs#stub_responses}. # @see Stubs # @option options [String] :user_agent_suffix - # The suffix appended to the user agent header. + # An optional string that is appended to the User-Agent header. + # The default User-Agent includes the smithy-client version, + # the ruby platform and version, and host OS information. # @option options [Boolean] :validate_params (true) # When `true`, request parameters are validated before sending the request. def initialize(*options) From 130930adca411e828b6b8b72a37c36147cd56d26 Mon Sep 17 00:00:00 2001 From: Richard Wang Date: Thu, 10 Jul 2025 13:30:39 -0700 Subject: [PATCH 12/13] Rubocop --- gems/smithy-client/lib/smithy-client/plugins/user_agent.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb index d8779f650..683c671e4 100644 --- a/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb +++ b/gems/smithy-client/lib/smithy-client/plugins/user_agent.rb @@ -10,7 +10,7 @@ class UserAgent < Plugin doc_type: String, docstring: <<~DOCS) An optional string that is appended to the User-Agent header. - The default User-Agent includes the smithy-client version, + The default User-Agent includes the smithy-client version, the ruby platform and version, and host OS information. DOCS From 92431f87fbe7dc187e4689ed204a7017716cf9f9 Mon Sep 17 00:00:00 2001 From: Richard Wang Date: Thu, 10 Jul 2025 13:56:25 -0700 Subject: [PATCH 13/13] Revert with_metrics --- .../lib/smithy-client/pageable_response.rb | 10 +--------- .../lib/smithy-client/waiters/poller.rb | 12 +----------- projections/shapes/lib/shapes/client.rb | 2 +- projections/weather/lib/weather/client.rb | 2 +- 4 files changed, 4 insertions(+), 22 deletions(-) diff --git a/gems/smithy-client/lib/smithy-client/pageable_response.rb b/gems/smithy-client/lib/smithy-client/pageable_response.rb index f3f16b4dc..99b5e8844 100644 --- a/gems/smithy-client/lib/smithy-client/pageable_response.rb +++ b/gems/smithy-client/lib/smithy-client/pageable_response.rb @@ -92,7 +92,7 @@ def next_page(params = {}) raise LastPageError, self if last_page? params = next_page_params(params) - with_metric { context.client.send(context.operation_name, params) } + context.client.send(context.operation_name, params) end # Yields the current and each following response to the given block. @@ -133,14 +133,6 @@ def next_page_params(params) new_params = context.params.except(*prev_tokens) new_params.merge!(@paginator.next_tokens(data).merge(params)) end - - def with_metric(&block) - Thread.current[:aws_sdk_core_user_agent_metric] ||= [] - Thread.current[:aws_sdk_core_user_agent_metric] << 'C' - block.call - ensure - Thread.current[:aws_sdk_core_user_agent_metric].pop - end end end end diff --git a/gems/smithy-client/lib/smithy-client/waiters/poller.rb b/gems/smithy-client/lib/smithy-client/waiters/poller.rb index 18842af35..3fdd25649 100644 --- a/gems/smithy-client/lib/smithy-client/waiters/poller.rb +++ b/gems/smithy-client/lib/smithy-client/waiters/poller.rb @@ -15,9 +15,7 @@ def call(client, params) @input = params request = client.build_request(@operation_name, params) request.handlers.remove(Plugins::RaiseResponseErrors::Handler) - response = with_metric do - request.send_request - end + response = request.send_request status = evaluate_acceptors(response) [response, status.to_sym] end @@ -89,14 +87,6 @@ def anyStringEquals?(actual, expected) actual.any? { |value| value == expected } end # rubocop:enable Naming/MethodName - - def with_metric(&block) - Thread.current[:aws_sdk_core_user_agent_metric] ||= [] - Thread.current[:aws_sdk_core_user_agent_metric] << 'B' - block.call - ensure - Thread.current[:aws_sdk_core_user_agent_metric].pop - end end end end diff --git a/projections/shapes/lib/shapes/client.rb b/projections/shapes/lib/shapes/client.rb index 889aef27e..13d353430 100644 --- a/projections/shapes/lib/shapes/client.rb +++ b/projections/shapes/lib/shapes/client.rb @@ -162,7 +162,7 @@ class Client < Smithy::Client::Base # @see Stubs # @option options [String] :user_agent_suffix # An optional string that is appended to the User-Agent header. - # The default User-Agent includes the smithy-client version, + # The default User-Agent includes the smithy-client version, # the ruby platform and version, and host OS information. # @option options [Boolean] :validate_params (true) # When `true`, request parameters are validated before sending the request. diff --git a/projections/weather/lib/weather/client.rb b/projections/weather/lib/weather/client.rb index 9dbe1532e..b2d2c06a4 100644 --- a/projections/weather/lib/weather/client.rb +++ b/projections/weather/lib/weather/client.rb @@ -162,7 +162,7 @@ class Client < Smithy::Client::Base # @see Stubs # @option options [String] :user_agent_suffix # An optional string that is appended to the User-Agent header. - # The default User-Agent includes the smithy-client version, + # The default User-Agent includes the smithy-client version, # the ruby platform and version, and host OS information. # @option options [Boolean] :validate_params (true) # When `true`, request parameters are validated before sending the request.