gitlab-labkit 0.12.0 → 0.13.2
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/.gitlab-ci.yml +9 -0
- data/gitlab-labkit.gemspec +1 -1
- data/lib/labkit/context.rb +1 -1
- data/lib/labkit/correlation/grpc/grpc_common.rb +10 -0
- data/lib/labkit/logging.rb +1 -0
- data/lib/labkit/logging/grpc.rb +9 -0
- data/lib/labkit/logging/grpc/server_interceptor.rb +85 -0
- data/lib/labkit/tracing/grpc/server_interceptor.rb +3 -8
- data/lib/labkit/tracing/jaeger_factory.rb +3 -0
- data/lib/labkit/tracing/redis/redis_interceptor_helper.rb +2 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 458dd268746446a442c85e56a58ebc2005a169822856cf041e30444c649cd02a
|
4
|
+
data.tar.gz: 73613e1ad1aacf1f67bd9875622e97475600f65a2a5624b0cf39c79ba434b300
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 111b312fac281429728c2e33c2e57548c643b7ead4079c86ae6ab766c670b23417e336610acb4a7b1fe6d9e297f6d2080192029e04a229b8956f1a9293cb0ce9
|
7
|
+
data.tar.gz: 17ea39978f5cd418ffe33f6fe2baf931fcd76cf3bfe7c47cfca9a0acdedf97cf2078ff64a18a10c0735f9bc87e3ad7a76369191a3394dfcb8a74a6bebe16406d
|
data/.gitlab-ci.yml
CHANGED
@@ -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:
|
data/gitlab-labkit.gemspec
CHANGED
@@ -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", "~>
|
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
|
|
data/lib/labkit/context.rb
CHANGED
@@ -22,7 +22,7 @@ module Labkit
|
|
22
22
|
CORRELATION_ID_KEY = "correlation_id"
|
23
23
|
RAW_KEYS = [CORRELATION_ID_KEY].freeze
|
24
24
|
KNOWN_KEYS = %w[user project root_namespace subscription_plan caller_id
|
25
|
-
related_class].freeze
|
25
|
+
related_class feature_category].freeze
|
26
26
|
|
27
27
|
class << self
|
28
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
|
data/lib/labkit/logging.rb
CHANGED
@@ -0,0 +1,85 @@
|
|
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.start_time': start.utc.rfc3339,
|
71
|
+
'grpc.time_ms': ((Time.now - start) * 1000.0).truncate(3),
|
72
|
+
'grpc.code': CODE_STRINGS.fetch(code, code.to_s),
|
73
|
+
'grpc.method': method_name,
|
74
|
+
'grpc.service': service_name,
|
75
|
+
pid: Process.pid,
|
76
|
+
correlation_id: Labkit::Correlation::CorrelationId.current_id.to_s,
|
77
|
+
time: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ"),
|
78
|
+
)
|
79
|
+
|
80
|
+
@log_file.puts(JSON.dump(message))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
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 =
|
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.
|
4
|
+
version: 0.13.2
|
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-
|
11
|
+
date: 2020-10-28 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: '
|
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: '
|
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
|