gitlab-labkit 0.41.2 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.pre-commit-config.yaml +1 -1
- data/lib/gitlab-labkit.rb +1 -0
- data/lib/labkit/context.rb +11 -4
- data/lib/labkit/correlation/correlation_id.rb +3 -3
- data/lib/labkit/fields.rb +41 -0
- data/lib/labkit/logging/json_logger.rb +1 -1
- data/lib/labkit/middleware/rack.rb +1 -1
- data/lib/labkit/middleware/sidekiq/context/client.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a34b2991af0968bfb934925fb5a71ac0206224a6ffdfe65ba026fa0dc9a56dc3
|
4
|
+
data.tar.gz: 001d8f998218b85fb6da441681197211d2d13a21d36bff3218e3f142fbfd2d0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d294b0a1f9c935bf723082a0e470ea1774c150c755511f5f8aa879611e48aec0d7b268758d908af4ccccbcfa957b7df5c940d11b7a37237f433fa7e8a2d0011e
|
7
|
+
data.tar.gz: fb075af43298d662526fb561eff09bccd38dcce8d6b58f740e165a13dc9fca9e3e3391e67e114c11f317814ce0dbc687c1509ddcac491d9c4b4a4c1cdf8b03e4
|
data/.pre-commit-config.yaml
CHANGED
@@ -25,7 +25,7 @@ repos:
|
|
25
25
|
# Documentation available at
|
26
26
|
# https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks/-/blob/main/docs/pre-commit.md
|
27
27
|
- repo: https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks
|
28
|
-
rev: v2.
|
28
|
+
rev: v2.93 # renovate:managed
|
29
29
|
|
30
30
|
hooks:
|
31
31
|
- id: shellcheck # Run shellcheck for changed Shell files
|
data/lib/gitlab-labkit.rb
CHANGED
@@ -15,6 +15,7 @@ module Labkit
|
|
15
15
|
autoload :Logging, "labkit/logging"
|
16
16
|
autoload :Metrics, "labkit/metrics"
|
17
17
|
autoload :Middleware, "labkit/middleware"
|
18
|
+
autoload :Fields, "labkit/fields"
|
18
19
|
|
19
20
|
# Publishers to publish notifications whenever a HTTP reqeust is made.
|
20
21
|
# A broadcasted notification's payload in topic "request.external_http" includes:
|
data/lib/labkit/context.rb
CHANGED
@@ -7,6 +7,8 @@ require "active_support/core_ext/string/starts_ends_with"
|
|
7
7
|
require "active_support/core_ext/string/inflections"
|
8
8
|
require "active_support/core_ext/object/blank"
|
9
9
|
|
10
|
+
require_relative "fields"
|
11
|
+
|
10
12
|
module Labkit
|
11
13
|
# A context can be used to provide structured information on what resources
|
12
14
|
# GitLab is working on within a service.
|
@@ -24,9 +26,14 @@ module Labkit
|
|
24
26
|
# end
|
25
27
|
#
|
26
28
|
class Context
|
29
|
+
# The meta log key is used to effectively aggregate
|
30
|
+
# the attributes that we should be associating with
|
31
|
+
# the logs that we emit.
|
32
|
+
# These fields will get propagated across all services
|
33
|
+
# which will allow us to correlate logs across these
|
34
|
+
# different services.
|
27
35
|
LOG_KEY = "meta"
|
28
|
-
|
29
|
-
RAW_KEYS = [CORRELATION_ID_KEY].freeze
|
36
|
+
RAW_KEYS = [Fields::CORRELATION_ID].freeze
|
30
37
|
|
31
38
|
class << self
|
32
39
|
def with_context(attributes = {})
|
@@ -92,7 +99,7 @@ module Labkit
|
|
92
99
|
end
|
93
100
|
|
94
101
|
def correlation_id
|
95
|
-
data[
|
102
|
+
data[Fields::CORRELATION_ID]
|
96
103
|
end
|
97
104
|
|
98
105
|
def get_attribute(attribute)
|
@@ -113,7 +120,7 @@ module Labkit
|
|
113
120
|
|
114
121
|
# Assign a correlation if it was missing in the first context or when
|
115
122
|
# explicitly removed
|
116
|
-
data[
|
123
|
+
data[Fields::CORRELATION_ID] ||= new_id
|
117
124
|
|
118
125
|
data
|
119
126
|
end
|
@@ -5,11 +5,11 @@ module Labkit
|
|
5
5
|
# CorrelationId module provides access the Correlation-ID
|
6
6
|
# of the current request
|
7
7
|
module CorrelationId
|
8
|
-
LOG_KEY = Labkit::Context::CORRELATION_ID_KEY
|
9
|
-
|
10
8
|
class << self
|
11
9
|
def use_id(correlation_id)
|
12
|
-
Labkit::Context.with_context(
|
10
|
+
Labkit::Context.with_context(
|
11
|
+
Labkit::Fields::CORRELATION_ID => correlation_id
|
12
|
+
) do |context|
|
13
13
|
yield(context.correlation_id)
|
14
14
|
end
|
15
15
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Labkit
|
4
|
+
##
|
5
|
+
# Fields is intended to be a SSOT for all of the common field names that
|
6
|
+
# we emit via any observability we add to our systems.
|
7
|
+
#
|
8
|
+
# These fields should span multiple services. This is
|
9
|
+
#
|
10
|
+
# The goal of this package is to reduce the likelihood for typos or
|
11
|
+
# subtly different naming conventions. This will help to ensure we
|
12
|
+
# are able to marry up logs between different systems as a request
|
13
|
+
# is being processed.
|
14
|
+
#
|
15
|
+
# Usage:
|
16
|
+
# require 'labkit/fields'
|
17
|
+
# ...
|
18
|
+
# data[Labkit::Fields::GL_USER_ID] = user.id
|
19
|
+
# ...
|
20
|
+
#
|
21
|
+
module Fields
|
22
|
+
# correlation_id - string
|
23
|
+
#
|
24
|
+
# This field is used to correlate
|
25
|
+
# the logs emitted by all of our systems.
|
26
|
+
#
|
27
|
+
# This should be present in all log line
|
28
|
+
# emissions.
|
29
|
+
CORRELATION_ID = "correlation_id"
|
30
|
+
|
31
|
+
# We'll need to add the rest of the top
|
32
|
+
# level fields here:
|
33
|
+
# [endpoint_id, duration_s, status_code]
|
34
|
+
|
35
|
+
# gl_user_id - integer
|
36
|
+
GL_USER_ID = "gl_user_id"
|
37
|
+
|
38
|
+
# gl_user_name - string
|
39
|
+
GL_USER_NAME = "gl_user_name"
|
40
|
+
end
|
41
|
+
end
|
@@ -42,7 +42,7 @@ module Labkit
|
|
42
42
|
data[:time] = timestamp.utc.iso8601(3)
|
43
43
|
|
44
44
|
if self.class.exclude_context?
|
45
|
-
data[Labkit::
|
45
|
+
data[Labkit::Fields::CORRELATION_ID] = Labkit::Correlation::CorrelationId.current_id
|
46
46
|
else
|
47
47
|
data.merge!(Labkit::Context.current.to_h)
|
48
48
|
end
|
@@ -18,7 +18,7 @@ module Labkit
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def call(env)
|
21
|
-
Labkit::Context.with_context(Labkit::
|
21
|
+
Labkit::Context.with_context(Labkit::Fields::CORRELATION_ID => correlation_id(env)) do |context|
|
22
22
|
status, headers, response = @app.call(env)
|
23
23
|
|
24
24
|
headers[HEADER] = context_to_json(context)
|
@@ -15,7 +15,7 @@ module Labkit
|
|
15
15
|
# will always generate a new correlation_id and we'd rather carry
|
16
16
|
# through the correlation_id from the previous job if it is
|
17
17
|
# present (eg. for retries).
|
18
|
-
attributes[Labkit::
|
18
|
+
attributes[Labkit::Fields::CORRELATION_ID] = job["correlation_id"] if job["correlation_id"]
|
19
19
|
|
20
20
|
Labkit::Context.with_context(attributes) do |context|
|
21
21
|
job.merge!(context.to_h)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab-labkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.42.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Newdigate
|
@@ -466,6 +466,7 @@ files:
|
|
466
466
|
- lib/labkit/covered_experience/null.rb
|
467
467
|
- lib/labkit/covered_experience/registry.rb
|
468
468
|
- lib/labkit/excon_publisher.rb
|
469
|
+
- lib/labkit/fields.rb
|
469
470
|
- lib/labkit/fips.rb
|
470
471
|
- lib/labkit/httpclient_publisher.rb
|
471
472
|
- lib/labkit/logging.rb
|