gitlab-labkit 0.31.1 → 0.33.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: 461e2ae3317fcc57f55038742d5e29f45c1b743cf91eb55655f67d35a82e7cc3
4
- data.tar.gz: f5793900cd880f16037355f77523062155edd7f49d346be76300340a2952f06f
3
+ metadata.gz: dc3aec011f3ce5f31f6a44e57b69bee416bcb42410f6f2a888a3a99dfcb51578
4
+ data.tar.gz: 50516dc7cf61f67ad70d00bcaa7dbec3449b25d9767dc071f84c368d3ad46b47
5
5
  SHA512:
6
- metadata.gz: 7dba4b73d1ecf26e6d39d21cf9e289e35f9e83a9a9639d8f7cf5da5a7e9c1ae8bf427a9afbfc9e15a9d99fe11c239329b6d72c2f548d1caa58b94b59e1d0274a
7
- data.tar.gz: 95a71558f6bedab54d16c63cfb525eaf083dc7dc4f4cfd0bedb2ac14056a9f01df475eca7906e4bfa72f043461f8f67f9dcc7bff9d3b77cbed617e08991018ad
6
+ metadata.gz: 85ec84e6981c85ae75e002e7ab051b6b8e1573c93d79b97ec2940408868a35f0c2166f842e3cb64fd5699e22fcabbbdea91f80ec4bff1e5df5bf1922b69026e3
7
+ data.tar.gz: dd57031373d351bad29c65ab6fa6186d90ab0eb12361fe911d790903875df7aaa81425d7c6c6b8fb794f37ca72fcf586a34301feb7d25c3add45a6899e3e8747
data/.gitlab-ci.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  default:
2
- image: ruby:2.7
2
+ image: ruby:3.1
3
3
 
4
4
  workflow:
5
5
  rules:
@@ -11,19 +11,22 @@ workflow:
11
11
  - if: '$CI_COMMIT_TAG'
12
12
 
13
13
  .test_template: &test_definition
14
+ image: ruby:${RUBY_VERSION}
14
15
  stage: test
15
16
  script:
16
- - gem install bundler
17
+ - gem install bundler --no-document
18
+ - bundle config --local path vendor
17
19
  - bundle install
18
20
  - bundle exec rake verify build install
19
-
20
- test:3.0:
21
- image: ruby:3.0
22
- <<: *test_definition
23
-
24
- test:2.7:
25
- image: ruby:2.7
21
+ cache:
22
+ key: ${CI_JOB_IMAGE}
23
+ paths:
24
+ - vendor/ruby
25
+ ruby:
26
26
  <<: *test_definition
27
+ parallel:
28
+ matrix:
29
+ - RUBY_VERSION: ["2.7", "3.0", "3.1", "3.2"]
27
30
 
28
31
  static-analysis:
29
32
  before_script:
@@ -24,12 +24,12 @@ Gem::Specification.new do |spec|
24
24
  spec.add_runtime_dependency "grpc", ">= 1.37" # Be sure to update the "grpc-tools" dev_dependency too
25
25
  spec.add_runtime_dependency "jaeger-client", "~> 1.1.0"
26
26
  spec.add_runtime_dependency "opentracing", "~> 0.4"
27
- spec.add_runtime_dependency "pg_query", "~> 2.1"
27
+ spec.add_runtime_dependency "pg_query", "~> 4.2.1"
28
28
  spec.add_runtime_dependency "redis", ">3.0.0", "<6.0.0"
29
29
 
30
30
  # Please maintain alphabetical order for dev dependencies
31
31
  spec.add_development_dependency "excon", "~> 0.78.1"
32
- spec.add_development_dependency "faraday", "~> 1.2.0"
32
+ spec.add_development_dependency "faraday", "~> 1.0"
33
33
  spec.add_development_dependency "gitlab-dangerfiles", "~> 2.11.0"
34
34
  spec.add_development_dependency "gitlab-styles", "~> 6.2.0"
35
35
  spec.add_development_dependency "grpc-tools", ">= 1.37"
@@ -39,8 +39,8 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency "rack", "~> 2.0"
40
40
  spec.add_development_dependency "rake", "~> 12.3"
41
41
  spec.add_development_dependency "rest-client", "~> 2.1.0"
42
- spec.add_development_dependency "rspec", "~> 3.10.0"
43
- spec.add_development_dependency "rspec-parameterized", "~> 0.4"
42
+ spec.add_development_dependency "rspec", "~> 3.12.0"
43
+ spec.add_development_dependency "rspec-parameterized", "~> 1.0"
44
44
  spec.add_development_dependency "rufo", "0.9.0"
45
45
  spec.add_development_dependency "sidekiq", ">= 5.2", "< 7"
46
46
  spec.add_development_dependency "webrick", "~> 1.7.0"
@@ -26,7 +26,6 @@ module Labkit
26
26
  LOG_KEY = "meta"
27
27
  CORRELATION_ID_KEY = "correlation_id"
28
28
  RAW_KEYS = [CORRELATION_ID_KEY].freeze
29
- HEADER_PREFIX = "X-Gitlab-"
30
29
 
31
30
  class << self
32
31
  def with_context(attributes = {})
@@ -71,10 +70,6 @@ module Labkit
71
70
  @known_log_keys ||= (KNOWN_KEYS.map(&method(:log_key)) + RAW_KEYS).freeze
72
71
  end
73
72
 
74
- def header_name(name)
75
- HEADER_PREFIX + log_key(name).titlecase(keep_id_suffix: true).gsub(/\W/, "-")
76
- end
77
-
78
73
  private
79
74
 
80
75
  def contexts
@@ -103,12 +98,6 @@ module Labkit
103
98
  data[CORRELATION_ID_KEY]
