gitlab-labkit 0.11.0 → 0.13.1

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: '079f4d5036a9fec36b5b6407aae14904afe2cf8e14805bd66e2bc4e7232fbf6a'
4
- data.tar.gz: ba3f76216a9e26fd2208911ae51f147e94ffa3bb786922eec529f4188c35b91b
3
+ metadata.gz: a70f566d4ed676fa90486f0117f74d52a839d2720103cf2c909ecfdb1e762b6e
4
+ data.tar.gz: 21614ae6e31149551dd15337957ff079c7c40536710d8911e697087e7a15bde3
5
5
  SHA512:
6
- metadata.gz: 512596bceb4a8549af748a72e49286e3c1224ab1ae61d30f127685b70653fe30579c37d1091190cab19e244e016f5e2947b5892f51ba55b31651ccbc9e028706
7
- data.tar.gz: de29c45094bafd62607471a8b0142ae3dffced97032d2a6b25c748a2a47347a5c815e5735d60985a98f6c43f3107ba901094ba814d1ff903d38c4f8ac6452b9b
6
+ metadata.gz: 94946b83b7e1f15fbcbd641b44332a78a9c578a26d2261f22ceb916266bb5f5ddf14652ec7485cc774f03ab051c4e78de1380501a6e35517121e526c170caca3
7
+ data.tar.gz: 9feec573a60e49eea6e86bc9ed85b615a0ca60bca10228a49fdea2afbb9296b8bfbccac646dc3cecb4e1bd71e8bd8f53efe1c77305c2cf0098b5dff0ac808ae6
@@ -1,3 +1,12 @@
1
+ workflow:
2
+ rules:
3
+ # For merge requests, create a pipeline.
4
+ - if: '$CI_MERGE_REQUEST_IID'
5
+ # For `master` branch, create a pipeline (this includes on schedules, pushes, merges, etc.).
6
+ - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
7
+ # For tags, create a pipeline.
8
+ - if: '$CI_COMMIT_TAG'
9
+
1
10
  .test_template: &test_definition
2
11
  stage: test
3
12
  script:
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_runtime_dependency "actionpack", ">= 5.0.0", "< 6.1.0"
23
23
  spec.add_runtime_dependency "activesupport", ">= 5.0.0", "< 6.1.0"
24
24
  spec.add_runtime_dependency "grpc", "~> 1.19" # Be sure to update the "grpc-tools" dev_depenency too
25
- spec.add_runtime_dependency "jaeger-client", "~> 0.10"
25
+ spec.add_runtime_dependency "jaeger-client", "~> 1.1"
26
26
  spec.add_runtime_dependency "opentracing", "~> 0.4"
27
27
  spec.add_runtime_dependency "redis", ">3.0.0", "<5.0.0"
28
28
 
@@ -21,7 +21,8 @@ module Labkit
21
21
  LOG_KEY = "meta"
22
22
  CORRELATION_ID_KEY = "correlation_id"
23
23
  RAW_KEYS = [CORRELATION_ID_KEY].freeze
24
- KNOWN_KEYS = %w[user project root_namespace subscription_plan caller_id].freeze
24
+ KNOWN_KEYS = %w[user project root_namespace subscription_plan caller_id
25
+ related_class feature_category].freeze
25
26
 
26
27
  class << self
27
28
  def with_context(attributes = {})
@@ -7,6 +7,16 @@ module Labkit
7
7
  # It is not part of the public API
8
8
  module GRPCCommon
9
9
  CORRELATION_METADATA_KEY = "x-gitlab-correlation-id"
10
+
11
+ def rpc_split(method)
12
+ owner = method.owner
13
+ method_name, = owner.rpc_descs.find do |k, _|
14
+ ::GRPC::GenericService.underscore(k.to_s) == method.name.to_s
15
+ end
16
+ method_name ||= "(unknown)"
17
+
18
+ [owner.service_name, method_name]
19
+ end
10
20
  end
11
21
  end
12
22
  end
