gitlab-labkit 0.13.0 → 0.13.5

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: 54ad7f3ed011ed85b6f0c090f05cd47a4bf7c738fabd2a165bad85b6e4d288c0
4
- data.tar.gz: c833a07fa745fe8286b9c000879de8b0f338c0d24b722e71dc5044c60dcc3b79
3
+ metadata.gz: 386875226d2cd983130f209da6204b633bc564dc7cdf749e4fd51aeb27ea44b7
4
+ data.tar.gz: b07771c72a4dc8385bba052ac9524dde00cce55023ad9c327db040535faeed31
5
5
  SHA512:
6
- metadata.gz: 5c724e7322119314f35831c726900220842e2f473a48d81241a94cc2eb4f34da39bb38c843ba72b724a1b5d0dff5e1b115cec704468d49797d4c681c309cf7ba
7
- data.tar.gz: 91e870d9af690c2b5f6ce7659954616880ee3313f710b49c89505cbe915c4606ef3d1032d905cbfd1be4e547d98c846baa6fed052836833e71dc7a59444c0727
6
+ metadata.gz: 73dcbe4d30d4706da4299dce292b7cd7271be8c10ab555fa4bbd46c53f3cdbb2d47e1c92743f4f914a95b78d3035d43e38003344f7afc399b5507dab84690bb1
7
+ data.tar.gz: 571c2df46e971b9696c5e23b5bdba9ab6df56d8253e998fa9a8797b2ebfb4d0e1b2371ac1626fd8e02d11641b17fb5270e23a7c927e28fddf03b17f4b3b21e7a
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  Gemfile.lock
2
2
  *.gem
3
3
  node_modules
4
+ .bundle
@@ -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:
@@ -5,6 +14,10 @@
5
14
  - bundle install
6
15
  - bundle exec rake verify build install
7
16
 
17
+ test:2.7:
18
+ image: ruby:2.7
19
+ <<: *test_definition
20
+
8
21
  test:2.6:
9
22
  image: ruby:2.6
10
23
  <<: *test_definition
@@ -13,10 +26,6 @@ test:2.5:
13
26
  image: ruby:2.5
14
27
  <<: *test_definition
15
28
 
16
- test:2.4:
17
- image: ruby:2.4
18
- <<: *test_definition
19
-
20
29
  deploy:
21
30
  stage: deploy
22
31
  script:
@@ -1 +1 @@
1
- 2.6.3
1
+ 2.7.2
@@ -22,9 +22,10 @@ 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
+ spec.add_runtime_dependency "gitlab-pg_query", "~> 1.3"
28
29
 
29
30
  # Please maintain alphabetical order for dev dependencies
30
31
  spec.add_development_dependency "grpc-tools", "~> 1.19"
@@ -21,8 +21,9 @@ module Labkit
21
21
  LOG_KEY = "meta"
22
22
  CORRELATION_ID_KEY = "correlation_id"
23
23
  RAW_KEYS = [CORRELATION_ID_KEY].freeze
24
+ HEADER_PREFIX = "X-Gitlab-"
24
25
  KNOWN_KEYS = %w[user project root_namespace subscription_plan caller_id
25
- related_class feature_category].freeze
26
+ remote_ip related_class feature_category].freeze
26
27
 
27
28
  class << self
28
29
  def with_context(attributes = {})
@@ -67,6 +68,10 @@ module Labkit
67
68
  @known_log_keys ||= (KNOWN_KEYS.map(&method(:log_key)) + RAW_KEYS).freeze
68
69
  end
69
70
 
71
+ def header_name(name)
72
+ HEADER_PREFIX + log_key(name).titlecase(keep_id_suffix: true).gsub(/\W/, "-")
73
+ end
74
+
70
75
  private
71
76
 
72
77
  def contexts
@@ -95,6 +100,12 @@ module Labkit
95
100
  data[CORRELATION_ID_KEY]
96
101
  end
97
102
 
