gitlab-labkit 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7e7afa0f2bf64760a144d433f5433532c1a08f1157f2ca46f180f13fead059b
4
- data.tar.gz: 6647d722dc1ad3835001401ff13be3545649bbbc5847d664678422c3f3bab688
3
+ metadata.gz: a2d4710034737a40d4a0947d4a59eec42c82ebe95d8e1e77b0f8b6a20afd48d0
4
+ data.tar.gz: 6870c998273ae0bf10572172304f50335f1597e33970454524b42a7557bb551e
5
5
  SHA512:
6
- metadata.gz: 1c2a10af3bb8968d523f62a40ef1597af6c26173b7b433c6ed7a1f2f613f76c02008653471dba139a82de7582e564d703da3b28b4bdc10f081c443dd0a41a07d
7
- data.tar.gz: 5d38c2ef80073df95a0b3898e324ef7ac7b3e962bb72470833f4b1f0c1d28e64580c164fdcfca5d84f2f2e1579f3bd3b6211996205254be35631f5143787e07f
6
+ metadata.gz: accd3967431bc14bef4fb1ef747b10ed056da881cdde861fa4d361e0c91bd5f309ef4fa46ff097a8806e17fee431757b1fac2d858d3f3f239c66abe76adb2a45
7
+ data.tar.gz: f7568c0b0ced1de4d217a66951249900497e8c25babd40c567a54cba0163a4945bc67e1dc41662996a69ab4c77348b54aa1df843d52ebf6ea6d5d72d0499ce51
@@ -1,6 +1,7 @@
1
1
  .test_template: &test_definition
2
2
  stage: test
3
3
  script:
4
+ - gem install bundler
4
5
  - bundle install
5
6
  - bundle exec rake verify build install
6
7
 
data/Rakefile CHANGED
@@ -34,6 +34,12 @@ namespace :rufo do
34
34
  end
35
35
  end
36
36
 
37
+ desc "Generate test protobuf stubs"
38
+ task :gen_test_proto do
39
+ system "grpc_tools_ruby_protoc --ruby_out=. --grpc_out=. spec/support/grpc_service/test.proto"
40
+ Rufo::Command.run(["spec/support/grpc_service/test_pb.rb", "spec/support/grpc_service/test_services_pb.rb"])
41
+ end
42
+
37
43
  task :fix => %w[rufo:run rubocop:auto_correct]
38
44
 
39
45
  task :verify => %w[spec rufo:check rubocop]
@@ -17,12 +17,15 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ["lib"]
18
18
  spec.required_ruby_version = ">= 2.4.0"
19
19
 
20
+ # Please maintain alphabetical order for dependencies
20
21
  spec.add_runtime_dependency "actionpack", "~> 5"
21
22
  spec.add_runtime_dependency "activesupport", "~> 5"
22
- spec.add_runtime_dependency "grpc", "~> 1.15"
23
+ spec.add_runtime_dependency "grpc", "~> 1.19.0" # Be sure to update the "grpc-tools" dev_depenency too
23
24
  spec.add_runtime_dependency "jaeger-client", "~> 0.10"
24
25
  spec.add_runtime_dependency "opentracing", "~> 0.4"
25
26
 
27
+ # Please maintain alphabetical order for dev dependencies
28
+ spec.add_development_dependency "grpc-tools", "~> 1.19.0"
26
29
  spec.add_development_dependency "rack", "~> 2.0"
27
30
  spec.add_development_dependency "rake", "~> 12.3"
28
31
  spec.add_development_dependency "rspec", "~> 3.6.0"
@@ -6,7 +6,8 @@ module Labkit
6
6
  # Tracing provides distributed tracing functionality
7
7
  module Tracing
8
8
  autoload :Factory, "labkit/tracing/factory"
9
- autoload :GRPCInterceptor, "labkit/tracing/grpc_interceptor"
9
+ autoload :GRPC, "labkit/tracing/grpc"
10
+ autoload :GRPCInterceptor, "labkit/tracing/grpc_interceptor" # Deprecated
10
11
  autoload :JaegerFactory, "labkit/tracing/jaeger_factory"
11
12
  autoload :RackMiddleware, "labkit/tracing/rack_middleware"
