Skip to content

Commit 1869c67

Browse files
authored
Additional metrics collection (#3099)
1 parent 2988c41 commit 1869c67

File tree

14 files changed

+41
-77
lines changed

14 files changed

+41
-77
lines changed

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/endpoints_module.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ def initialize(options)
4242

4343
# @return [Array<EndpointParameter>]
4444
attr_reader :parameters
45-
46-
def has_endpoint_built_in?
47-
parameters.any? { |p| p.param_data['builtIn'] == 'SDK::Endpoint' }
48-
end
4945
end
5046

5147
class EndpointParameter
@@ -155,7 +151,7 @@ def built_in_client_context_param_value(param_data)
155151
when 'AWS::S3::DisableMultiRegionAccessPoints'
156152
'context.config.s3_disable_multiregion_access_points'
157153
when 'SDK::Endpoint'
158-
'endpoint'
154+
'context.config.regional_endpoint ? nil : context.config.endpoint.to_s'
159155
end
160156
end
161157

build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/spec/endpoint_provider_spec_class.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def initialize(options)
5151
operation_name: Underscore.underscore(
5252
operation_inputs_test['operationName']
5353
),
54-
operation_params: operation_inputs_test['operationParams'] || [],
55-
built_in_params: operation_inputs_test['builtInParams'] || [],
56-
client_params: operation_inputs_test['clientParams'] || []
54+
operation_params: operation_inputs_test['operationParams'] || {},
55+
built_in_params: operation_inputs_test['builtInParams'] || {},
56+
client_params: operation_inputs_test['clientParams'] || {}
5757
)
5858
end
5959
end
@@ -117,12 +117,13 @@ def initialize(options)
117117
@client_params = options[:client_params].map do |k,v|
118118
Param.new(Underscore.underscore(k), v)
119119
end
120-
121120
@client_params += options[:built_in_params].map do |k,v|
122121
built_in_to_param(k, v)
123122
end
124-
# the expected default of UseGlobalEndpoint does not match the SDK's default value
125-
if @service.identifier == 's3' && !options[:built_in_params].include?('AWS::S3::UseGlobalEndpoint')
123+
# the expected default of UseGlobalEndpoint in rules
124+
# does not match the Ruby SDK's default value
125+
if @service.identifier == 's3' &&
126+
!options[:built_in_params].include?('AWS::S3::UseGlobalEndpoint')
126127
@client_params << built_in_to_param('AWS::S3::UseGlobalEndpoint', false)
127128
end
128129
end

