Skip to content

Commit

Permalink
Additional metrics collection
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp committed Sep 6, 2024
1 parent aa27c50 commit a4cd361
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ def initialize(options)

# @return [Array<EndpointParameter>]
attr_reader :parameters

def has_endpoint_built_in?
parameters.any? { |p| p.param_data['builtIn'] == 'SDK::Endpoint' }
end
end

class EndpointParameter
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions build_tools/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
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
------------------

* Issue - Additional metrics collection in the User-Agent plugin.

3.203.0 (2024-09-03)
------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
8 changes: 7 additions & 1 deletion gems/aws-sdk-core/lib/aws-sdk-core/plugins/sign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
5 changes: 4 additions & 1 deletion gems/aws-sdk-core/lib/aws-sdk-core/plugins/user_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion gems/aws-sdk-core/lib/aws-sdk-core/rpc_v2/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ 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
end

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'
Expand Down
14 changes: 0 additions & 14 deletions gems/aws-sdk-core/spec/aws/plugins/request_compression_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions gems/aws-sdk-core/spec/aws/plugins/retry_errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions gems/aws-sdk-s3/spec/plugins/express_session_auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a4cd361

Please sign in to comment.