gitlab-labkit 0.41.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d9f3f7db908df4f839a96f74ce39650dad4a132e5b72e3ac4d7fb1358bc48f1
4
- data.tar.gz: 125b63a4f1716bfbb8dca8ab986c5f824dd2a56f8df46079041c6c62f5e385e5
3
+ metadata.gz: a34b2991af0968bfb934925fb5a71ac0206224a6ffdfe65ba026fa0dc9a56dc3
4
+ data.tar.gz: 001d8f998218b85fb6da441681197211d2d13a21d36bff3218e3f142fbfd2d0d
5
5
  SHA512:
6
- metadata.gz: 92907d96e457abebe07567df0506f80c585f159ead4b78b6bdf8c57b3eb82d19c7700b88d2733415dad5c0d3bba792c23ae9b1e2281df9fef6ec44b7069d453c
7
- data.tar.gz: 678ab5ad3290e93ff0682ef1f5f08681ea85e01c65919c3c16f21c95949065fa70c20507499b20c2c72f1a856838650fe79963533b529a463d9fc5a6f99a3bfc
6
+ metadata.gz: d294b0a1f9c935bf723082a0e470ea1774c150c755511f5f8aa879611e48aec0d7b268758d908af4ccccbcfa957b7df5c940d11b7a37237f433fa7e8a2d0011e
7
+ data.tar.gz: fb075af43298d662526fb561eff09bccd38dcce8d6b58f740e165a13dc9fca9e3e3391e67e114c11f317814ce0dbc687c1509ddcac491d9c4b4a4c1cdf8b03e4
@@ -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.92 # renovate:managed
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:
@@ -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
- CORRELATION_ID_KEY = "correlation_id"
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[CORRELATION_ID_KEY]
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[CORRELATION_ID_KEY] ||= new_id
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(LOG_KEY => correlation_id) do |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
@@ -92,7 +92,7 @@ module Labkit
92
92
  # @param extra [Hash] Additional data to include in the log event
93
93
  # @return [self]
94
94
  def checkpoint(**extra)
95
- return unless ensure_started!
95
+ return self unless ensure_started!
96
96
 
97
97
  @checkpoint_time = Time.now.utc
98
98
  checkpoint_counter.increment(checkpoint: "intermediate", **base_labels)
@@ -106,7 +106,7 @@ module Labkit
106
106
  # @yield [self] When a block is provided, the experience will be completed automatically.
107
107
  # @param extra [Hash] Additional data to include in the log
108
108
  def resume(**extra, &)
109
- return unless ensure_started!
109
+ return self unless ensure_started!
110
110
 
111
111
  checkpoint(checkpoint_action: 'resume', **extra)
112
112
 
@@ -120,8 +120,7 @@ module Labkit
120
120
  # @param extra [Hash] Additional data to include in the log event
121
121
  # @return [self]
122
122
  def complete(**extra)
123
- return unless ensure_started!
124
- return unless ensure_incomplete!
123
+ return self unless ensure_started! && ensure_incomplete!
125
124
 
126
125
  begin
127
126
  @end_time = Time.now.utc
@@ -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::Correlation::CorrelationId::LOG_KEY] = Labkit::Correlation::CorrelationId.current_id
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::Context::CORRELATION_ID_KEY => correlation_id(env)) do |context|
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::Context::CORRELATION_ID_KEY] = job["correlation_id"] if job["correlation_id"]
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.41.1
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