grpc 1.36.0-x64-mingw32 → 1.37.0.pre1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/grpc_c.32.ruby +0 -0
  3. data/grpc_c.64.ruby +0 -0
  4. data/src/ruby/ext/grpc/extconf.rb +9 -1
  5. data/src/ruby/ext/grpc/rb_channel.c +10 -1
  6. data/src/ruby/ext/grpc/rb_channel_credentials.c +11 -1
  7. data/src/ruby/ext/grpc/rb_channel_credentials.h +4 -0
  8. data/src/ruby/ext/grpc/rb_compression_options.c +1 -1
  9. data/src/ruby/ext/grpc/rb_enable_cpp.cc +1 -1
  10. data/src/ruby/ext/grpc/rb_grpc.c +4 -0
  11. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  12. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -1
  13. data/src/ruby/ext/grpc/rb_server.c +13 -1
  14. data/src/ruby/ext/grpc/rb_server_credentials.c +19 -3
  15. data/src/ruby/ext/grpc/rb_server_credentials.h +4 -0
  16. data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +215 -0
  17. data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +35 -0
  18. data/src/ruby/ext/grpc/rb_xds_server_credentials.c +169 -0
  19. data/src/ruby/ext/grpc/rb_xds_server_credentials.h +35 -0
  20. data/src/ruby/lib/grpc/2.4/grpc_c.so +0 -0
  21. data/src/ruby/lib/grpc/2.5/grpc_c.so +0 -0
  22. data/src/ruby/lib/grpc/2.6/grpc_c.so +0 -0
  23. data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
  24. data/src/ruby/lib/grpc/3.0/grpc_c.so +0 -0
  25. data/src/ruby/lib/grpc/generic/client_stub.rb +4 -2
  26. data/src/ruby/lib/grpc/version.rb +1 -1
  27. data/src/ruby/pb/test/xds_client.rb +42 -26
  28. data/src/ruby/spec/call_spec.rb +1 -1
  29. data/src/ruby/spec/channel_credentials_spec.rb +32 -0
  30. data/src/ruby/spec/channel_spec.rb +17 -6
  31. data/src/ruby/spec/client_auth_spec.rb +27 -1
  32. data/src/ruby/spec/errors_spec.rb +1 -1
  33. data/src/ruby/spec/generic/active_call_spec.rb +2 -2
  34. data/src/ruby/spec/generic/client_stub_spec.rb +4 -4
  35. data/src/ruby/spec/generic/rpc_server_spec.rb +1 -1
  36. data/src/ruby/spec/server_credentials_spec.rb +25 -0
  37. data/src/ruby/spec/server_spec.rb +22 -0
  38. metadata +36 -32