103
+ def to_headers
104
+ to_h.except(CORRELATION_ID_KEY).transform_keys do |key|
105
+ self.class.header_name(key)
106
+ end
107
+ end
108
+
98
109
  protected
99
110
 
100
111
  def assign_attributes(attributes)
@@ -67,6 +67,7 @@ module Labkit
67
67
  ensure
68
68
  service_name, method_name = rpc_split(method)
69
69
  message = @default_tags.merge(
70
+ 'grpc.start_time': start.utc.rfc3339,
70
71
  'grpc.time_ms': ((Time.now - start) * 1000.0).truncate(3),
71
72
  'grpc.code': CODE_STRINGS.fetch(code, code.to_s),
72
73
  'grpc.method': method_name,
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "pg_query"
4
+
3
5
  module Labkit
4
6
  module Logging
5
7
  # Sanitizer provides log message sanitization, removing
@@ -22,6 +24,12 @@ module Labkit
22
24
  content
23
25
  end
24
26
 
27
+ def self.sanitize_sql(sql)
28
+ PgQuery.normalize(sql)
29
+ rescue PgQuery::ParseError
30
+ ""
31
+ end
32
+
25
33
  # Ensures that URLS are sanitized to hide credentials
26
34
  def self.mask_url(url)
27
35
  url = url.to_s.strip
@@ -28,6 +28,12 @@ module Labkit
28
28
  ENV["GITLAB_TRACING_URL"]
29
29
  end
30
30
 
31
+ # Check if the current request is being traced.
32
+ def self.sampled?
33
+ context = OpenTracing.active_span&.context
34
+ context && context.respond_to?(:sampled?) && context.sampled?
35
+ end
36
+
31
37
  def self.stacktrace_operations
32
38
  @stacktrace_operations ||= Set.new(ENV["GITLAB_TRACING_INCLUDE_STACKTRACE"].to_s.split(",").map(&:strip))
33
39
  end
@@ -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]),
@@ -34,7 +37,7 @@ module Labkit
34
37
  warn message
35
38
  end
36
39
 
37
- Jaeger::Client.build(kwargs)
40
+ Jaeger::Client.build(**kwargs)
38
41
  end
39
42
 
40
43
  def self.get_sampler(sampler_type, sampler_param)
@@ -14,13 +14,14 @@ module Labkit
14
14
  end
15
15
 
16
16
  def tags(payload)
17
+ sql = Labkit::Logging::Sanitizer.sanitize_sql(payload[:sql]) if Labkit::Tracing.sampled? && payload[:sql]
17
18
  {
18
19
  "component" => COMPONENT_TAG,
19
20
  "span.kind" => "client",
20
21
  "db.type" => "sql",
21
22
  "db.connection_id" => payload[:connection_id],
22
23
  "db.cached" => payload[:cached] || false,
23
- "db.statement" => payload[:sql],
24
+ "db.statement" => sql,
24
25
  }
25
26
  end
26
27
  end
@@ -49,7 +49,7 @@ module Labkit
49
49
  # Add exception logging to a span
50
50
  def self.log_exception_on_span(span, exception)
51
51
  span.set_tag("error", true)
52
- span.log_kv(kv_tags_for_exception(exception))
52
+ span.log_kv(**kv_tags_for_exception(exception))
53
53
  end
54
54
 
55
55
  # Generate key-value tags for an exception
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.13.0
4
+ version: 0.13.5
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-10-20 00:00:00.000000000 Z
11
+ date: 2020-12-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
@@ -112,6 +112,20 @@ dependencies:
112
112
  - - "<"
113
113
  - !ruby/object:Gem::Version
114
114
  version: 5.0.0
115
+ - !ruby/object:Gem::Dependency
116
+ name: gitlab-pg_query
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '1.3'
122
+ type: :runtime
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: '1.3'
115
129
  - !ruby/object:Gem::Dependency
116
130
  name: grpc-tools
117
131
  requirement: !ruby/object:Gem::Requirement