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 +4 -4
- data/.gitlab-ci.yml +0 -5
- data/gitlab-labkit.gemspec +1 -1
- data/lib/labkit/context.rb +6 -2
- data/lib/labkit/logging/json_logger.rb +44 -0
- data/lib/labkit/logging.rb +1 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67d751c41c569f082517aca92fb16a5671d9b82693a6a02065ad349ad648c4ab
|
4
|
+
data.tar.gz: 94ac25bcad3f2cdb07626e882866b232e75328d5ad458d99dd7feeb81d656852
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/gitlab-labkit.gemspec
CHANGED
@@ -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", "<
|
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"
|
data/lib/labkit/context.rb
CHANGED
@@ -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
|
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
|
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
|
data/lib/labkit/logging.rb
CHANGED
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.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-
|
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:
|
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:
|
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
|