gapic-common 0.22.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/README.md +5 -5
- data/lib/gapic/call_options/error_codes.rb +2 -60
- data/lib/gapic/call_options/retry_policy.rb +10 -109
- data/lib/gapic/call_options.rb +1 -1
- data/lib/gapic/common/error_codes.rb +74 -0
- data/lib/gapic/common/polling_harness.rb +82 -0
- data/lib/gapic/common/retry_policy.rb +255 -0
- data/lib/gapic/common/version.rb +1 -1
- data/lib/gapic/common.rb +1 -0
- data/lib/gapic/grpc/service_stub/channel.rb +4 -2
- data/lib/gapic/grpc/service_stub/channel_pool.rb +9 -2
- data/lib/gapic/grpc/service_stub/rpc_call.rb +120 -12
- data/lib/gapic/grpc/service_stub.rb +15 -3
- data/lib/gapic/headers.rb +5 -1
- data/lib/gapic/logging_concerns.rb +210 -0
- data/lib/gapic/operation/retry_policy.rb +25 -65
- data/lib/gapic/rest/client_stub.rb +91 -18
- data/lib/gapic/universe_domain_concerns.rb +2 -2
- metadata +40 -12
@@ -13,6 +13,7 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
require "googleauth"
|
16
|
+
require "gapic/logging_concerns"
|
16
17
|
require "gapic/rest/faraday_middleware"
|
17
18
|
require "gapic/universe_domain_concerns"
|
18
19
|
require "faraday/retry"
|
@@ -28,9 +29,11 @@ module Gapic
|
|
28
29
|
#
|
29
30
|
class ClientStub
|
30
31
|
include UniverseDomainConcerns
|
32
|
+
include LoggingConcerns
|
31
33
|
|
32
34
|
##
|
33
35
|
# Initializes with an endpoint and credentials
|
36
|
+
#
|
34
37
|
# @param endpoint [String] The endpoint of the API. Overrides any endpoint_template.
|
35
38
|
# @param endpoint_template [String] The endpoint of the API, where the
|
36
39
|
# universe domain component of the hostname is marked by the string in
|
@@ -41,12 +44,14 @@ module Gapic
|
|
41
44
|
# Credentials to send with calls in form of a googleauth credentials object.
|
42
45
|
# (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
|
43
46
|
# @param numeric_enums [Boolean] Whether to signal the server to JSON-encode enums as ints
|
44
|
-
#
|
45
47
|
# @param raise_faraday_errors [Boolean]
|
46
48
|
# Whether to raise Faraday errors instead of wrapping them in `Gapic::Rest::Error`
|
47
49
|
# Added for backwards compatibility.
|
48
50
|
# Default is `true`. All REST clients (except for old versions of `google-cloud-compute-v1`)
|
49
51
|
# should explicitly set this parameter to `false`.
|
52
|
+
# @param logger [Logger,:default,nil] An explicit logger to use, or one
|
53
|
+
# of the values `:default` (the default) to construct a default logger,
|
54
|
+
# or `nil` to disable logging explicitly.
|
50
55
|
#
|
51
56
|
# @yield [Faraday::Connection]
|
52
57
|
#
|
@@ -55,7 +60,10 @@ module Gapic
|
|
55
60
|
endpoint_template: nil,
|
56
61
|
universe_domain: nil,
|
57
62
|
numeric_enums: false,
|
58
|
-
raise_faraday_errors: true
|
63
|
+
raise_faraday_errors: true,
|
64
|
+
logging_system: nil,
|
65
|
+
service_name: nil,
|
66
|
+
logger: :default
|
59
67
|
setup_universe_domain universe_domain: universe_domain,
|
60
68
|
endpoint: endpoint,
|
61
69
|
endpoint_template: endpoint_template,
|
@@ -65,6 +73,12 @@ module Gapic
|
|
65
73
|
endpoint_url = "https://#{endpoint_url}" unless /^https?:/.match? endpoint_url
|
66
74
|
endpoint_url = endpoint_url.sub %r{/$}, ""
|
67
75
|
|
76
|
+
setup_logging logger: logger,
|
77
|
+
system_name: logging_system,
|
78
|
+
service: service_name,
|
79
|
+
endpoint: endpoint_url,
|
80
|
+
client_id: object_id
|
81
|
+
|
68
82
|
@numeric_enums = numeric_enums
|
69
83
|
|
70
84
|
@raise_faraday_errors = raise_faraday_errors
|
@@ -88,8 +102,8 @@ module Gapic
|
|
88
102
|
# @param options [::Gapic::CallOptions,Hash] gapic options to be applied
|
89
103
|
# to the REST call. Currently only timeout and headers are supported.
|
90
104
|
# @return [Faraday::Response]
|
91
|
-
def make_get_request uri:, params: {}, options: {}
|
92
|
-
make_http_request :get, uri: uri, body: nil, params: params, options: options
|
105
|
+
def make_get_request uri:, params: {}, options: {}, method_name: nil
|
106
|
+
make_http_request :get, uri: uri, body: nil, params: params, options: options, method_name: method_name
|
93
107
|
end
|
94
108
|
|
95
109
|
##
|
@@ -100,8 +114,8 @@ module Gapic
|
|
100
114
|
# @param options [::Gapic::CallOptions,Hash] gapic options to be applied
|
101
115
|
# to the REST call. Currently only timeout and headers are supported.
|
102
116
|
# @return [Faraday::Response]
|
103
|
-
def make_delete_request uri:, params: {}, options: {}
|
104
|
-
make_http_request :delete, uri: uri, body: nil, params: params, options: options
|
117
|
+
def make_delete_request uri:, params: {}, options: {}, method_name: nil
|
118
|
+
make_http_request :delete, uri: uri, body: nil, params: params, options: options, method_name: method_name
|
105
119
|
end
|
106
120
|
|
107
121
|
##
|
@@ -113,8 +127,8 @@ module Gapic
|
|
113
127
|
# @param options [::Gapic::CallOptions,Hash] gapic options to be applied
|
114
128
|
# to the REST call. Currently only timeout and headers are supported.
|
115
129
|
# @return [Faraday::Response]
|
116
|
-
def make_patch_request uri:, body:, params: {}, options: {}
|
117
|
-
make_http_request :patch, uri: uri, body: body, params: params, options: options
|
130
|
+
def make_patch_request uri:, body:, params: {}, options: {}, method_name: nil
|
131
|
+
make_http_request :patch, uri: uri, body: body, params: params, options: options, method_name: method_name
|
118
132
|
end
|
119
133
|
|
120
134
|
##
|
@@ -126,8 +140,8 @@ module Gapic
|
|
126
140
|
# @param options [::Gapic::CallOptions,Hash] gapic options to be applied
|
127
141
|
# to the REST call. Currently only timeout and headers are supported.
|
128
142
|
# @return [Faraday::Response]
|
129
|
-
def make_post_request uri:, body: nil, params: {}, options: {}
|
130
|
-
make_http_request :post, uri: uri, body: body, params: params, options: options
|
143
|
+
def make_post_request uri:, body: nil, params: {}, options: {}, method_name: nil
|
144
|
+
make_http_request :post, uri: uri, body: body, params: params, options: options, method_name: method_name
|
131
145
|
end
|
132
146
|
|
133
147
|
##
|
@@ -139,8 +153,8 @@ module Gapic
|
|
139
153
|
# @param options [::Gapic::CallOptions,Hash] gapic options to be applied
|
140
154
|
# to the REST call. Currently only timeout and headers are supported.
|
141
155
|
# @return [Faraday::Response]
|
142
|
-
def make_put_request uri:, body: nil, params: {}, options: {}
|
143
|
-
make_http_request :put, uri: uri, body: body, params: params, options: options
|
156
|
+
def make_put_request uri:, body: nil, params: {}, options: {}, method_name: nil
|
157
|
+
make_http_request :put, uri: uri, body: body, params: params, options: options, method_name: method_name
|
144
158
|
end
|
145
159
|
|
146
160
|
##
|
@@ -154,27 +168,38 @@ module Gapic
|
|
154
168
|
# @param is_server_streaming [Boolean] flag if method is streaming
|
155
169
|
# @yieldparam chunk [String] The chunk of data received during server streaming.
|
156
170
|
# @return [Faraday::Response]
|
157
|
-
def make_http_request verb,
|
171
|
+
def make_http_request verb,
|
172
|
+
uri:, body:, params:, options:,
|
173
|
+
is_server_streaming: false, method_name: nil,
|
174
|
+
&block
|
158
175
|
# Converts hash and nil to an options object
|
159
176
|
options = ::Gapic::CallOptions.new(**options.to_h) unless options.is_a? ::Gapic::CallOptions
|
160
177
|
deadline = calculate_deadline options
|
161
178
|
retried_exception = nil
|
162
179
|
next_timeout = get_timeout deadline
|
180
|
+
request_id = LoggingConcerns.random_uuid4
|
181
|
+
try_number = 1
|
163
182
|
|
164
183
|
begin
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
184
|
+
log_request method_name, request_id, try_number, body, options.metadata
|
185
|
+
response = base_make_http_request verb: verb, uri: uri, body: body,
|
186
|
+
params: params, metadata: options.metadata,
|
187
|
+
timeout: next_timeout,
|
188
|
+
is_server_streaming: is_server_streaming,
|
189
|
+
&block
|
190
|
+
log_response method_name, request_id, try_number, response, is_server_streaming
|
191
|
+
response
|
170
192
|
rescue ::Faraday::TimeoutError => e
|
193
|
+
log_response method_name, request_id, try_number, e, is_server_streaming
|
171
194
|
raise if @raise_faraday_errors
|
172
195
|
raise Gapic::Rest::DeadlineExceededError.wrap_faraday_error e, root_cause: retried_exception
|
173
196
|
rescue ::Faraday::Error => e
|
197
|
+
log_response method_name, request_id, try_number, e, is_server_streaming
|
174
198
|
next_timeout = get_timeout deadline
|
175
199
|
|
176
200
|
if check_retry?(next_timeout) && options.retry_policy.call(e)
|
177
201
|
retried_exception = e
|
202
|
+
try_number += 1
|
178
203
|
retry
|
179
204
|
end
|
180
205
|
|
@@ -251,6 +276,54 @@ module Gapic
|
|
251
276
|
|
252
277
|
timeout.positive?
|
253
278
|
end
|
279
|
+
|
280
|
+
def log_request method_name, request_id, try_number, body, metadata
|
281
|
+
return unless stub_logger
|
282
|
+
stub_logger.info do |entry|
|
283
|
+
entry.set_system_name
|
284
|
+
entry.set_service
|
285
|
+
entry.set "rpcName", method_name
|
286
|
+
entry.set "retryAttempt", try_number
|
287
|
+
entry.set "requestId", request_id
|
288
|
+
entry.message = "Sending request to #{entry.service}.#{method_name} (try #{try_number})"
|
289
|
+
end
|
290
|
+
body = body.to_s
|
291
|
+
metadata = metadata.to_h rescue {}
|
292
|
+
return if body.empty? && metadata.empty?
|
293
|
+
stub_logger.debug do |entry|
|
294
|
+
entry.set "requestId", request_id
|
295
|
+
entry.set "request", body
|
296
|
+
entry.set "headers", metadata
|
297
|
+
entry.message = "(request payload as JSON)"
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
def log_response method_name, request_id, try_number, response, is_server_streaming
|
302
|
+
return unless stub_logger
|
303
|
+
stub_logger.info do |entry|
|
304
|
+
entry.set_system_name
|
305
|
+
entry.set_service
|
306
|
+
entry.set "rpcName", method_name
|
307
|
+
entry.set "retryAttempt", try_number
|
308
|
+
entry.set "requestId", request_id
|
309
|
+
if response.is_a? StandardError
|
310
|
+
entry.set "exception", response.to_s
|
311
|
+
entry.message = "Received error for #{entry.service}.#{method_name} (try #{try_number}): #{response}"
|
312
|
+
elsif is_server_streaming
|
313
|
+
entry.message = "Receiving stream for #{entry.service}.#{method_name} (try #{try_number})"
|
314
|
+
else
|
315
|
+
entry.message = "Received response for #{entry.service}.#{method_name} (try #{try_number})"
|
316
|
+
end
|
317
|
+
end
|
318
|
+
return if is_server_streaming || !response.respond_to?(:body)
|
319
|
+
body = response.body.to_s
|
320
|
+
return if body.empty?
|
321
|
+
stub_logger.debug do |entry|
|
322
|
+
entry.set "requestId", request_id
|
323
|
+
entry.set "response", body
|
324
|
+
entry.message = "(response payload as JSON)"
|
325
|
+
end
|
326
|
+
end
|
254
327
|
end
|
255
328
|
end
|
256
329
|
end
|
@@ -60,11 +60,11 @@ module Gapic
|
|
60
60
|
raise ArgumentError, "endpoint or endpoint_template is required" if endpoint.nil? && endpoint_template.nil?
|
61
61
|
raise ArgumentError, "credentials is required" if credentials.nil?
|
62
62
|
|
63
|
-
# TODO: The env logic should live in google-cloud-env
|
64
63
|
universe_domain ||= ENV["GOOGLE_CLOUD_UNIVERSE_DOMAIN"] || "googleapis.com"
|
65
64
|
endpoint ||= endpoint_template.sub ENDPOINT_SUBSTITUTION, universe_domain
|
66
65
|
|
67
|
-
if credentials.respond_to?(:
|
66
|
+
if !(credentials.respond_to?(:disable_universe_domain_check) && credentials.disable_universe_domain_check) &&
|
67
|
+
credentials.respond_to?(:universe_domain) && credentials.universe_domain != universe_domain
|
68
68
|
raise UniverseDomainMismatch,
|
69
69
|
"Universe domain is #{universe_domain} but credentials are in #{credentials.universe_domain}"
|
70
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gapic-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.25.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Google API Authors
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-22 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: faraday
|
@@ -84,14 +83,42 @@ dependencies:
|
|
84
83
|
requirements:
|
85
84
|
- - "~>"
|
86
85
|
- !ruby/object:Gem::Version
|
87
|
-
version: '1.
|
86
|
+
version: '1.12'
|
88
87
|
type: :runtime
|
89
88
|
prerelease: false
|
90
89
|
version_requirements: !ruby/object:Gem::Requirement
|
91
90
|
requirements:
|
92
91
|
- - "~>"
|
93
92
|
- !ruby/object:Gem::Version
|
94
|
-
version: '1.
|
93
|
+
version: '1.12'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: google-cloud-env
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - "~>"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '2.2'
|
101
|
+
type: :runtime
|
102
|
+
prerelease: false
|
103
|
+
version_requirements: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - "~>"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '2.2'
|
108
|
+
- !ruby/object:Gem::Dependency
|
109
|
+
name: google-logging-utils
|
110
|
+
requirement: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - "~>"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0.1'
|
115
|
+
type: :runtime
|
116
|
+
prerelease: false
|
117
|
+
version_requirements: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - "~>"
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0.1'
|
95
122
|
- !ruby/object:Gem::Dependency
|
96
123
|
name: google-protobuf
|
97
124
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,15 +145,14 @@ dependencies:
|
|
118
145
|
requirements:
|
119
146
|
- - "~>"
|
120
147
|
- !ruby/object:Gem::Version
|
121
|
-
version: '1.
|
148
|
+
version: '1.66'
|
122
149
|
type: :runtime
|
123
150
|
prerelease: false
|
124
151
|
version_requirements: !ruby/object:Gem::Requirement
|
125
152
|
requirements:
|
126
153
|
- - "~>"
|
127
154
|
- !ruby/object:Gem::Version
|
128
|
-
version: '1.
|
129
|
-
description:
|
155
|
+
version: '1.66'
|
130
156
|
email:
|
131
157
|
- googleapis-packages@google.com
|
132
158
|
executables: []
|
@@ -146,6 +172,9 @@ files:
|
|
146
172
|
- lib/gapic/call_options/retry_policy.rb
|
147
173
|
- lib/gapic/common.rb
|
148
174
|
- lib/gapic/common/error.rb
|
175
|
+
- lib/gapic/common/error_codes.rb
|
176
|
+
- lib/gapic/common/polling_harness.rb
|
177
|
+
- lib/gapic/common/retry_policy.rb
|
149
178
|
- lib/gapic/common/version.rb
|
150
179
|
- lib/gapic/config.rb
|
151
180
|
- lib/gapic/config/method.rb
|
@@ -159,6 +188,7 @@ files:
|
|
159
188
|
- lib/gapic/grpc/service_stub/rpc_call.rb
|
160
189
|
- lib/gapic/grpc/status_details.rb
|
161
190
|
- lib/gapic/headers.rb
|
191
|
+
- lib/gapic/logging_concerns.rb
|
162
192
|
- lib/gapic/lru_hash.rb
|
163
193
|
- lib/gapic/operation.rb
|
164
194
|
- lib/gapic/operation/retry_policy.rb
|
@@ -177,11 +207,10 @@ files:
|
|
177
207
|
- lib/gapic/rest/transport_operation.rb
|
178
208
|
- lib/gapic/stream_input.rb
|
179
209
|
- lib/gapic/universe_domain_concerns.rb
|
180
|
-
homepage: https://github.com/googleapis/
|
210
|
+
homepage: https://github.com/googleapis/ruby-core-libraries
|
181
211
|
licenses:
|
182
212
|
- Apache-2.0
|
183
213
|
metadata: {}
|
184
|
-
post_install_message:
|
185
214
|
rdoc_options: []
|
186
215
|
require_paths:
|
187
216
|
- lib
|
@@ -196,8 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
225
|
- !ruby/object:Gem::Version
|
197
226
|
version: '0'
|
198
227
|
requirements: []
|
199
|
-
rubygems_version: 3.
|
200
|
-
signing_key:
|
228
|
+
rubygems_version: 3.6.2
|
201
229
|
specification_version: 4
|
202
230
|
summary: Common code for GAPIC-generated API clients
|
203
231
|
test_files: []
|