gitlab-labkit 1.2.0 → 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: 8cad3a0a83a80e9fac360086b222165e87138784589c0097c2da798e9f97e10a
4
- data.tar.gz: 2b18c29e1fd8f7e90768593957a144498ac80af3bb215f3b0145d77507ff9847
3
+ metadata.gz: a0cf5e5935ee28f4b6bcc2165d6df81c38006f2b503044563850e744cfb85737
4
+ data.tar.gz: e5c6137d9430cedfc0984d279d09c9758cdc43e6c25734c91d5b558cf92452e5
5
5
  SHA512:
6
- metadata.gz: 3578c97ad20f26e43d9fd377a04f06bc4f6cad1b13469dee2a921a15b82230f10d70d9e01665ab930fb1240f6a5629898147cf5426c54f8698640d047afd7b02
7
- data.tar.gz: 0fb39ba59dadbc0a1b8be0e2c7f00bf19850b1cb12058410d29ff2977b689b7dd1f25e1da5e65f5ae5543a6fda7f249a37275f1994371c717988d7da92dfae61
6
+ metadata.gz: 4fab0460afaf9c9912e0225942395669336232f1de591a638e71715ea198cb9cee3f8c5dd462478fc62d1f3ca1741d7d4561983fb5a01cc6760efea2ed2d9374
7
+ data.tar.gz: ed6778b22816c5e4b301f12b71b28a97d126f4238b896941674a543631a89b7d0624d0c2b2210918f2621f1a9cf8d4c874f3cb0df0c9e67018dbe5d420ba5330
@@ -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.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Newdigate