gitlab-labkit 1.1.3 → 1.3.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: 1bbb89ac1275f06d828f9d9fa4a24e20e33f4a01d201956d4dd8d30e87dd8f5a
4
- data.tar.gz: 1d6b24a17f8b2096e34303fba306ea1271146b3245cb5edcb3fabbccd26f1e45
3
+ metadata.gz: a0cf5e5935ee28f4b6bcc2165d6df81c38006f2b503044563850e744cfb85737
4
+ data.tar.gz: e5c6137d9430cedfc0984d279d09c9758cdc43e6c25734c91d5b558cf92452e5
5
5
  SHA512:
6
- metadata.gz: 4950f9c1615b432b5d53ab54a51cca84a10cbf548b434665fdda93a2204f912f172540652df7b634907c61fa88f03f50a1ad9de96e04d2795a59393fe3fdcf93
7
- data.tar.gz: a67c2262dd119373431f271779baf8311c5eb47a794a2970e1b4b9dcd28c59a4253ff844654f20a99026f95aabe6538f8fbdc864da29f007cd6c94a99eb427ad
6
+ metadata.gz: 4fab0460afaf9c9912e0225942395669336232f1de591a638e71715ea198cb9cee3f8c5dd462478fc62d1f3ca1741d7d4561983fb5a01cc6760efea2ed2d9374
7
+ data.tar.gz: ed6778b22816c5e4b301f12b71b28a97d126f4238b896941674a543631a89b7d0624d0c2b2210918f2621f1a9cf8d4c874f3cb0df0c9e67018dbe5d420ba5330
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. This is
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
@@ -3,6 +3,7 @@
3
3
  require 'net/http'
4
4
  require 'uri'
5
5
  require 'json'
6
+ require 'active_support/core_ext/module/attribute_accessors'
6
7
 
7
8
  module Labkit
8
9
  module JsonSchema
@@ -50,6 +50,33 @@ This configuration is useful when:
50
50
 
51
51
  **Note:** The timeout applies to both connection opening and reading operations when fetching remote JSON schema references.
52
52
 
53
+ ### Feature Category Schema Preloading
54
+
55
+ When validating user experience SLI definitions, the system validates the `feature_category` field against a remote up to date JSON schema (cached after first request) by default. To avoid HTTP requests at runtime, you can preload the feature category schema from a local file:
56
+
57
+ ```ruby
58
+ Labkit::UserExperienceSli.configure do |config|
59
+ config.feature_category_schema_path = Rails.root.join('config/feature_categories/schema.json').to_s
60
+ end
61
+ ```
62
+
63
+ JSON schema example:
64
+
65
+ ```json
66
+ {
67
+ "$schema": "http://json-schema.org/draft-07/schema#",
68
+ "type": "string",
69
+ "enum": ["source_code_management", "team_planning", "observability"]
70
+ }
71
+ ```
72
+
73
+ The current single source of truth can be found in https://gitlab.com/gitlab-org/gitlab/-/raw/master/config/feature_categories/schema.json.
74
+
75
+
76
+ This configuration is useful when:
77
+ - Running in environments without external network access
78
+ - Ensuring consistent validation against a known schema version
79
+
53
80
  ### User Experience Definitions
54
81
 
55
82
  User Experience SLI definitions will be lazy loaded from the default directory (`config/user_experience_slis`).
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'labkit/json_schema/ref_resolver'
4
+ require 'labkit/logging/json_logger'
3
5
  require 'labkit/user_experience_sli/current'
4
6
  require 'labkit/user_experience_sli/error'
5
7
  require 'labkit/user_experience_sli/experience'
6
8
  require 'labkit/user_experience_sli/null'
7
9
  require 'labkit/user_experience_sli/registry'
8
- require 'labkit/logging/json_logger'
9
10
 
10
11
  module Labkit
11
12
  # Labkit::UserExperienceSli namespace module.
@@ -23,6 +24,33 @@ module Labkit
23
24
  @registry_path = File.join("config", "user_experience_slis")
24
25
  @ref_resolver_timeout = 2
25
26
  end
27
+
28
+ def feature_category_schema_path=(path)
29
+ preload_feature_category_schema(path) if path
30
+ end
31
+
32
+ private
33
+
34
+ def preload_feature_category_schema(path)
35
+ internal_schema = JSON.parse(File.read(Registry::SCHEMA_PATH))
36
+ ref_url = internal_schema.dig("properties", "feature_category", "$ref")
37
+ return unless ref_url
38
+
39
+ schema = parse_schema_json(read_schema_file(path), path)
40
+ Labkit::JsonSchema::RefResolver.cache[ref_url] = schema
41
+ end
42
+
43
+ def read_schema_file(path)
44
+ File.read(path)
45
+ rescue StandardError => e
46
+ raise(UserExperienceError, "Failed to read feature category schema file at '#{path}': #{e.message}")
47
+ end
48
+
49
+ def parse_schema_json(content, path)
50
+ JSON.parse(content)
51
+ rescue JSON::ParserError => e
52
+ raise(UserExperienceError, "Failed to parse feature category schema JSON at '#{path}': #{e.message}")
53
+ end
26
54
  end
27
55
 
28
56
  class << self
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: 1.1.3
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Newdigate