@@ -0,0 +1,35 @@
1
+ /*
2
+ *
3
+ * Copyright 2021 gRPC authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+
19
+ #ifndef GRPC_RB_XDS_CHANNEL_CREDENTIALS_H_
20
+ #define GRPC_RB_XDS_CHANNEL_CREDENTIALS_H_
21
+
22
+ #include <grpc/grpc_security.h>
23
+ #include <ruby/ruby.h>
24
+ #include <stdbool.h>
25
+
26
+ /* Initializes the ruby ChannelCredentials class. */
27
+ void Init_grpc_xds_channel_credentials();
28
+
29
+ /* Gets the wrapped credentials from the ruby wrapper */
30
+ grpc_channel_credentials* grpc_rb_get_wrapped_xds_channel_credentials(VALUE v);
31
+
32
+ /* Check if v is kind of XdsChannelCredentials */
33
+ bool grpc_rb_is_xds_channel_credentials(VALUE v);
34
+
35
+ #endif /* GRPC_RB_XDS_CHANNEL_CREDENTIALS_H_ */
@@ -0,0 +1,169 @@
1
+ /*
2
+ *
3
+ * Copyright 2021 gRPC authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+
19
+ #include "rb_xds_server_credentials.h"
20
+
21
+ #include <grpc/grpc.h>
22
+ #include <grpc/grpc_security.h>
23
+ #include <grpc/support/log.h>
24
+ #include <ruby/ruby.h>
25
+
26
+ #include "rb_grpc.h"
27
+ #include "rb_grpc_imports.generated.h"
28
+ #include "rb_server_credentials.h"
29
+
30
+ /* grpc_rb_cXdsServerCredentials is the ruby class that proxies
31
+ grpc_server_credentials. */
32
+ static VALUE grpc_rb_cXdsServerCredentials = Qnil;
33
+
34
+ /* grpc_rb_xds_server_credentials wraps a grpc_server_credentials. It provides
35
+ a peer ruby object, 'mark' to hold references to objects involved in
36
+ constructing the server credentials. */
37
+ typedef struct grpc_rb_xds_server_credentials {
38
+ /* Holder of ruby objects involved in constructing the server credentials */
39
+ VALUE mark;
40
+ /* The actual server credentials */
41
+ grpc_server_credentials* wrapped;
42
+ } grpc_rb_xds_server_credentials;
43
+
44
+ /* Destroys the server credentials instances. */
45
+ static void grpc_rb_xds_server_credentials_free_internal(void* p) {
46
+ grpc_rb_xds_server_credentials* wrapper = NULL;
47
+ if (p == NULL) {
48
+ return;
49
+ };
50
+ wrapper = (grpc_rb_xds_server_credentials*)p;
51
+
52
+ /* Delete the wrapped object if the mark object is Qnil, which indicates that
53
+ no other object is the actual owner. */
54
+ if (wrapper->wrapped != NULL && wrapper->mark == Qnil) {
55
+ grpc_server_credentials_release(wrapper->wrapped);
56
+ wrapper->wrapped = NULL;
57
+ }
58
+
59
+ xfree(p);
60
+ }
61
+
62
+ /* Destroys the server credentials instances. */
63
+ static void grpc_rb_xds_server_credentials_free(void* p) {
64
+ grpc_rb_xds_server_credentials_free_internal(p);
65
+ grpc_ruby_shutdown();
66
+ }
67
+
68
+ /* Protects the mark object from GC */
69
+ static void grpc_rb_xds_server_credentials_mark(void* p) {
70
+ if (p == NULL) {
71
+ return;
72
+ }
73
+ grpc_rb_xds_server_credentials* wrapper = (grpc_rb_xds_server_credentials*)p;
74
+
75
+ /* If it's not already cleaned up, mark the mark object */
76
+ if (wrapper->mark != Qnil) {
77
+ rb_gc_mark(wrapper->mark);
78
+ }
79
+ }
80
+
81
+ static const rb_data_type_t grpc_rb_xds_server_credentials_data_type = {
82
+ "grpc_xds_server_credentials",
83
+ {grpc_rb_xds_server_credentials_mark, grpc_rb_xds_server_credentials_free,
84
+ GRPC_RB_MEMSIZE_UNAVAILABLE, NULL},
85
+ NULL,
86
+ NULL,
87
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
88
+ RUBY_TYPED_FREE_IMMEDIATELY
89
+ #endif
90
+ };
91
+
92
+ /* Allocates ServerCredential instances.
93
+ Provides safe initial defaults for the instance fields. */
94
+ static VALUE grpc_rb_xds_server_credentials_alloc(VALUE cls) {
95
+ grpc_ruby_init();
96
+ grpc_rb_xds_server_credentials* wrapper =
97
+ ALLOC(grpc_rb_xds_server_credentials);
98
+ wrapper->wrapped = NULL;
99
+ wrapper->mark = Qnil;
100
+ return TypedData_Wrap_Struct(cls, &grpc_rb_xds_server_credentials_data_type,
101
+ wrapper);
102
+ }
103
+
104
+ /* The attribute used on the mark object to preserve the fallback_creds. */
105
+ static ID id_fallback_creds;
106
+
107
+ /*
108
+ call-seq:
109
+ creds = ServerCredentials.new(fallback_creds)
110
+ fallback_creds: (ServerCredentials) fallback credentials to create
111
+ XDS credentials.
112
+ Initializes ServerCredential instances. */
113
+ static VALUE grpc_rb_xds_server_credentials_init(VALUE self,
114
+ VALUE fallback_creds) {
115
+ grpc_rb_xds_server_credentials* wrapper = NULL;
116
+ grpc_server_credentials* creds = NULL;
117
+
118
+ grpc_server_credentials* grpc_fallback_creds =
119
+ grpc_rb_get_wrapped_server_credentials(fallback_creds);
120
+ creds = grpc_xds_server_credentials_create(grpc_fallback_creds);
121
+
122
+ if (creds == NULL) {
123
+ rb_raise(rb_eRuntimeError,
124
+ "the call to grpc_xds_server_credentials_create() failed, could "
125
+ "not create a credentials, see "
126
+ "https://github.com/grpc/grpc/blob/master/TROUBLESHOOTING.md for "
127
+ "debugging tips");
128
+ return Qnil;
129
+ }
130
+ TypedData_Get_Struct(self, grpc_rb_xds_server_credentials,
131
+ &grpc_rb_xds_server_credentials_data_type, wrapper);
132
+ wrapper->wrapped = creds;
133
+
134
+ /* Add the input objects as hidden fields to preserve them. */
135
+ rb_ivar_set(self, id_fallback_creds, fallback_creds);
136
+
137
+ return self;
138
+ }
139
+
140
+ void Init_grpc_xds_server_credentials() {
141
+ grpc_rb_cXdsServerCredentials = rb_define_class_under(
142
+ grpc_rb_mGrpcCore, "XdsServerCredentials", rb_cObject);
143
+
144
+ /* Allocates an object managed by the ruby runtime */
145
+ rb_define_alloc_func(grpc_rb_cXdsServerCredentials,
146
+ grpc_rb_xds_server_credentials_alloc);
147
+
148
+ /* Provides a ruby constructor and support for dup/clone. */
149
+ rb_define_method(grpc_rb_cXdsServerCredentials, "initialize",
150
+ grpc_rb_xds_server_credentials_init, 1);
151
+ rb_define_method(grpc_rb_cXdsServerCredentials, "initialize_copy",
152
+ grpc_rb_cannot_init_copy, 1);
153
+
154
+ id_fallback_creds = rb_intern("__fallback_creds");
155
+ }
156
+
157
+ /* Gets the wrapped grpc_server_credentials from the ruby wrapper */
158
+ grpc_server_credentials* grpc_rb_get_wrapped_xds_server_credentials(VALUE v) {
159
+ grpc_rb_xds_server_credentials* wrapper = NULL;
160
+ Check_TypedStruct(v, &grpc_rb_xds_server_credentials_data_type);
161
+ TypedData_Get_Struct(v, grpc_rb_xds_server_credentials,
162
+ &grpc_rb_xds_server_credentials_data_type, wrapper);
163
+ return wrapper->wrapped;
164
+ }
165
+
166
+ /* Check if v is kind of ServerCredentials */
167
+ bool grpc_rb_is_xds_server_credentials(VALUE v) {
168
+ return rb_typeddata_is_kind_of(v, &grpc_rb_xds_server_credentials_data_type);
169
+ }
@@ -0,0 +1,35 @@
1
+ /*
2
+ *
3
+ * Copyright 2021 gRPC authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+
19
+ #ifndef GRPC_RB_XDS_SERVER_CREDENTIALS_H_
20
+ #define GRPC_RB_XDS_SERVER_CREDENTIALS_H_
21
+
22
+ #include <grpc/grpc_security.h>
23
+ #include <ruby/ruby.h>
24
+ #include <stdbool.h>
25
+
26
+ /* Initializes the ruby XdsServerCredentials class. */
27
+ void Init_grpc_xds_server_credentials();
28
+
29
+ /* Gets the wrapped server_credentials from the ruby wrapper */
30
+ grpc_server_credentials* grpc_rb_get_wrapped_xds_server_credentials(VALUE v);
31
+
32
+ /* Check if v is kind of XdsServerCredentials */
33
+ bool grpc_rb_is_xds_server_credentials(VALUE v);
34
+
35
+ #endif /* GRPC_RB_XDS_SERVER_CREDENTIALS_H_ */
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -41,8 +41,10 @@ module GRPC
41
41
  channel_args['grpc.primary_user_agent'] += ' '