104
99
  end
105
100
 
106
- def to_headers
107
- to_h.except(CORRELATION_ID_KEY).transform_keys do |key|
108
- self.class.header_name(key)
109
- end
110
- end
111
-
112
101
  def get_attribute(attribute)
113
102
  raw = call_or_value(data[log_key(attribute)])
114
103
 
@@ -23,6 +23,15 @@ module Labkit
23
23
  ENV.fetch("GITLAB_LOG_LEVEL", fallback)
24
24
  end
25
25
 
26
+ def self.exclude_context!
27
+ @exclude_context = true
28
+ self
29
+ end
30
+
31
+ def self.exclude_context?
32
+ !!@exclude_context
33
+ end
34
+
26
35
  def initialize(path, level: JsonLogger.log_level)
27
36
  super
28
37
  end
@@ -31,7 +40,12 @@ module Labkit
31
40
  data = default_attributes
32
41
  data[:severity] = severity
33
42
  data[:time] = timestamp.utc.iso8601(3)
34
- data[Labkit::Correlation::CorrelationId::LOG_KEY] = Labkit::Correlation::CorrelationId.current_id
43
+
44
+ if self.class.exclude_context?
45
+ data[Labkit::Correlation::CorrelationId::LOG_KEY] = Labkit::Correlation::CorrelationId.current_id
46
+ else
47
+ data.merge!(Labkit::Context.current.to_h)
48
+ end
35
49
 
36
50
  case message
37
51
  when String
@@ -1,9 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "action_dispatch"
4
+ require "json"
4
5
 
5
6
  module Labkit
6
7
  module Middleware
8
+ HEADER = "X-Gitlab-Meta"
9
+
7
10
  # This is a rack middleware to be inserted in GitLab-rails
8
11
  # It makes sure that there's always a root context containing the correlation
9
12
  # id.
@@ -15,8 +18,12 @@ module Labkit
15
18
  end
16
19
 
17
20
  def call(env)
18
- Labkit::Context.with_context(Labkit::Context::CORRELATION_ID_KEY => correlation_id(env)) do
19
- @app.call(env)
21
+ Labkit::Context.with_context(Labkit::Context::CORRELATION_ID_KEY => correlation_id(env)) do |context|
22
+ status, headers, response = @app.call(env)
23
+
24
+ headers[HEADER] = context_to_json(context)
25
+
26
+ [status, headers, response]
20
27
  end
21
28
  end
22
29
 
@@ -29,6 +36,14 @@ module Labkit
29
36
  def request(env)
30
37
  ActionDispatch::Request.new(env)
31
38
  end
39
+
40
+ def context_to_json(context)
41
+ context
42
+ .to_h
43
+ .transform_keys { |k| k.delete_prefix("meta.") }
44
+ .merge("version" => "1")
45
+ .to_json
46
+ end
32
47
  end
33
48
  end
34
49
  end
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.31.1
4
+ version: 0.33.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: 2023-03-06 00:00:00.000000000 Z
11
+ date: 2023-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -98,14 +98,14 @@ dependencies:
98
98
  requirements:
99
99
  - - "~>"
100
100
  - !ruby/object:Gem::Version
101
- version: '2.1'
101
+ version: 4.2.1
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - "~>"
107
107
  - !ruby/object:Gem::Version
108
- version: '2.1'
108
+ version: 4.2.1
109
109
  - !ruby/object:Gem::Dependency
110
110
  name: redis
111
111
  requirement: !ruby/object:Gem::Requirement
@@ -146,14 +146,14 @@ dependencies:
146
146
  requirements:
147
147
  - - "~>"
148
148
  - !ruby/object:Gem::Version
149
- version: 1.2.0
149
+ version: '1.0'
150
150
  type: :development
151
151
  prerelease: false
152
152
  version_requirements: !ruby/object:Gem::Requirement
153
153
  requirements:
154
154
  - - "~>"
155
155
  - !ruby/object:Gem::Version
156
- version: 1.2.0
156
+ version: '1.0'
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: gitlab-dangerfiles
159
159
  requirement: !ruby/object:Gem::Requirement
@@ -286,28 +286,28 @@ dependencies:
286
286
  requirements:
287
287
  - - "~>"
288
288
  - !ruby/object:Gem::Version
289
- version: 3.10.0
289
+ version: 3.12.0
290
290
  type: :development
291
291
  prerelease: false
292
292
  version_requirements: !ruby/object:Gem::Requirement
293
293
  requirements:
294
294
  - - "~>"
295
295
  - !ruby/object:Gem::Version
296
- version: 3.10.0
296
+ version: 3.12.0
297
297
  - !ruby/object:Gem::Dependency
298
298
  name: rspec-parameterized
299
299
  requirement: !ruby/object:Gem::Requirement
300
300
  requirements:
301
301
  - - "~>"
302
302
  - !ruby/object:Gem::Version
303
- version: '0.4'
303
+ version: '1.0'
304
304
  type: :development
305
305
  prerelease: false
306
306
  version_requirements: !ruby/object:Gem::Requirement
307
307
  requirements:
308
308
  - - "~>"
309
309
  - !ruby/object:Gem::Version
310
- version: '0.4'
310
+ version: '1.0'
311
311
  - !ruby/object:Gem::Dependency
312
312
  name: rufo
313
313
  requirement: !ruby/object:Gem::Requirement
@@ -462,7 +462,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
462
462
  - !ruby/object:Gem::Version
463
463
  version: '0'
464
464
  requirements: []
465
- rubygems_version: 3.1.6
465
+ rubygems_version: 3.3.26
466
466
  signing_key:
467
467
  specification_version: 4
468
468
  summary: Instrumentation for GitLab