gitlab-labkit 5.0.1 → 5.1.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/.gitlab-ci.yml +56 -3
- data/.pre-commit-config.yaml +1 -1
- data/README.md +21 -0
- data/lib/labkit/rate_limit/README.md +1 -0
- data/lib/labkit/rate_limit/metrics.rb +10 -0
- 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: 517717fb252b6eecaa4ff8d584d51d2318c0ad2334937626d27c983c8008b82d
|
|
4
|
+
data.tar.gz: 72c7a73c0a08c7bdef92e0889123c6f96785a70f79cb01b9b83eb482acc3481c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dadc324d442f4a13bf2c3bf3e93797ecf8f4ebc44342ffc2dd7c88b415f59513e9ad558470d4bc085c1afe6979ee8f3bd23e8151f8fef02423509b07c40dc73b
|
|
7
|
+
data.tar.gz: f99e0cb9a2a2fd65dd2e63533987a6f349bd320b24441756c530079e672402400e4be7a3d9b7182d8f0ea4bc09b47e148d07a1ebfa6e84cfaf1f4e5fd803babf
|
data/.gitlab-ci.yml
CHANGED
|
@@ -19,13 +19,13 @@ include:
|
|
|
19
19
|
# It includes standard checks, gitlab-scanners, validations and release processes
|
|
20
20
|
# common to all projects using this template library.
|
|
21
21
|
# see https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks/-/blob/main/templates/standard.md
|
|
22
|
-
- component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/standard-build@
|
|
22
|
+
- component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/standard-build@v5.15
|
|
23
23
|
|
|
24
24
|
# Runs rspec tests and rubocop on the project
|
|
25
25
|
# see https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks/-/blob/main/templates/ruby.md
|
|
26
|
-
- component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/ruby-build@
|
|
26
|
+
- component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/ruby-build@v5.15
|
|
27
27
|
|
|
28
|
-
- component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/danger@
|
|
28
|
+
- component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/danger@v5.15
|
|
29
29
|
|
|
30
30
|
# Attach a redis service to the rspec job from common-ci-tasks/ruby-build.
|
|
31
31
|
# GitLab merges keys when a local job has the same name as an included one,
|
|
@@ -59,3 +59,56 @@ deploy:
|
|
|
59
59
|
stage: release
|
|
60
60
|
script:
|
|
61
61
|
- tools/deploy-rubygem.sh
|
|
62
|
+
|
|
63
|
+
.conformance-trigger-paths:
|
|
64
|
+
changes:
|
|
65
|
+
- lib/**/*
|
|
66
|
+
- gitlab-labkit.gemspec
|
|
67
|
+
- Gemfile
|
|
68
|
+
- .gitlab-ci.yml
|
|
69
|
+
|
|
70
|
+
# Run the labkit-spec conformance harness with its Ruby server built from this
|
|
71
|
+
# checkout. labkit-spec pins released SDKs, so this is the only pre-merge check
|
|
72
|
+
# against the spec.
|
|
73
|
+
conformance:
|
|
74
|
+
stage: validate
|
|
75
|
+
image:
|
|
76
|
+
name: jdxcode/mise:2026.8.14
|
|
77
|
+
entrypoint: [""]
|
|
78
|
+
needs: []
|
|
79
|
+
services:
|
|
80
|
+
- name: redis:8-alpine
|
|
81
|
+
alias: redis
|
|
82
|
+
rules:
|
|
83
|
+
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
|
84
|
+
- if: $CI_COMMIT_BRANCH
|
|
85
|
+
changes: !reference [.conformance-trigger-paths, changes]
|
|
86
|
+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
87
|
+
changes: !reference [.conformance-trigger-paths, changes]
|
|
88
|
+
variables:
|
|
89
|
+
LABKIT_SPEC_REPO: https://gitlab.com/gitlab-org/quality/tooling/labkit-spec.git
|
|
90
|
+
LABKIT_SPEC_REF: main
|
|
91
|
+
LABKIT_SPEC_DIR: $CI_PROJECT_DIR/.labkit-spec
|
|
92
|
+
MISE_TRUSTED_CONFIG_PATHS: $LABKIT_SPEC_DIR
|
|
93
|
+
MISE_DATA_DIR: $CI_PROJECT_DIR/.mise-cache
|
|
94
|
+
BUNDLE_PATH: vendor/bundle
|
|
95
|
+
CONFORMANCE_REDIS_ADDR: redis:6379
|
|
96
|
+
cache:
|
|
97
|
+
key: conformance-servers
|
|
98
|
+
paths:
|
|
99
|
+
- .labkit-spec/conformance/servers/ruby/vendor/
|
|
100
|
+
- .mise-cache/
|
|
101
|
+
script:
|
|
102
|
+
# Not clone: the restored cache makes LABKIT_SPEC_DIR non-empty.
|
|
103
|
+
- git init -q "$LABKIT_SPEC_DIR"
|
|
104
|
+
- git -C "$LABKIT_SPEC_DIR" fetch -q --depth 1 "$LABKIT_SPEC_REPO" "$LABKIT_SPEC_REF"
|
|
105
|
+
- git -C "$LABKIT_SPEC_DIR" checkout -q FETCH_HEAD
|
|
106
|
+
- cd "$LABKIT_SPEC_DIR"
|
|
107
|
+
- mise install
|
|
108
|
+
# The gemspec lists files via `git ls-files`, so the path must be a git work tree.
|
|
109
|
+
# grep fails the job if the Gemfile line moved and sed matched nothing.
|
|
110
|
+
- |
|
|
111
|
+
sed -i 's|^gem "gitlab-labkit".*|gem "gitlab-labkit", path: "'"$CI_PROJECT_DIR"'"|' conformance/servers/ruby/Gemfile
|
|
112
|
+
grep -q 'gem "gitlab-labkit", path: "'"$CI_PROJECT_DIR"'"' conformance/servers/ruby/Gemfile
|
|
113
|
+
- mise run conformance:ruby
|
|
114
|
+
timeout: 15m
|
data/.pre-commit-config.yaml
CHANGED
|
@@ -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:
|
|
28
|
+
rev: v5.15 # renovate:managed
|
|
29
29
|
|
|
30
30
|
hooks:
|
|
31
31
|
- id: shellcheck # Run shellcheck for changed Shell files
|
data/README.md
CHANGED
|
@@ -55,6 +55,27 @@ To opt out of autostart (e.g. you've started Redis some other way), set
|
|
|
55
55
|
`LABKIT_TEST_REDIS_URL` to a reachable instance, or
|
|
56
56
|
`LABKIT_TEST_REDIS_NO_AUTOSTART=1` to fail loudly instead of spawning.
|
|
57
57
|
|
|
58
|
+
The `conformance` CI job runs the
|
|
59
|
+
[labkit-spec](https://gitlab.com/gitlab-org/quality/tooling/labkit-spec)
|
|
60
|
+
conformance harness against the spec's Ruby server, with the `gitlab-labkit`
|
|
61
|
+
gem installed from your branch instead of the released version. A change to
|
|
62
|
+
logging, lifecycle, or rate limiting is therefore checked against the
|
|
63
|
+
cross-SDK scenarios before it merges. To run it locally, clone labkit-spec and
|
|
64
|
+
replace the `gitlab-labkit` line in `conformance/servers/ruby/Gemfile` with
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
gem "gitlab-labkit", path: "/path/to/labkit-ruby"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
then run `mise run conformance:ruby` from the spec checkout (the rate-limit
|
|
71
|
+
aspect needs Docker or `CONFORMANCE_REDIS_ADDR`).
|
|
72
|
+
|
|
73
|
+
If your change also needs a labkit-spec change (a new scenario, or an update
|
|
74
|
+
to its Ruby server), open that MR first and point `LABKIT_SPEC_REF` in
|
|
75
|
+
`.gitlab-ci.yml` at its branch so this job validates both together. Set it
|
|
76
|
+
back to `main` once the spec MR merges; a non-`main` ref must not reach
|
|
77
|
+
`master`.
|
|
78
|
+
|
|
58
79
|
Please also review the [development section of the LabKit (go) README](https://gitlab.com/gitlab-org/labkit#developing-labkit) for details of the LabKit architectural philosophy.
|
|
59
80
|
|
|
60
81
|
To work on some of the scripts we use for releasing a new version,
|
|
@@ -514,6 +514,7 @@ flooding).
|
|
|
514
514
|
| `gitlab_labkit_rate_limiter_checks_total` | counter | `rate_limiter`, `action`, `matched`, `error` | Exactly one increment per `check` call, including fail-open. `action` is what the caller should do (`"allow"` or `"block"`); `matched` and `error` are `"true"`/`"false"`. |
|
|
515
515
|
| `gitlab_labkit_rate_limiter_rule_evaluations_total` | counter | `rate_limiter`, `rule`, `action`, `result` | One increment per evaluated rule (plus one per matched `:skip` rule). `action` is the configured rule action (`"limit"`, `"log"`, `"skip"`); `result` is what the evaluation decided (`"allow"`, `"block"`, `"log"`, `"skip"`, `"banned"` — see the Actions table). |
|
|
516
516
|
| `gitlab_labkit_rate_limiter_peeks_total` | counter | `rate_limiter`, `error` | Exactly one increment per `peek` call, including fail-open. `error` is `"true"`/`"false"`. |
|
|
517
|
+
| `gitlab_labkit_rate_limiter_enforced_total` | counter | `rate_limiter`, `rule` | One increment per request the caller rejected on a `:block`. Emitted by the caller, not the evaluator: a rollout gate may observe a block without enforcing it. |
|
|
517
518
|
| `gitlab_labkit_rate_limiter_limit` | gauge | `rate_limiter`, `rule` | Resolved limit at the last check (useful when `limit:` is callable). |
|
|
518
519
|
| `gitlab_labkit_rate_limiter_period_seconds` | gauge | `rate_limiter`, `rule` | Resolved period at the last check. |
|
|
519
520
|
|
|
@@ -71,6 +71,16 @@ module Labkit
|
|
|
71
71
|
)
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
+
# Emitted by the caller, once per rejected request: only the caller knows
|
|
75
|
+
# whether it acted on a :block (a rollout gate may observe without enforcing).
|
|
76
|
+
def enforced_total
|
|
77
|
+
Labkit::Metrics::Client.counter(
|
|
78
|
+
:gitlab_labkit_rate_limiter_enforced_total,
|
|
79
|
+
'Total number of requests rejected on a rate limit block',
|
|
80
|
+
{ rate_limiter: nil, rule: nil }
|
|
81
|
+
)
|
|
82
|
+
end
|
|
83
|
+
|
|
74
84
|
def limit_gauge
|
|
75
85
|
Labkit::Metrics::Client.gauge(
|
|
76
86
|
:gitlab_labkit_rate_limiter_limit,
|