gitlab-labkit 0.24.0 → 0.26.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: 6e86f57fe5a7804f3b930b86abd75f74f7e4a6b01d67eba235c036ba88646052
4
- data.tar.gz: ea7d3fe526de0859b739b108adebdf86110cc49f6c59ae98b9b834c876794bb7
3
+ metadata.gz: 67d751c41c569f082517aca92fb16a5671d9b82693a6a02065ad349ad648c4ab
4
+ data.tar.gz: 94ac25bcad3f2cdb07626e882866b232e75328d5ad458d99dd7feeb81d656852
5
5
  SHA512:
6
- metadata.gz: 0a21a42f553c966c7bf5555afea1abaa72ab2837300bd09bae84c2b58f141a72c22cb3f2f20257c1ab1aadc789af47b2ed3104440b0ca3d66f37e67c17c32f0e
7
- data.tar.gz: b8f72ab37a74c3523dfc8095d2ebe549c2710bed45741c9a6acb0211424a602695732340e94b7d9d7d3bcd3a1b95151540b3726462bf821ee03acc03951a3968
6
+ metadata.gz: 11754a10140341571519d42e999240c3f580b32e7313852c361ba93c42f9b9d0b18599d019d07217566440e128d8f8a00490ab39938e1dec7f813f1d45c03806
7
+ data.tar.gz: 7b993168a160a5beacf9757893b424f3da57eeb4fa71600d7ed41e99841a92d0bc7cb4a95fefa572697957c5e7081a672cbe570897db08e5d78e55d6bac3cedb
data/.gitlab-ci.yml CHANGED
@@ -20,16 +20,11 @@ workflow:
20
20
  test:3.0:
21
21
  image: ruby:3.0
22
22
  <<: *test_definition
23
- allow_failure: true # until we resolve grpc compatibility, see https://gitlab.com/gitlab-org/labkit-ruby/-/merge_requests/81
24
23
 
25
24
  test:2.7:
26
25
  image: ruby:2.7
27
26
  <<: *test_definition
28
27
 
29
- test:2.6:
30
- image: ruby:2.6
31
- <<: *test_definition
32
-
33
28
  static-analysis:
34
29
  before_script:
35
30
  - bundle install
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_runtime_dependency "jaeger-client", "~> 1.1.0"
26
26
  spec.add_runtime_dependency "opentracing", "~> 0.4"
27
27
  spec.add_runtime_dependency "pg_query", "~> 2.1"
28
- spec.add_runtime_dependency "redis", ">3.0.0", "<5.0.0"
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"
@@ -123,7 +123,7 @@ module Labkit
123
123
  data.merge!(attributes)
124
124
 
125
125
  # Remove keys that had their values set to `nil` in the new attributes
126
- data.keep_if { |_, value| value.present? }
126
+ data.keep_if { |_, value| valid_data?(value) }
127
127
 
128
128
  # Assign a correlation if it was missing in the first context or when
129
129
  # explicitly removed
@@ -146,12 +146,16 @@ module Labkit
146
146
  data.transform_values do |value|
147
147
  value = call_or_value(value)
148
148
 
149
- value.presence
149
+ value if valid_data?(value)
150
150
  end.compact
151
151
  end
152
152
 
153
153
  def new_id
154
154
  SecureRandom.hex
155
155
  end
156
+
157
+ def valid_data?(value)
158
+ value == false || value.present?
159
+ end
156
160
  end
157
161
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+ require "time"
3
+ require "logger"
4
+ require "json"
5
+
6
+ module Labkit
7
+ module Logging
8
+ class JsonLogger < ::Logger
9
+ def self.log_level(fallback: ::Logger::DEBUG)
10
+ ENV.fetch("GITLAB_LOG_LEVEL", fallback)
11
+ end
12
+
13
+ def initialize(path, level: JsonLogger.log_level)
14
+ super
15
+ end
16
+
17
+ def format_message(severity, timestamp, progname, message)
18
+ data = default_attributes
19
+ data[:severity] = severity
20
+ data[:time] = timestamp.utc.iso8601(3)
21
+ data[Labkit::Correlation::CorrelationId::LOG_KEY] = Labkit::Correlation::CorrelationId.current_id
22
+
23
+ case message
24
+ when String
25
+ data[:message] = message
26
+ when Hash
27
+ data.merge!(message)
28
+ end
29
+
30
+ dump_json(data) << "\n"
31
+ end
32
+
33
+ private
34
+
35
+ def default_attributes
36
+ {}
37
+ end
38
+
39
+ def dump_json(data)
40
+ JSON.generate(data)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -6,5 +6,6 @@ module Labkit
6
6
  module Logging
7
7
  autoload :GRPC, "labkit/logging/grpc"
8
8
  autoload :Sanitizer, "labkit/logging/sanitizer"
9
+ autoload :JsonLogger, "labkit/logging/json_logger"
9
10
  end
10
11
  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.24.0
4
+ version: 0.26.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: 2022-06-23 00:00:00.000000000 Z
11
+ date: 2022-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -115,7 +115,7 @@ dependencies:
115
115
  version: 3.0.0
116
116
  - - "<"
117
117
  - !ruby/object:Gem::Version
118
- version: 5.0.0
118
+ version: 6.0.0
119
119
  type: :runtime
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
@@ -125,7 +125,7 @@ dependencies:
125
125
  version: 3.0.0
126
126
  - - "<"
127
127
  - !ruby/object:Gem::Version
128
- version: 5.0.0
128
+ version: 6.0.0
129
129
  - !ruby/object:Gem::Dependency
130
130
  name: excon
131
131
  requirement: !ruby/object:Gem::Requirement
@@ -386,6 +386,7 @@ files:
386
386
  - lib/labkit/logging.rb
387
387
  - lib/labkit/logging/grpc.rb
388
388
  - lib/labkit/logging/grpc/server_interceptor.rb
389
+ - lib/labkit/logging/json_logger.rb
389
390
  - lib/labkit/logging/sanitizer.rb
390
391
  - lib/labkit/middleware.rb
391
392
  - lib/labkit/middleware/rack.rb