gitlab-labkit 0.25.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: b1966ecde160ebd4af3cf1e131cdc2f5e7665e327bc0074128d293f4b33710c8
4
- data.tar.gz: 0abde88973ac84a12862be74f5a438ae5a76852d805dc690852f121eb0466cce
3
+ metadata.gz: 67d751c41c569f082517aca92fb16a5671d9b82693a6a02065ad349ad648c4ab
4
+ data.tar.gz: 94ac25bcad3f2cdb07626e882866b232e75328d5ad458d99dd7feeb81d656852
5
5
  SHA512:
6
- metadata.gz: 7a18b78e676c89304be5db049ea675fe2b8671d0f4eabfec557340328821dc14f56a9b4a6e80a86fa62c72a657e97dd5f667e63a5da2eedb419114ce68480eeb
7
- data.tar.gz: 2aeb4a0f9b5cd31e89d169654992977bbab625539da4511de6e989ec8dfae31693a4180e0def980437cdc89b258d18ea577d5f9ca70b06797e7080ea4b7d5e08
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
@@ -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.25.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-08-30 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
@@ -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