12
13
  autoload :Rails, "labkit/tracing/rails"
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Tracing
5
+ # The GRPC module contains functionality for instrumenting GRPC calls
6
+ module GRPC
7
+ autoload :ClientInterceptor, "labkit/tracing/grpc/client_interceptor"
8
+ autoload :ServerInterceptor, "labkit/tracing/grpc/server_interceptor"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Disable the UnusedMethodArgument linter, since we need to declare the kwargs
4
+ # in the methods, but we don't actually use them.
5
+ # rubocop:disable Lint/UnusedMethodArgument
6
+ require "opentracing"
7
+ require "grpc"
8
+
9
+ module Labkit
10
+ module Tracing
11
+ module GRPC
12
+ # GRPCClientInterceptor is a client-side GRPC interceptor
13
+ # for instrumenting GRPC calls with distributed tracing
14
+ class ClientInterceptor < ::GRPC::ClientInterceptor
15
+ include Singleton
16
+
17
+ def request_response(request:, call:, method:, metadata:)
18
+ wrap_with_tracing(method, "unary", metadata) { yield }
19
+ end
20
+
21
+ def client_streamer(requests:, call:, method:, metadata:)
22
+ wrap_with_tracing(method, "client_stream", metadata) { yield }
23
+ end
24
+
25
+ def server_streamer(request:, call:, method:, metadata:)
26
+ wrap_with_tracing(method, "server_stream", metadata) { yield }
27
+ end
28
+
29
+ def bidi_streamer(requests:, call:, method:, metadata:)
30
+ wrap_with_tracing(method, "bidi_stream", metadata) { yield }
31
+ end
32
+
33
+ private
34
+
35
+ def wrap_with_tracing(method, grpc_type, metadata)
36
+ tags = { "component" => "grpc", "span.kind" => "client", "grpc.method" => method, "grpc.type" => grpc_type }
37
+
38
+ TracingUtils.with_tracing(operation_name: "grpc:#{method}", tags: tags) do |span|
39
+ OpenTracing.inject(span.context, OpenTracing::FORMAT_TEXT_MAP, metadata)
40
+
41
+ yield
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ # rubocop:enable Lint/UnusedMethodArgument
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Disable the UnusedMethodArgument linter, since we need to declare the kwargs
4
+ # in the methods, but we don't actually use them.
5
+ # rubocop:disable Lint/UnusedMethodArgument
6
+
7
+ require "opentracing"
8
+ require "grpc"
9
+
10
+ module Labkit
11
+ module Tracing
12
+ module GRPC
13
+ # GRPCServerInterceptor is a server-side GRPC interceptor
14
+ # for instrumenting GRPC calls with distributed tracing
15
+ # in a GRPC Ruby server
16
+ class ServerInterceptor < ::GRPC::ServerInterceptor
17
+ def request_response(request: nil, call: nil, method: nil)
18
+ wrap_with_tracing(call, method, "unary") do
19
+ yield
20
+ end
21
+ end
22
+
23
+ def client_streamer(call: nil, method: nil)
24
+ wrap_with_tracing(call, method, "client_stream") do
25
+ yield
26
+ end
27
+ end
28
+
29
+ def server_streamer(request: nil, call: nil, method: nil)
30
+ wrap_with_tracing(call, method, "server_stream") do
31
+ yield
32
+ end
33
+ end
34
+
35
+ def bidi_streamer(requests: nil, call: nil, method: nil)
36
+ wrap_with_tracing(call, method, "bidi_stream") do
37
+ yield
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def route_from_method(method)
44
+ service_class = method.owner
45
+ rpc_method = method.name.to_s.split("_").map(&:capitalize).join("")
46
+
47
+ "/#{service_class.service_name}/#{rpc_method}"
48
+ end
49
+
50
+ def wrap_with_tracing(call, method, grpc_type)
51
+ context = TracingUtils.tracer.extract(OpenTracing::FORMAT_TEXT_MAP, call.metadata)
52
+ method_name = route_from_method(method)
53
+ tags = {
54
+ "component" => "grpc",
55
+ "span.kind" => "server",
56
+ "grpc.method" => method_name,
57
+ "grpc.type" => grpc_type,
58
+ }
59
+
60
+ TracingUtils.with_tracing(operation_name: "grpc:#{method_name}", child_of: context, tags: tags) do |_span|
61
+ yield
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ # rubocop:enable Lint/UnusedMethodArgument
@@ -1,45 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Lint/UnusedMethodArgument
4
- require "opentracing"
5
- require "grpc"
6
-
7
3
  module Labkit
8
4
  module Tracing
9
- # GRPCInterceptor is a client-side GRPC interceptor
10
- # for instrumenting GRPC calls with distributed tracing
11
- class GRPCInterceptor < GRPC::ClientInterceptor
12
- include Singleton
13
-
14
- def request_response(request:, call:, method:, metadata:)
15
- wrap_with_tracing(method, "unary", metadata) { yield }
16
- end
17
-
18
- def client_streamer(requests:, call:, method:, metadata:)
19
- wrap_with_tracing(method, "client_stream", metadata) { yield }
20
- end
21
-
22
- def server_streamer(request:, call:, method:, metadata:)
23
- wrap_with_tracing(method, "server_stream", metadata) { yield }
24
- end
25
-
26
- def bidi_streamer(requests:, call:, method:, metadata:)
27
- wrap_with_tracing(method, "bidi_stream", metadata) { yield }
28
- end
29
-
30
- private
31
-
32
- def wrap_with_tracing(method, grpc_type, metadata)
33
- tags = { "component" => "grpc", "span.kind" => "client", "grpc.method" => method, "grpc.type" => grpc_type }
34
-
35
- TracingUtils.with_tracing(operation_name: "grpc:#{method}", tags: tags) do |span|
36
- OpenTracing.inject(span.context, OpenTracing::FORMAT_TEXT_MAP, metadata)
37
-
38
- yield
39
- end
40
- end
41
- end
5
+ # GRPCInterceptor is the deprecated name for GRPCClientInterceptor
6
+ GRPCInterceptor = GRPC::ClientInterceptor
42
7
  end
43
8
  end
44
-
45
- # rubocop:enable Lint/UnusedMethodArgument
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-labkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Newdigate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-30 00:00:00.000000000 Z
11
+ date: 2019-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.15'
47
+ version: 1.19.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.15'
54
+ version: 1.19.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: jaeger-client
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: grpc-tools
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.19.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.19.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rack
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -203,6 +217,9 @@ files:
203
217
  - lib/labkit/logging/sanitizer.rb
204
218
  - lib/labkit/tracing.rb
205
219
  - lib/labkit/tracing/factory.rb
220
+ - lib/labkit/tracing/grpc.rb
221
+ - lib/labkit/tracing/grpc/client_interceptor.rb
222
+ - lib/labkit/tracing/grpc/server_interceptor.rb
206
223
  - lib/labkit/tracing/grpc_interceptor.rb
207
224
  - lib/labkit/tracing/jaeger_factory.rb
208
225
  - lib/labkit/tracing/rack_middleware.rb