42
42
  end
43
43
  channel_args['grpc.primary_user_agent'] += "grpc-ruby/#{VERSION}"
44
- unless creds.is_a?(Core::ChannelCredentials) || creds.is_a?(Symbol)
45
- fail(TypeError, '!ChannelCredentials or Symbol')
44
+ unless creds.is_a?(Core::ChannelCredentials) ||
45
+ creds.is_a?(Core::XdsChannelCredentials) ||
46
+ creds.is_a?(Symbol)
47
+ fail(TypeError, 'creds is not a ChannelCredentials, XdsChannelCredentials, or Symbol')
46
48
  end
47
49
  Core::Channel.new(host, channel_args, creds)
48
50
  end
@@ -14,5 +14,5 @@
14
14
 
15
15
  # GRPC contains the General RPC module.
16
16
  module GRPC
17
- VERSION = '1.36.0'
17
+ VERSION = '1.37.0.pre1'
18
18
  end
@@ -40,15 +40,11 @@ require_relative '../src/proto/grpc/testing/messages_pb'
40
40
  require_relative '../src/proto/grpc/testing/test_services_pb'
41
41
 
42
42
  class RpcConfig
43
- def init(rpcs_to_send, metadata_to_send)
43
+ attr_reader :rpcs_to_send, :metadata_to_send, :timeout_sec
44
+ def init(rpcs_to_send, metadata_to_send, timeout_sec = 0)
44
45
  @rpcs_to_send = rpcs_to_send
