gitlab-labkit 1.1.3 → 1.2.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/lib/labkit/fields.rb +49 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8cad3a0a83a80e9fac360086b222165e87138784589c0097c2da798e9f97e10a
|
|
4
|
+
data.tar.gz: 2b18c29e1fd8f7e90768593957a144498ac80af3bb215f3b0145d77507ff9847
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3578c97ad20f26e43d9fd377a04f06bc4f6cad1b13469dee2a921a15b82230f10d70d9e01665ab930fb1240f6a5629898147cf5426c54f8698640d047afd7b02
|
|
7
|
+
data.tar.gz: 0fb39ba59dadbc0a1b8be0e2c7f00bf19850b1cb12058410d29ff2977b689b7dd1f25e1da5e65f5ae5543a6fda7f249a37275f1994371c717988d7da92dfae61
|
data/lib/labkit/fields.rb
CHANGED
|
@@ -5,7 +5,7 @@ module Labkit
|
|
|
5
5
|
# Fields is intended to be a SSOT for all of the common field names that
|
|
6
6
|
# we emit via any observability we add to our systems.
|
|
7
7
|
#
|
|
8
|
-
# These fields should span multiple services.
|
|
8
|
+
# These fields should span multiple services.
|
|
9
9
|
#
|
|
10
10
|
# The goal of this package is to reduce the likelihood for typos or
|
|
11
11
|
# subtly different naming conventions. This will help to ensure we
|
|
@@ -30,7 +30,6 @@ module Labkit
|
|
|
30
30
|
module Fields
|
|
31
31
|
# correlation_id - string
|
|
32
32
|
#
|
|
33
|
-
# correlation_id - string
|
|
34
33
|
# This field is used to correlate
|
|
35
34
|
# the logs emitted by all of our systems.
|
|
36
35
|
# This should be present in all log line
|
|
@@ -50,5 +49,53 @@ module Labkit
|
|
|
50
49
|
# should clearly indicate what the intended use of the
|
|
51
50
|
# field is and should be replicated across the labkit
|
|
52
51
|
# variations.
|
|
52
|
+
|
|
53
|
+
# Get the constant name for a field value
|
|
54
|
+
# @param field_value [String] The field value (e.g., "gl_user_id")
|
|
55
|
+
# @return [String, nil] The constant name (e.g., "GL_USER_ID") or nil if not found
|
|
56
|
+
def self.constant_name_for(field_value)
|
|
57
|
+
constants(false).find do |const_name|
|
|
58
|
+
next if const_name == :Deprecated
|
|
59
|
+
|
|
60
|
+
const_get(const_name) == field_value
|
|
61
|
+
end&.to_s
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
module Deprecated
|
|
65
|
+
# This module tracks deprecated field names and maps them to their
|
|
66
|
+
# standard replacements. These mappings are used by the field scanner
|
|
67
|
+
# to identify and track usage of deprecated fields in the codebase.
|
|
68
|
+
|
|
69
|
+
MAPPINGS = {
|
|
70
|
+
Fields::GL_USER_ID => %w[user_id userid],
|
|
71
|
+
}.freeze
|
|
72
|
+
|
|
73
|
+
class << self
|
|
74
|
+
# Get all deprecated fields as a lookup hash
|
|
75
|
+
#
|
|
76
|
+
# @return [Hash{String => String}] Hash mapping deprecated field names to standard field names
|
|
77
|
+
def all
|
|
78
|
+
@all ||= MAPPINGS.each_with_object({}) do |(key, values), result|
|
|
79
|
+
values.each { |v| result[v] = key }
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Check if a field is deprecated
|
|
84
|
+
#
|
|
85
|
+
# @param field_name [String, Symbol] The field name to check
|
|
86
|
+
# @return [Boolean] true if the field is deprecated
|
|
87
|
+
def deprecated?(field_name)
|
|
88
|
+
all.key?(field_name.to_s)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Get the standard field for a deprecated field
|
|
92
|
+
#
|
|
93
|
+
# @param deprecated_field [String, Symbol] The deprecated field name
|
|
94
|
+
# @return [String, nil] The standard field name, or nil if not found
|
|
95
|
+
def standard_field_for(deprecated_field)
|
|
96
|
+
all[deprecated_field.to_s]
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
53
100
|
end
|
|
54
101
|
end
|