@@ -4,6 +4,7 @@ module Labkit
4
4
  # Logging provides functionality for logging, such as
5
5
  # sanitization
6
6
  module Logging
7
+ autoload :GRPC, "labkit/logging/grpc"
7
8
  autoload :Sanitizer, "labkit/logging/sanitizer"
8
9
  end
9
10
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Logging
5
+ module GRPC
6
+ autoload :ServerInterceptor, "labkit/logging/grpc/server_interceptor"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "grpc"
4
+ require "json"
5
+
6
+ module Labkit
7
+ module Logging
8
+ module GRPC
9
+ class ServerInterceptor < ::GRPC::ServerInterceptor
10
+ include Labkit::Correlation::GRPC::GRPCCommon
11
+
12
+ CODE_STRINGS = {
13
+ ::GRPC::Core::StatusCodes::OK => "OK",
14
+ ::GRPC::Core::StatusCodes::CANCELLED => "Canceled",
15
+ ::GRPC::Core::StatusCodes::UNKNOWN => "Unknown",
16
+ ::GRPC::Core::StatusCodes::INVALID_ARGUMENT => "InvalidArgument",
17
+ ::GRPC::Core::StatusCodes::DEADLINE_EXCEEDED => "DeadlineExceeded",
18
+ ::GRPC::Core::StatusCodes::NOT_FOUND => "NotFound",
19
+ ::GRPC::Core::StatusCodes::ALREADY_EXISTS => "AlreadyExists",
20
+ ::GRPC::Core::StatusCodes::PERMISSION_DENIED => "PermissionDenied",
21
+ ::GRPC::Core::StatusCodes::RESOURCE_EXHAUSTED => "ResourceExhausted",
22
+ ::GRPC::Core::StatusCodes::FAILED_PRECONDITION => "FailedPrecondition",
23
+ ::GRPC::Core::StatusCodes::ABORTED => "Aborted",
24
+ ::GRPC::Core::StatusCodes::OUT_OF_RANGE => "OutOfRange",
25
+ ::GRPC::Core::StatusCodes::UNIMPLEMENTED => "Unimplemented",
26
+ ::GRPC::Core::StatusCodes::INTERNAL => "Internal",
27
+ ::GRPC::Core::StatusCodes::UNAVAILABLE => "Unavailable",
28
+ ::GRPC::Core::StatusCodes::DATA_LOSS => "DataLoss",
29
+ ::GRPC::Core::StatusCodes::UNAUTHENTICATED => "Unauthenticated",
30
+ }.freeze
31
+
32
+ def initialize(log_file, default_tags)
33
+ @log_file = log_file
34
+ @log_file.sync = true
35
+ @default_tags = default_tags
36
+
37
+ super()
38
+ end
39
+
40
+ def request_response(request: nil, call: nil, method: nil)
41
+ log_request(method, call) { yield }
42
+ end
43
+
44
+ def server_streamer(request: nil, call: nil, method: nil)
45
+ log_request(method, call) { yield }
46
+ end
47
+
48
+ def client_streamer(call: nil, method: nil)
49
+ log_request(method, call) { yield }
50
+ end
51
+
52
+ def bidi_streamer(requests: nil, call: nil, method: nil)
53
+ log_request(method, call) { yield }
54
+ end
55
+
56
+ private
57
+
58
+ def log_request(method, call)
59
+ start = Time.now
60
+ code = ::GRPC::Core::StatusCodes::OK
61
+
62
+ yield
63
+ rescue StandardError => ex
64
+ code = ex.is_a?(::GRPC::BadStatus) ? ex.code : ::GRPC::Core::StatusCodes::UNKNOWN
65
+
66
+ raise
67
+ ensure
68
+ service_name, method_name = rpc_split(method)
69
+ message = @default_tags.merge(
70
+ 'grpc.time_ms': ((Time.now - start) * 1000.0).truncate(3),
71
+ 'grpc.code': CODE_STRINGS.fetch(code, code.to_s),
72
+ 'grpc.method': method_name,
73
+ 'grpc.service': service_name,
74
+ pid: Process.pid,
75
+ correlation_id: Labkit::Correlation::CorrelationId.current_id.to_s,
76
+ time: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ"),
77
+ )
78
+
79
+ @log_file.puts(JSON.dump(message))
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -14,6 +14,8 @@ module Labkit
14
14
  # for instrumenting GRPC calls with distributed tracing