45
46
  @metadata_to_send = metadata_to_send
46
- end
47
- def rpcs_to_send
48
- @rpcs_to_send
49
- end
50
- def metadata_to_send
51
- @metadata_to_send
47
+ @timeout_sec = timeout_sec
52
48
  end
53
49
  end
54
50
 
@@ -71,6 +67,7 @@ $accumulated_stats_mu = Mutex.new
71
67
  $num_rpcs_started_by_method = {}
72
68
  $num_rpcs_succeeded_by_method = {}
73
69
  $num_rpcs_failed_by_method = {}
70
+ $accumulated_method_stats = {}
74
71
 
75
72
  # RubyLogger defines a logger for gRPC based on the standard ruby logger.
76
73
  module RubyLogger
@@ -98,13 +95,26 @@ def create_stub(opts)
98
95
  )
99
96
  end
100
97
 
98
+ class StatsPerMethod
99
+ attr_reader :rpcs_started, :result
100
+ def initialize()
101
+ @rpcs_started = 0
102
+ @result = Hash.new(0)
103
+ end
104
+ def increment_rpcs_started()
105
+ @rpcs_started += 1
106
+ end
107
+ def add_result(status_code)
108
+ @result[status_code] += 1
109
+ end
110
+ end
111
+
101
112
  class ConfigureTarget < Grpc::Testing::XdsUpdateClientConfigureService::Service
102
113
  include Grpc::Testing
103
114
 
104
115
  def configure(req, _call)
105
- rpcs_to_send = req['types'];
106
116
  metadata_to_send = {}
107
- req['metadata'].each do |m|
117
+ req.metadata.each do |m|
108
118
  rpc = m.type
109
119
  if !metadata_to_send.key?(rpc)
110
120
  metadata_to_send[rpc] = {}
@@ -113,13 +123,10 @@ class ConfigureTarget < Grpc::Testing::XdsUpdateClientConfigureService::Service
113
123
  metadata_value = m.value
114
124
  metadata_to_send[rpc][metadata_key] = metadata_value
115
125
  end
116
- GRPC.logger.info("Configuring new rpcs_to_send and metadata_to_send...")
117
- GRPC.logger.info(rpcs_to_send)
118
- GRPC.logger.info(metadata_to_send)
119
126
  new_rpc_config = RpcConfig.new
120
- new_rpc_config.init(rpcs_to_send, metadata_to_send)
127
+ new_rpc_config.init(req['types'], metadata_to_send, req['timeout_sec'])
121
128
  $rpc_config = new_rpc_config
122
- ClientConfigureResponse.new();
129
+ ClientConfigureResponse.new()
123
130
  end
124
131
  end
125
132
 
@@ -159,15 +166,23 @@ class TestTarget < Grpc::Testing::LoadBalancerStatsService::Service
159
166
  rpcs_by_method: rpcs_by_method,
160
167
  rpcs_by_peer: watcher['rpcs_by_peer'],
161
168
  num_failures: watcher['no_remote_peer'] + watcher['rpcs_needed']
162
- );
169
+ )
163
170
  end
164
171
 
165
172
  def get_client_accumulated_stats(req, _call)
166
173
  $accumulated_stats_mu.synchronize do
174
+ all_stats_per_method = $accumulated_method_stats.map { |rpc, stats_per_method|
175
+ [rpc,
176
+ LoadBalancerAccumulatedStatsResponse::MethodStats.new(
177
+ rpcs_started: stats_per_method.rpcs_started,
178
+ result: stats_per_method.result
179
+ )]
180
+ }.to_h
167
181
  LoadBalancerAccumulatedStatsResponse.new(
168
182
  num_rpcs_started_by_method: $num_rpcs_started_by_method,
169
183
  num_rpcs_succeeded_by_method: $num_rpcs_succeeded_by_method,
170
- num_rpcs_failed_by_method: $num_rpcs_failed_by_method
184
+ num_rpcs_failed_by_method: $num_rpcs_failed_by_method,
185
+ stats_per_method: all_stats_per_method,
171
186
  )
172
187
  end
173
188
  end
@@ -176,6 +191,7 @@ end
176
191
  # execute 1 RPC and return remote hostname