build_tools/aws-sdk-code-generator/templates/endpoints_module.mustache

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ module {{module_name}}
1111
{{#endpoint_classes}}
1212
class {{name}}
1313
def self.build(context)
14-
{{#has_endpoint_built_in?}}
15-
unless context.config.regional_endpoint
16-
endpoint = context.config.endpoint.to_s
17-
end
18-
{{/has_endpoint_built_in?}}
1914
{{module_name}}::EndpointParameters.new(
2015
{{#parameters}}
2116
{{#static_string?}}

build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,20 @@ module {{module_name}}
4444
context[:auth_scheme] =
4545
Aws::Endpoints.resolve_auth_scheme(context, endpoint)
4646

47-
@handler.call(context)
47+
with_metrics(context) { @handler.call(context) }
4848
end
4949

5050
private
5151

52+
def with_metrics(context, &block)
53+
metrics = []
54+
metrics << 'ENDPOINT_OVERRIDE' unless context.config.regional_endpoint
55+
if context[:auth_scheme] && context[:auth_scheme]['name'] == 'sigv4a'
56+
metrics << 'SIGV4A_SIGNING'
57+
end
58+
Aws::Plugins::UserAgent.metric(*metrics, &block)
59+
end
60+
5261
def apply_endpoint_headers(context, headers)
5362
headers.each do |key, values|
5463
value = values

build_tools/aws-sdk-code-generator/templates/spec/endpoint_provider_spec_class.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module {{module_name}}
1111
subject { {{module_name}}::EndpointProvider.new }
1212

1313
{{#endpoint_tests}}
14-
context '{{documentation}}' do
14+
context "{{{documentation}}}" do
1515
let(:expected) do
1616
{{{expect}}}
1717
end

build_tools/services.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ class ServiceEnumerator
1010
MANIFEST_PATH = File.expand_path('../../services.json', __FILE__)
1111

1212
# Minimum `aws-sdk-core` version for new gem builds
13-
MINIMUM_CORE_VERSION = "3.203.0"
13+
MINIMUM_CORE_VERSION = "3.204.1"
1414

1515
# Minimum `aws-sdk-core` version for new S3 gem builds
16-
MINIMUM_CORE_VERSION_S3 = "3.203.0"
16+
MINIMUM_CORE_VERSION_S3 = "3.204.1"
1717

1818
EVENTSTREAM_PLUGIN = "Aws::Plugins::EventStreamConfiguration"
1919

gems/aws-sdk-core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Unreleased Changes
22
------------------
33

4+
* Issue - Additional metrics collection in the User-Agent plugin.
5+
46
3.204.0 (2024-09-10)
57
------------------
68

gems/aws-sdk-core/lib/aws-sdk-core/plugins/regional_endpoint.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def handle_legacy_pseudo_regions(cfg)
205205
cfg.override_config(:region, new_region)
206206
end
207207
end
208+
208209
# set a default endpoint in config using legacy (endpoints.json) resolver
209210
def resolve_legacy_endpoint(cfg)
210211
endpoint_prefix = cfg.api.metadata['endpointPrefix']

gems/aws-sdk-core/lib/aws-sdk-core/plugins/user_agent.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ class UserAgent < Seahorse::Client::Plugin
1717
"S3_CRYPTO_V2": "I",
1818
"S3_EXPRESS_BUCKET": "J",
1919
"S3_ACCESS_GRANTS": "K",
20-
"GZIP_REQUEST_COMPRESSION": "L"
20+
"GZIP_REQUEST_COMPRESSION": "L",
21+
"PROTOCOL_RPC_V2_CBOR": "M",
22+
"ENDPOINT_OVERRIDE": "N",
23+
"SIGV4A_SIGNING": "S"
2124
}
2225
METRICS
2326

@@ -45,15 +48,13 @@ def self.feature(_feature, &block)
4548
block.call
4649
end
4750

48-
def self.metric(metric, &block)
51+
def self.metric(*metrics, &block)
4952
Thread.current[:aws_sdk_core_user_agent_metric] ||= []
50-
Thread.current[:aws_sdk_core_user_agent_metric] << METRICS[metric]
53+
metrics = metrics.map { |metric| METRICS[metric] }.compact
54+
Thread.current[:aws_sdk_core_user_agent_metric].concat(metrics)
5155
block.call
5256
ensure
53-
Thread.current[:aws_sdk_core_user_agent_metric].pop
54-
if Thread.current[:aws_sdk_core_user_agent_metric].empty?
55-
Thread.current[:aws_sdk_core_user_agent_metric] = nil
56-
end
57+
Thread.current[:aws_sdk_core_user_agent_metric].pop(metrics.size)
5758
end
5859

5960
# @api private
@@ -166,7 +167,10 @@ def framework_metadata
166167
end
167168

168169
def metric_metadata
169-
return unless Thread.current[:aws_sdk_core_user_agent_metric]
170+
if Thread.current[:aws_sdk_core_user_agent_metric].nil? ||
171+
Thread.current[:aws_sdk_core_user_agent_metric].empty?
172+
return
173+
end
170174

171175
metrics = Thread.current[:aws_sdk_core_user_agent_metric].join(',')
172176
# Metric metadata is limited to 1024 bytes

gems/aws-sdk-core/lib/aws-sdk-core/rpc_v2/handler.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ class Handler < Seahorse::Client::Handler
77
# @return [Seahorse::Client::Response]
88
def call(context)
99
build_request(context)
10-
response = @handler.call(context)
10+
response = with_metric { @handler.call(context) }
1111
response.on(200..299) { |resp| resp.data = parse_body(context) }
1212
response.on(200..599) { |_resp| apply_request_id(context) }
1313
response
1414
end
1515

1616
private
1717

18+
def with_metric(&block)
19+
Aws::Plugins::UserAgent.metric('PROTOCOL_RPC_V2_CBOR', &block)
20+
end
21+
1822
def build_request(context)
1923
context.http_request.headers['smithy-protocol'] = 'rpc-v2-cbor'
2024
context.http_request.http_method = 'POST'

0 commit comments

Comments
 (0)