15
15
  # in a GRPC Ruby server
16
16
  class ServerInterceptor < ::GRPC::ServerInterceptor
17
+ include Labkit::Correlation::GRPC::GRPCCommon
18
+
17
19
  def request_response(request: nil, call: nil, method: nil)
18
20
  wrap_with_tracing(call, method, "unary") do
19
21
  yield
@@ -40,16 +42,9 @@ module Labkit
40
42
 
41
43
  private
42
44
 
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
45
  def wrap_with_tracing(call, method, grpc_type)
51
46
  context = TracingUtils.tracer.extract(OpenTracing::FORMAT_TEXT_MAP, call.metadata)
52
- method_name = route_from_method(method)
47
+ method_name = "/#{rpc_split(method).join("/")}"
53
48
  tags = {
54
49
  "component" => "grpc",
55
50
  "span.kind" => "server",
@@ -19,6 +19,9 @@ module Labkit
19
19
  FLUSH_INTERVAL = 5
20
20
 
21
21
  def self.create_tracer(service_name, options)
22
+ # The service_name parameter from GITLAB_TRACING takes precedence over the application one
23
+ service_name = options[:service_name] if options[:service_name]
24
+
22
25
  kwargs = {
23
26
  service_name: service_name,
24
27
  sampler: get_sampler(options[:sampler], options[:sampler_param]),
@@ -8,7 +8,7 @@ module Labkit
8
8
  # RedisInterceptorHelper is a helper for the RedisInterceptor. This is not a public API
9
9
  class RedisInterceptorHelper
10
10
  # For optimization, compile this once
11
- MASK_REDIS_RE = /^([\w-]+(?:\W+[\w-]+(?:\W+[\w-]+)?)?)(.?)/.freeze
11
+ MASK_REDIS_RE = /^([\w{}-]+(?:\W+[\w{}-]+(?:\W+[\w{}-]+)?)?)(.?)/.freeze
12
12
 
13
13
  def self.call_with_tracing(command, client)
14
14
  Labkit::Tracing::TracingUtils.with_tracing(operation_name: "redis.call", tags: tags_from_command(command, client)) do |_span|
@@ -99,6 +99,7 @@ module Labkit
99
99
  return "" if argument.empty?
100
100
 
101
101
  matches = argument.match(MASK_REDIS_RE)
102
+
102
103
  matches[2].empty? ? matches[0] : matches[0] + "*****"
103
104
  end
104
105
  private_class_method :mask_redis_arg
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.11.0
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Newdigate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-11 00:00:00.000000000 Z
11
+ date: 2020-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -70,14 +70,14 @@ dependencies:
70
70
  requirements:
71
71
  - - "~>"
72
72
  - !ruby/object:Gem::Version
73
- version: '0.10'
73
+ version: '1.1'
74
74
  type: :runtime
75
75
  prerelease: false
76
76
  version_requirements: !ruby/object:Gem::Requirement
77
77
  requirements:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
- version: '0.10'
80
+ version: '1.1'
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: opentracing
83
83
  requirement: !ruby/object:Gem::Requirement
@@ -279,6 +279,8 @@ files:
279
279
  - lib/labkit/correlation/grpc/grpc_common.rb
280
280
  - lib/labkit/correlation/grpc/server_interceptor.rb
281
281
  - lib/labkit/logging.rb
282
+ - lib/labkit/logging/grpc.rb
283
+ - lib/labkit/logging/grpc/server_interceptor.rb
282
284
  - lib/labkit/logging/sanitizer.rb
283
285
  - lib/labkit/middleware.rb
284
286
  - lib/labkit/middleware/rack.rb