gitlab-labkit 1.5.0 → 1.5.1

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: bf6262472d851bcdfeb96b0ed3b7acf25f462b0b968d2ac2f431ea946b68b33a
4
- data.tar.gz: b04bfc82c7ea63848849af40c7940788796b486a16c41416de824b7440f01992
3
+ metadata.gz: 7c7057e132dd046256e4e099cadef103283e3bbd682ecf3d1c596a0996d2c007
4
+ data.tar.gz: 238db3eca235a4423df26c23b65ed22523c7d27d9209a19f953df9e3ff817437
5
5
  SHA512:
6
- metadata.gz: 7c5a7b9002239cf23e7609fd8c07174bf588c0f2f1f2177616d6f98f4490c8e32f74cb7c8e62c1bf8ae839da24e30023e9bd733f1a6e40bbf75484d614a3d9ad
7
- data.tar.gz: e699b4a653c268c7333bdad41006a5c52d0fbdaf0aa4c21ca90bbb396695d6519695243e0548e0f5439f9bd11366c6a3359c013766deadaa6996e31bbbfb7c7a
6
+ metadata.gz: cd33f670799561477b139c690eab1e89ba6e28e660cf95d64725be3a5daf2b2df3e589180fcd6afeea7c2c6fa01e8c7e76ddaba3be4d0ee0ced09f16953e4764
7
+ data.tar.gz: bd64be24a45c2fec786c94bdc61bc3d4abf982eb1d073db41a217240b46b741fea2982e58c1ca568d6c4ff3474d32296cca2991f96011b7a188fa955f457fc3a
@@ -0,0 +1,9 @@
1
+ ## Description
2
+
3
+ <!-- Briefly describe what this MR does and why -->
4
+
5
+ ## Related Issues
6
+
7
+ <!-- Link to related issues using #issue_number -->
8
+
9
+ /assign me
@@ -2,134 +2,172 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- The LabKit Field Validator detects when your code uses deprecated logging field names and helps you migrate to standardized fields. This supports the [Observability Field Standardisation initiative](https://handbook.gitlab.com/handbook/engineering/architecture/design-documents/observability_field_standardisation/).
5
+ The LabKit Field Validator detects deprecated logging field names and helps
6
+ migrate them to standardized fields.
7
+ It supports the [Observability Field Standardisation initiative](https://handbook.gitlab.com/handbook/engineering/architecture/design-documents/observability_field_standardisation/).
6
8
 
7
- **Goal:** Standardize logging field names across GitLab so logs are queryable and actionable across all systems.
9
+ The validator intercepts logging calls in non-production environments, detects
10
+ deprecated fields, and compares them against a frozen baseline stored in
11
+ `.labkit_logging_todo.yml`.
12
+ New offenses raise an error. Known offenses are allowed.
8
13
 
9
- **How it works:** The validator intercepts logging calls during development and testing, detects deprecated fields, and compares them against a frozen baseline. New offenses fail CI; known offenses are tracked in `.labkit_logging_todo.yml`. The validator is **not** active in production environments.
14
+ For the architectural decision and rationale, see
15
+ [ADR: Dynamic Runtime Linting](./architecture/decisions/001_field_standardization_dynamic_runtime_linting.md).
10
16
 
11
- For the architectural decision and rationale, see [ADR: Dynamic Runtime Linting](./architecture/decisions/001_field_standardization_dynamic_runtime_linting.md).
17
+ ## Key concepts
12
18
 
13
- ## Key Concepts
19
+ Offense
20
+ : A unique combination of file path, deprecated field, and logger class.
21
+ Multiple log calls in the same file using the same deprecated field count as
22
+ one offense.
23
+ An offense exists until the deprecated field is entirely removed from the
24
+ file.
14
25
 
15
- **Offense**
16
- - A unique combination of [File Path] + [Deprecated Field] + [Logger Class]
17
- - Multiple log calls in the same file using the same deprecated field = 1 offense
18
- - Offenses exist until the deprecated field is entirely removed from the file
26
+ TODO Baseline
27
+ : The list of known offenses in `.labkit_logging_todo.yml`.
28
+ The baseline prevents regression while allowing incremental cleanup.
19
29
 
20
- **TODO Baseline**
21
- - A list of known offenses tracked in `.labkit_logging_todo.yml`
22
- - Existing offenses in this baseline are allowed
23
- - Any new offenses detected during development raise an error
24
- - Prevents regression while allowing incremental cleanup
30
+ ## Quick start
25
31
 
26
- ## Quick Start
32
+ 1. Initialize the todo file:
27
33
 
28
- ### First-Time Setup
29
-
30
- 1. **Initialize the todo file:**
31
-
32
- ```bash
34
+ ```shell
33
35
  bundle exec labkit-logging init
34
36
  ```
35
37
 
36
- This creates `.labkit_logging_todo.yml` with `skip_ci_failure: true`, which allows CI to pass while collecting the initial baseline.
38
+ This creates `.labkit_logging_todo.yml` with `skip_ci_failure: true`, which
39
+ allows CI to pass while outputting found offenses.
40
+ These are later collected to create the baseline.
37
41
 
38
- 2. **Commit and push:**
42
+ 1. Commit and push:
39
43
 
40
- ```bash
44
+ ```shell
41
45
  git add .labkit_logging_todo.yml
42
46
  git commit -m "Add LabKit logging todo baseline"
43
47
  git push
44
48
  ```
45
49
 
46
- 3. **Wait for CI to complete**, then fetch the baseline:
50
+ 1. Wait for CI to complete, then fetch the baseline:
47
51
 
48
- ```bash
52
+ ```shell
49
53
  bundle exec labkit-logging fetch <project> <pipeline_id>
50
54
  ```
51
55
 
52
56
  For example:
53
- ```bash
57
+
58
+ ```shell
54
59
  bundle exec labkit-logging fetch gitlab-org/gitlab 12345
55
60
  ```
56
61
 
57
- This fetches all detected offenses from the CI pipeline logs and populates the todo file. The `skip_ci_failure` flag is automatically removed.
62
+ This fetches detected offenses from CI pipeline logs and populates the todo
63
+ file.
64
+ The `skip_ci_failure` flag is automatically removed.
58
65
 
59
- 4. **Commit the populated baseline:**
66
+ 1. Commit the populated baseline:
60
67
 
61
- ```bash
68
+ ```shell
62
69
  git add .labkit_logging_todo.yml
63
70
  git commit -m "Populate LabKit logging todo baseline"
64
71
  git push
65
72
  ```
66
73
 
67
- Future CI runs will now enforce this baseline—new offenses will fail the pipeline.
74
+ Future CI runs enforce this baseline.
75
+ New offenses fail the pipeline.
68
76
 
69
- ## Developer Workflow
77
+ ## How to deprecate a field
70
78
 
71
- ### Fixing Offenses (Recommended)
79
+ 1. In `lib/labkit/fields.rb`, confirm the standard field constant exists in
80
+ `Labkit::Fields`. Add it if it does not exist:
72
81
 
73
- Replace deprecated fields with standard constants:
82
+ ```ruby
83
+ GL_PROJECT_ID = "gl_project_id"
84
+ ```
74
85
 
75
- ```ruby
76
- # Before
77
- logger.info(user_id: current_user.id)
86
+ 1. In the same file, add the deprecated names to
87
+ `Labkit::Fields::Deprecated::MAPPINGS`:
78
88
 
79
- # After
80
- logger.info(Labkit::Fields::GL_USER_ID => current_user.id)
81
- ```
89
+ ```ruby
90
+ Fields::GL_PROJECT_ID => %w[project_id projectid],
91
+ ```
82
92
 
83
- When you fix an offense, it's automatically removed from the baseline on the next test run. Run your tests locally to verify:
93
+ 1. Create a Kibana field alias in the relevant index patterns to map the
94
+ deprecated field to the standard field.
95
+ This ensures log queries continue to work during the migration period.
84
96
 
85
- ```bash
86
- LABKIT_LOGGING_TODO_UPDATE=true bundle exec rspec
87
- ```
97
+ 1. Release a new version of `labkit-ruby`.
88
98
 
89
- ### Adding Offenses Temporarily
99
+ 1. In each consumer repository (for example, `gitlab-org/gitlab`), the MR to
100
+ update `labkit-ruby` fails with new offenses.
101
+ To add these offenses to the baseline, run `fetch` against the failed
102
+ pipeline and push the updated baseline to the branch:
90
103
 
91
- If you can't fix an offense immediately, add it to the baseline:
104
+ ```shell
105
+ bundle exec labkit-logging fetch <project> <pipeline_id>
106
+ git add .labkit_logging_todo.yml
107
+ git commit -m "Add new deprecated field offenses to baseline"
108
+ git push
109
+ ```
92
110
 
93
- ```bash
94
- LABKIT_LOGGING_TODO_UPDATE=true bundle exec rspec
95
- ```
111
+ ## How to fix an offense
96
112
 
97
- This updates `.labkit_logging_todo.yml` with any new offenses found during the test run. Commit the updated file with your changes.
113
+ The field validator runs during any non-production process that exercises
114
+ logging code paths, including tests, local development, and CI pipelines.
115
+ When a log call uses the standard field instead of the deprecated field, the
116
+ validator detects the fix automatically and removes the offense from the
117
+ baseline.
98
118
 
99
- **Note:** Justify in your MR why you can't fix immediately. Keep the baseline as small as possible.
119
+ 1. Replace the deprecated field with the standard field constant.
100
120
 
101
- ### Regenerating the Baseline
121
+ 1. Remove the deprecated field entirely from each log call in the file.
122
+ Adding the new field is not enough. The old key must be deleted.
102
123
 
103
- To regenerate the entire baseline from scratch:
124
+ 1. Run any process that exercises the logging code path:
104
125
 
105
- ```bash
106
- rm .labkit_logging_todo.yml
107
- bundle exec labkit-logging init
108
- # Run CI, then:
109
- bundle exec labkit-logging fetch <project> <pipeline_id>
126
+ ```shell
127
+ bundle exec rspec
128
+ ```
129
+
130
+ The offense is automatically removed from `.labkit_logging_todo.yml`.
131
+
132
+ 1. Commit the updated baseline to complete the cleanup.
133
+
134
+ ### Example
135
+
136
+ ```ruby
137
+ # Before
138
+ logger.info(user_id: current_user.id)
139
+
140
+ # After
141
+ logger.info(Labkit::Fields::GL_USER_ID => current_user.id)
110
142
  ```
111
143
 
112
- ## CI Behavior
144
+ ### Add an offense to the baseline temporarily
113
145
 
114
- ### Baseline Generation Mode
146
+ If you cannot fix an offense immediately, add it to the baseline:
115
147
 
116
- When `skip_ci_failure: true` is set in the todo file:
148
+ ```shell
149
+ LABKIT_LOGGING_TODO_UPDATE=true bundle exec rspec
150
+ ```
117
151
 
118
- - CI passes even when deprecated fields are detected
119
- - Offenses are logged for collection via `labkit-logging fetch`
120
- - Use this mode only during initial setup
152
+ Commit the updated `.labkit_logging_todo.yml` with your changes.
153
+ Justify in your MR why you cannot fix the offense immediately.
121
154
 
122
- ### Enforcement Mode
155
+ ## CI behavior
156
+
157
+ When `skip_ci_failure: true` is set in the todo file, CI passes even when
158
+ deprecated fields are detected.
159
+ Offenses are logged for collection with `labkit-logging fetch`.
160
+ Use this mode only during initial setup or recreating the todo file.
123
161
 
124
162
  When `skip_ci_failure` is not set (normal operation):
125
163
 
126
- - **New offenses fail the pipeline** with a detailed error message
127
- - **Known offenses** (in the baseline) are allowed
128
- - **Fixed offenses** are automatically detected and can be removed from the baseline
164
+ - New offenses fail the pipeline.
165
+ - Known offenses in the baseline are allowed.
166
+ - Fixed offenses are detected automatically.
129
167
 
130
168
  Example CI failure output:
131
169
 
132
- ```
170
+ ```plaintext
133
171
  ================================================================================
134
172
  LabKit Logging Field Standardization: New Offenses Detected
135
173
  ================================================================================
@@ -139,93 +177,75 @@ app/models/project.rb:15: 'project_id' is deprecated. Use 'Labkit::Fields::GL_PR
139
177
 
140
178
  ================================================================================
141
179
  Total: 2 new offense(s) in 2 file(s)
142
- ================================================================================
143
- ```
144
-
145
- ### When Offenses Are Fixed
146
-
147
- When you fix offenses that were in the baseline, you'll see a message indicating which offenses were resolved. Update the baseline locally to remove them:
148
180
 
149
- ```bash
150
- LABKIT_LOGGING_TODO_UPDATE=true bundle exec rspec
151
- git add .labkit_logging_todo.yml
152
- git commit -m "Remove fixed logging offenses from baseline"
181
+ See https://gitlab.com/gitlab-org/ruby/gems/labkit-ruby/-/blob/master/doc/FIELD_STANDARDIZATION.md#new-offenses-detected
182
+ ================================================================================
153
183
  ```
154
184
 
155
- ## CLI Reference
156
-
157
- The `labkit-logging` command provides subcommands for managing the field validator.
185
+ ## CLI reference
158
186
 
159
- ```bash
187
+ ```shell
160
188
  bundle exec labkit-logging <command> [options]
161
189
  ```
162
190
 
163
- ### labkit-logging init
191
+ ### `labkit-logging init`
164
192
 
165
- Creates a new `.labkit_logging_todo.yml` file with `skip_ci_failure: true`.
193
+ Creates `.labkit_logging_todo.yml` with `skip_ci_failure: true`.
166
194
 
167
- ```bash
168
- bundle exec labkit-logging init
169
- ```
170
-
171
- ### labkit-logging fetch
195
+ ### `labkit-logging fetch`
172
196
 
173
197
  Fetches offense logs from a GitLab CI pipeline and updates the todo file.
174
198
 
175
- ```bash
199
+ ```shell
176
200
  bundle exec labkit-logging fetch <project> <pipeline_id>
177
201
  ```
178
202
 
179
- **Arguments:**
180
- - `project` - GitLab project ID or path (e.g., `278964` or `gitlab-org/gitlab`)
181
- - `pipeline_id` - CI pipeline ID number
203
+ - `project` - GitLab project ID or path (for example, `278964` or
204
+ `gitlab-org/gitlab`).
205
+ - `pipeline_id` - CI pipeline ID number.
206
+
207
+ ### Environment variables
182
208
 
183
- **Environment Variables:**
184
- - `GITLAB_TOKEN` - GitLab API token (required)
185
- - `CI_API_V4_URL` - GitLab API URL (default: `https://gitlab.com/api/v4`)
209
+ | Variable | Description |
210
+ |-----------------------------------|-----------------------------------------------------------|
211
+ | `LABKIT_LOGGING_TODO_UPDATE=true` | Update the baseline with new offenses (local development) |
212
+ | `GITLAB_TOKEN` | GitLab API token for `labkit-logging fetch` (required) |
213
+ | `CI_API_V4_URL` | GitLab API URL (default: `https://gitlab.com/api/v4`) |
186
214
 
187
- **Examples:**
215
+ ## Troubleshooting
188
216
 
189
- ```bash
190
- # Using project path
191
- bundle exec labkit-logging fetch gitlab-org/gitlab 12345
217
+ ### New offenses detected
192
218
 
193
- # Using project ID
194
- bundle exec labkit-logging fetch 278964 12345
195
- ```
219
+ The validator raises an error when code introduces a deprecated logging field
220
+ that is not in the baseline.
221
+ This can happen when you:
196
222
 
197
- ## Environment Variables
223
+ - Add a new log call that uses a deprecated field name.
224
+ - Update `labkit-ruby` to a version that deprecates a field your code uses.
198
225
 
199
- | Variable | Description |
200
- |----------|-------------|
201
- | `LABKIT_LOGGING_TODO_UPDATE=true` | Update the baseline with new offenses (local development) |
202
- | `GITLAB_TOKEN` | GitLab API token for fetching CI logs |
203
- | `CI_API_V4_URL` | GitLab API URL (defaults to gitlab.com) |
226
+ To resolve, either [fix the offense](#how-to-fix-an-offense) or
227
+ [add it to the baseline temporarily](#add-an-offense-to-the-baseline-temporarily).
204
228
 
205
- ## Troubleshooting
229
+ ### Offenses not detected
230
+
231
+ - Ensure `.labkit_logging_todo.yml` exists in your project root.
232
+ - Verify you are using `Labkit::Logging::JsonLogger`.
233
+ - Check you are logging with a Hash (not String).
234
+ - Verify the code path is executed during tests.
206
235
 
207
- **"New Offenses Detected" in CI**
208
- - Fix the deprecated fields in your code, or
209
- - Update the baseline locally: `LABKIT_LOGGING_TODO_UPDATE=true bundle exec rspec`
210
- - Commit the updated `.labkit_logging_todo.yml`
236
+ ### Pipeline not found when fetching
211
237
 
212
- **Offenses not detected**
213
- - Ensure `.labkit_logging_todo.yml` exists in your project root
214
- - Verify you're using `Labkit::Logging::JsonLogger`
215
- - Check you're logging with a Hash (not String)
216
- - Verify the code path is executed during tests
238
+ - Verify the project path or ID is correct.
239
+ - Ensure the pipeline has completed (not still running).
240
+ - Check your `GITLAB_TOKEN` has read access to the project.
217
241
 
218
- **Pipeline not found when fetching**
219
- - Verify the project path/ID is correct
220
- - Ensure the pipeline has completed (not still running)
221
- - Check your `GITLAB_TOKEN` has read access to the project
242
+ ### No offenses found in pipeline
222
243
 
223
- **No offenses found in pipeline**
224
- - Ensure `skip_ci_failure: true` was set during the CI run
225
- - Verify the pipeline ran tests that exercise the logging code
226
- - Check job logs are accessible with your token
244
+ - Ensure `skip_ci_failure: true` was set during the CI run.
245
+ - Verify the pipeline ran tests that exercise the logging code.
246
+ - Check job logs are accessible with your token.
227
247
 
228
- ## TODO File Format
248
+ ## TODO file format
229
249
 
230
250
  ```yaml
231
251
  # LabKit Logging Field Standardization TODO
data/lib/labkit/fields.rb CHANGED
@@ -44,6 +44,10 @@ module Labkit
44
44
  # captures the user's username for logging purposes.
45
45
  GL_USER_NAME = "gl_user_name"
46
46
 
47
+ # HTTPStatusCode - an integer field that
48
+ # captures the HTTP status code of requests for logging purposes.
49
+ HTTP_STATUS_CODE = "status"
50
+
47
51
  # New fields being added to this section should have
48
52
  # the appropriate doc comments added above. These
49
53
  # should clearly indicate what the intended use of the
@@ -68,6 +72,7 @@ module Labkit
68
72
 
69
73
  MAPPINGS = {
70
74
  Fields::GL_USER_ID => %w[user_id userid],
75
+ Fields::HTTP_STATUS_CODE => %w[status_code extra.status status_text]
71
76
  }.freeze
72
77
 
73
78
  class << self
@@ -88,26 +88,13 @@ module Labkit
88
88
  # This file tracks deprecated logging fields that need to be migrated to standard fields.
89
89
  # Each offense represents a file using a deprecated field that should be replaced.
90
90
  #
91
- # === HOW TO FIX ===
91
+ # How to fix: https://gitlab.com/gitlab-org/ruby/gems/labkit-ruby/-/blob/master/doc/FIELD_STANDARDIZATION.md#how-to-fix-an-offense
92
92
  #
93
- # 1. Replace the deprecated field with the standard field constant
94
- # 2. Remove the deprecated field entirely (adding the new field is not enough)
95
- # 3. Run your tests - the offense will be automatically removed
93
+ # Adding offenses (if fixing is not immediately possible):
94
+ # LABKIT_LOGGING_TODO_UPDATE=true bundle exec rspec <spec_file>
96
95
  #
97
- # Example:
98
- # # Before
99
- # logger.info(user_id: 123)
100
- #
101
- # # After
102
- # logger.info(Labkit::Fields::GL_USER_ID => 123)
103
- #
104
- # === ADDING OFFENSES (if fixing is not immediately possible) ===
105
- #
106
- # Run: LABKIT_LOGGING_TODO_UPDATE=true bundle exec rspec <spec_file>
107
- #
108
- # === REGENERATE ENTIRE TODO ===
109
- #
110
- # Delete this file and run: LABKIT_LOGGING_TODO_UPDATE=true bundle exec rspec
96
+ # Regenerate entire TODO:
97
+ # Delete this file and run: LABKIT_LOGGING_TODO_UPDATE=true bundle exec rspec
111
98
 
112
99
  HEADER
113
100
  end
@@ -158,7 +158,7 @@ module Labkit
158
158
  lines << ("=" * 80)
159
159
  lines << "Total: #{new_offenses.size} new offense(s) in #{new_offenses.map { |o| o['callsite'] }.uniq.size} file(s)" # rubocop:disable Rails/Pluck
160
160
  lines << ""
161
- lines << "See https://gitlab.com/gitlab-org/ruby/gems/labkit-ruby/-/blob/master/doc/FIELD_STANDARDIZATION.md"
161
+ lines << "See https://gitlab.com/gitlab-org/ruby/gems/labkit-ruby/-/blob/master/doc/FIELD_STANDARDIZATION.md#new-offenses-detected"
162
162
  lines << ("=" * 80)
163
163
  lines << ""
164
164
 
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.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Newdigate
@@ -525,6 +525,7 @@ files:
525
525
  - ".gitlab-ci-asdf-versions.yml"
526
526
  - ".gitlab-ci.yml"
527
527
  - ".gitlab/CODEOWNERS"
528
+ - ".gitlab/merge_request_templates/default.md"
528
529
  - ".gitleaks.toml"
529
530
  - ".mise.toml"
530
531
  - ".pre-commit-config.yaml"