177
192
  def execute_rpc(op, fail_on_failed_rpcs, rpc_stats_key)
178
193
  remote_peer = ""
194
+ status_code = 0
179
195
  begin
180
196
  op.execute
181
197
  if op.metadata.key?('hostname')
@@ -185,8 +201,10 @@ def execute_rpc(op, fail_on_failed_rpcs, rpc_stats_key)
185
201
  if fail_on_failed_rpcs
186
202
  raise e
187
203
  end
204
+ status_code = e.code
188
205
  end
189
206
  $accumulated_stats_mu.synchronize do
207
+ $accumulated_method_stats[rpc_stats_key].add_result(status_code)
190
208
  if remote_peer.empty?
191
209
  $num_rpcs_failed_by_method[rpc_stats_key] += 1
192
210
  else
@@ -207,6 +225,7 @@ def execute_rpc_in_thread(op, rpc_stats_key)
207
225
  # Doing this for consistency
208
226
  $accumulated_stats_mu.synchronize do
209
227
  $num_rpcs_succeeded_by_method[rpc_stats_key] += 1
228
+ $accumulated_method_stats[rpc_stats_key].add_result(0)
210
229
  end
211
230
  rescue GRPC::BadStatus => e
212
231
  # Normal execution arrives here,
@@ -214,6 +233,7 @@ def execute_rpc_in_thread(op, rpc_stats_key)
214
233
  # balancing policy"
215
234
  $accumulated_stats_mu.synchronize do
216
235
  $num_rpcs_failed_by_method[rpc_stats_key] += 1
236
+ $accumulated_method_stats[rpc_stats_key].add_result(e.code)
217
237
  end
218
238
  end
219
239
  }
@@ -238,7 +258,8 @@ def run_test_loop(stub, target_seconds_between_rpcs, fail_on_failed_rpcs)
238
258
  target_next_start += target_seconds_between_rpcs
239
259
  sleep(sleep_seconds)
240
260
  end
241
- deadline = GRPC::Core::TimeConsts::from_relative_time(30) # 30 seconds
261
+ deadline_sec = $rpc_config.timeout_sec > 0 ? $rpc_config.timeout_sec : 30
262
+ deadline = GRPC::Core::TimeConsts::from_relative_time(deadline_sec)
242
263
  results = {}
243
264
  $rpc_config.rpcs_to_send.each do |rpc|
244
265
  # rpc is in the form of :UNARY_CALL or :EMPTY_CALL here
@@ -246,10 +267,7 @@ def run_test_loop(stub, target_seconds_between_rpcs, fail_on_failed_rpcs)
246
267
  $rpc_config.metadata_to_send[rpc] : {}
247
268
  $accumulated_stats_mu.synchronize do
248
269
  $num_rpcs_started_by_method[rpc.to_s] += 1
249
- num_started = $num_rpcs_started_by_method[rpc.to_s]
250
- if num_started % 100 == 0
251
- GRPC.logger.info("Started #{num_started} of #{rpc}")
252
- end
270
+ $accumulated_method_stats[rpc.to_s].increment_rpcs_started()
253
271
  end
254
272
  if rpc == :UNARY_CALL
255
273
  op = stub.unary_call(simple_req,
@@ -266,11 +284,8 @@ def run_test_loop(stub, target_seconds_between_rpcs, fail_on_failed_rpcs)
266
284
  end
267
285
  rpc_stats_key = rpc.to_s
268
286
  if metadata.key?('rpc-behavior') and
269
- (metadata['rpc-behavior'] == 'keep-open')
270
- num_open_threads = keep_open_threads.size
271
- if num_open_threads % 50 == 0
272
- GRPC.logger.info("number of keep_open_threads = #{num_open_threads}")
273
- end
287
+ ((metadata['rpc-behavior'] == 'keep-open') or
288
+ (metadata['rpc-behavior'].start_with?('sleep')))
274
289
  keep_open_threads << execute_rpc_in_thread(op, rpc_stats_key)
275
290
  else
276
291
  results[rpc] = execute_rpc(op, fail_on_failed_rpcs, rpc_stats_key)
@@ -364,6 +379,7 @@ def main
364
379
  $num_rpcs_started_by_method[rpc.to_s] = 0
365
380
  $num_rpcs_succeeded_by_method[rpc.to_s] = 0
366
381
  $num_rpcs_failed_by_method[rpc.to_s] = 0
382
+ $accumulated_method_stats[rpc.to_s] = StatsPerMethod.new
367
383
  end
368
384
 
369
385
  # The client just sends rpcs continuously in a regular interval