qa: Update AI development principles from SSOT (20261027)
Summary
This MR updates AI development principles based on recent changes to the development documentation (SSOT). It is one of several team-scoped MRs from this run; the global routing tables (AGENTS.md, SKILL.md) are updated in a separate tooling MR.
Draft until GitLab Duo's review is addressed. GitLab Duo reviews this MR first, and its findings are worked through with the
ai-principles-review-feedbackskill. Human reviewers: please start once this MR is marked ready.
Could the authors listed below review the principles distilled from their SSOT changes?
| Author | SSOT commit(s) |
|---|---|
| @ashs2 | d1a96e9d |
| @fabiopitino | eede73ea, fbaaa497, 1b3331b8, 17a70080 |
| @eread | 88381481, c863a0ed, c9872b0f, 50d914c3, 8ecba73c, 9731762a, fe61c2a1 |
| @lauraXD | 5f205b37 |
Why you were pinged, and why this needs merging
You were pinged because you changed the SSOT documentation these principles are distilled from.
These MRs need to be reviewed and merged, not just reviewed: the
distilled principles only reach the gitlab-coding-principles that
AI agents load once this is merged. An unmerged MR is re-distilled
and reopened on the next weekly run, so the improvement stays
unavailable to agents until someone merges it.
Updated principles and their source-doc changes
code-review
Source files (2)
SSOT diff since previous distillation (f821a52e → 43a26748)
diff --git a/doc/development/code_review.md b/doc/development/code_review.md
index 1248024c28..38d1845d4e 100644
--- a/doc/development/code_review.md
+++ b/doc/development/code_review.md
@@ -32,7 +32,9 @@ to a maintainer. For security assistance, include `@gitlab-com/gl-security/appse
After the reviewer approves, a maintainer reviews and merges. The last required approver merges.
-For CODEOWNERS-required approvals, seek domain-specific approvals before generic ones.
+For CODEOWNERS-required approvals, seek domain-specific approvals before generic ones. The
+exception is database review: request it after the backend reviewer approves. For details, see
+[when to request a database review](database_review.md#when-to-request-a-database-review).
Domain-specific approvers who are also maintainers should review both aspects and approve once.
### Approval guidelinesbackend-architecture
Source files (6)
SSOT diff since previous distillation (829339e2 → 43a26748)
diff --git a/doc/development/application_limits.md b/doc/development/application_limits.md
index 169d5f4131..f7ef9fe9cb 100644
--- a/doc/development/application_limits.md
+++ b/doc/development/application_limits.md
@@ -1,6 +1,6 @@
---
-stage: Tenant Scale
-group: Tenant Services
+stage: Async
+group: Async
info: Any user with at least the Maintainer role can merge updates to this content. For details, see <https://docs.gitlab.com/development/development_processes/#development-guidelines-review>.
title: Application limits development
---
@@ -11,18 +11,26 @@ limits to GitLab.
## Documentation
First of all, you have to gather information and decide which are the different
-limits that are set for the different GitLab tiers. Coordinate with others to [document](../administration/instance_limits.md)
+limits that are set for the different GitLab tiers. Coordinate with others to document
and communicate those limits.
+Add the documentation to the page that matches the limit type:
+
+- [Plan limits and other instance-wide limits](../administration/instance_limits.md).
+- Rate limits that are:
+ - [Configurable in the **Admin** area](../rate_limits/_index.md#admin-area).
+ - [Configurable only with the API or the Rails console](../rate_limits/_index.md#api-and-rails-console).
+ - [Not configurable](../rate_limits/non_configurable.md).
+
There is a guide about [introducing application limits](https://handbook.gitlab.com/handbook/product/product-processes/#introducing-application-limits).
## Implement plan limits
-The `plan_limits` table is **cell-scoped configuration**: each cell has its own
+The `plan_limits` table is cell-scoped configuration: each cell has its own
copy of the table, and limits are not migrated between cells. New cells start
with the column default for each limit, and administrators tune limits per cell
via the [admin Plan Limits API](../api/plan_limits.md). Because of this, every
-new plan limit **must** be settable through that API - otherwise a new limit
+new plan limit must be settable through that API - otherwise a new limit
can only ever take its column default on each cell.
Do not introduce a plan limit that must stay consistent across cells -
@@ -182,52 +190,224 @@ There is an `early_adopter` plan on GitLab.com that has no subscriptions.
The `test` environment doesn't have any plans.
-## Implement rate limits using `Rack::Attack`
+## Choose a rate limiter
+
+GitLab has two rate limiters for application code.
+Both use the [LabKit rate limiting SDK](https://gitlab.com/gitlab-org/ruby/gems/labkit-ruby/-/blob/master/lib/labkit/rate_limit/README.md) and store their counters in the rate limiting Redis instance.
+
+Add a [request rate limit with LabKit](#implement-request-rate-limits-with-labkit) when:
+
+- The limit protects a group of routes from request volume, whatever action each request performs.
+ For example, the packages API, the files API, or Git over HTTP.
+- The limit counts by IP address or by the authenticated requester.
+- The request should be blocked before it reaches a controller or Grape endpoint.
+
+Add a [`Gitlab::ApplicationRateLimiter` key](#implement-rate-limits-using-gitlabapplicationratelimiter) when:
+
+- The limit applies to one action, such as creating an issue or sending an email.
+- The limit counts by a resource, such as a project, group, or namespace, or by a combination of values.
+- The limit counts distinct resources, or the work runs outside a web request, such as in a Sidekiq worker.
+
+If either rate limiter could work, use `Gitlab::ApplicationRateLimiter`.
+Its limit applies only to the action that calls it.
-We use the [`Rack::Attack`](https://github.com/rack/rack-attack) middleware to throttle Rack requests.
-This applies to Rails controllers, Grape endpoints, and any other Rack requests.
+## Implement request rate limits with LabKit
-The process for adding a new throttle is loosely:
+The `Gitlab::Middleware::LabkitRackRateLimit` middleware rate limits Rails controllers,
+Grape endpoints, and any other Rack requests.
+The middleware runs after Warden authenticates the request and before the request reaches the application.
+A request over the limit receives a `429 Too Many Requests` response.
+
+LabKit enforces these rate limits.
+`Rack::Attack` is still in the middleware stack, but it does not throttle requests.
+LabKit reads each limit and period from the throttle definitions in `Gitlab::RackAttack`,
+so new throttles still start there.
+
+To add a request rate limit:
1. Add new fields to the [rate_limits JSONB column](https://gitlab.com/gitlab-org/gitlab/-/blob/63b37287ae028842fcdcf56d311e6bb0c7e09e79/app/models/application_setting.rb#L603)
in the `ApplicationSetting` model.
1. Update the JSON schema validator for the [rate_limits column](https://gitlab.com/gitlab-org/gitlab/-/blob/63b37287ae028842fcdcf56d311e6bb0c7e09e79/app/validators/json_schemas/application_setting_rate_limits.json).
-1. Extend `Gitlab::RackAttack` and `Gitlab::RackAttack::Request` to configure the new rate limit,
- and apply it to the desired requests.
+1. Add a throttle definition, which holds the limit and period:
+ - For a single throttle, add it to `Gitlab::RackAttack.throttle_definitions`,
+ with a matching predicate in `Gitlab::RackAttack::Request`.
+ - For an authenticated and unauthenticated pair, add one entry to `Gitlab::Throttle::REGULAR_THROTTLES`.
+ `Gitlab::RackAttack.regular_throttle_definitions` generates `throttle_unauthenticated_<name>`
+ and `throttle_authenticated_<name>` from it.
+1. Register the throttle in `ThrottleRegistry`. For more information, see [register a throttle](#register-a-throttle).
1. Add the new settings to the **Admin** area form in `app/views/admin/application_settings/_ip_limits.html.haml`.
+1. Optional. To observe the throttle before it blocks requests, name it in the
+ [`GITLAB_THROTTLE_DRY_RUN` environment variable](../administration/settings/user_and_ip_rate_limits.md#try-out-throttling-settings-before-enforcing-them).
+ A throttle in dry run mode builds as a [`:log` rule](https://gitlab.com/gitlab-org/ruby/gems/labkit-ruby/-/blob/master/lib/labkit/rate_limit/README.md#actions) instead of a `:limit` rule,
+ and its claim is named `<rule_name>_dry_run_bypass` instead of `<rule_name>_claim`.
1. Document the new settings in [User and IP rate limits](../administration/settings/user_and_ip_rate_limits.md) and [Application settings API](../api/settings.md).
-1. Configure the rate limit for GitLab.com and document it in [rate limits on GitLab.com](../user/gitlab_com/_index.md#rate-limits-on-gitlabcom).
+1. Configure the rate limit for GitLab.com and document it in [rate limits on GitLab.com](../user/gitlab_com/rate_limits.md).
+
+### Register a throttle
+
+Each throttle maps to one LabKit rule in `Gitlab::RackAttack::LabkitRateLimit::ThrottleRegistry`,
+defined in `lib/gitlab/rack_attack/labkit_rate_limit/throttle_registry.rb` and, for EE throttles, in
+`ee/lib/ee/gitlab/rack_attack/labkit_rate_limit/throttle_registry.rb`.
+A spec fails if a throttle in `Gitlab::RackAttack.all_throttle_definitions` has no registry entry.
+
+Each entry declares:
+
+- `limiter`: The limiter that owns the rule. Use `ThrottleRegistry::GENERAL`, unless the throttle
+ must count requests that a rule in the general limiter also counts.
+ In one limiter, a request is counted by the first rule that claims it, so a throttle that
+ counts the same requests as another rule needs its own limiter.
+ The protected paths and EE incident management throttles have their own limiters for this reason.
+- `characteristics`: What the rule counts by, for example `[:ip]` for an unauthenticated
+ throttle or `[:requester_type, :requester_id]` for an authenticated throttle.
+- `match`: The facts a request must have for the rule to apply.
+- `cohort`: The rollout cohort whose feature flags control enforcement of the rule.
+ Use an existing cohort. A new cohort needs its own feature flag definitions, and
+ `Rack::Attack` throttles requests again until both flags for the new cohort are enabled.
... (diff truncated at 200 lines / 8 KB; use the per-file commit-history links above for the full picture)workers
Source files (6)
SSOT diff since previous distillation (f821a52e → 43a26748)
diff --git a/doc/development/sidekiq/_index.md b/doc/development/sidekiq/_index.md
index 3e75c7ff13..a18c63e6f2 100644
--- a/doc/development/sidekiq/_index.md
+++ b/doc/development/sidekiq/_index.md
@@ -28,6 +28,12 @@ All workers should include `ApplicationWorker` instead of `Sidekiq::Worker`,
which adds some convenience methods and automatically sets the queue based on
the [routing rules](../../administration/sidekiq/processing_specific_job_classes.md#routing-rules).
+## Business logic
+
+Keep business logic out of workers.
+A worker loads records from the job arguments, calls a service, and adds job-specific data to the job log.
+For more information, see [reusing abstractions](../reusing_abstractions.md#worker).
+
## Cells compatibility
GitLab.com is moving to a [Cells architecture](../cells/_index.md), where different organizations
@@ -275,6 +281,26 @@ Sidekiq workers are deferred in two ways:
end
```
+ By default, the middleware evaluates the indicators in
+ `Gitlab::Database::HealthStatus::DEFAULT_INDICATORS`:
+ `AutovacuumActiveOnTable`, `WriteAheadLog`, `PatroniApdex`, and `WalRate`.
+ To evaluate only some indicators, pass an array of indicator classes
+ with the `indicators:` argument.
+ `Gitlab::Database::HealthStatus::GLOBAL_INDICATORS` contains only the database-wide indicators:
+ `WriteAheadLog`, `PatroniApdex`, and `WalRate`.
+ Use it for workers that should not pause while autovacuum runs on their tables.
+ For example, `Projects::TransferWorker` uses it so that autovacuum on the `projects` table
+ does not defer transfers.
+ Only the autovacuum indicator uses `tables`, so `tables` has no effect when that
+ indicator is excluded.
+
+ **Example**:
+
+ ```ruby
+ defer_on_database_health_signal :gitlab_main, [:projects], 1.minute,
+ indicators: Gitlab::Database::HealthStatus::GLOBAL_INDICATORS
+ ```
+
To control when deferral applies, for example to gate deferral behind a feature flag,
the worker can override `defer_on_database_health_signal?`:
testing-rspec
Source files (5)
SSOT diff since previous distillation (0598d6c1 → 43a26748)
diff --git a/doc/development/testing_guide/best_practices.md b/doc/development/testing_guide/best_practices.md
index 3bb8a94a01..970e792888 100644
--- a/doc/development/testing_guide/best_practices.md
+++ b/doc/development/testing_guide/best_practices.md
@@ -2169,8 +2169,8 @@ GitLab.com runs on Elasticsearch 9. The `rspec-ee * es9` jobs run only the specs
- `:elasticsearch_adapter`
A spec without one of these tags runs against Elasticsearch 7 only, in the regular `rspec-ee` jobs.
-If you add a new Elasticsearch metadata tag, add it to `RSPEC_TAGS` and `RSPEC_DRY_RUN_TAGS` in
-`.rspec-ee-base-pg17-es9` in `.gitlab/ci/rails/shared.gitlab-ci.yml`.
+`ee/spec/support/elastic.rb` sets `:es_service` on any spec with one of these tags, and the `es9` jobs select on `:es_service`.
+If you add a new Elasticsearch metadata tag, add it to `ES_SERVICE_TAGS` in `ee/spec/support/elastic.rb`.
Most tests for Elasticsearch logic relate to:
feature-flags
Source files (1)
SSOT diff since previous distillation (f821a52e → 43a26748)
diff --git a/doc/development/feature_flags/_index.md b/doc/development/feature_flags/_index.md
index f0db170af2..8b22454236 100644
--- a/doc/development/feature_flags/_index.md
+++ b/doc/development/feature_flags/_index.md
@@ -34,8 +34,8 @@ Moved to the ["When to use feature flags"](https://handbook.gitlab.com/handbook/
Feature flags are internal implementation details and are not part of the public API contract.
External API consumers (such as IDE extensions, Duo CLI, and CI integrations) that query feature
-flags via the GraphQL [`metadata.featureFlags`](../../api/graphql/reference/_index.md#metadatafeatureflags)
-field or the deprecated [`featureFlagEnabled`](../../api/graphql/reference/_index.md#queryfeatureflagenabled)
+flags via the GraphQL [`metadata.featureFlags`](../../api/graphql/reference/objects.md#metadata)
+field or the deprecated [`featureFlagEnabled`](../../api/graphql/reference/queries.md#featureflagenabled)
field face a specific risk: when a flag is removed from the monolith, external consumers may not
have been updated yet, which can range from a minor UI issue to a customer-impacting incident.
@@ -670,6 +670,9 @@ GitLab supports the following feature flag actors:
- `User` model
- `Project` model
- `Group` model
+- `Namespace` model, including user namespaces
+- `Organizations::Organization` model
+- `Authn::OauthApplication` model
- `Ci::Runner` model
- Current request
@@ -709,6 +712,18 @@ This group can be found by calling `#root_ancestor` on any group or project.
Feature.enabled?(:feature_flag, group.root_ancestor)
```
+#### Namespace actor
+
+Use a `Namespace` actor when the feature applies to any kind of namespace, for example both groups
+and user namespaces. `Group` is a subclass of `Namespace`, so a group is also a valid namespace actor.
+
+```ruby
+Feature.enabled?(:feature_flag, namespace)
+```
+
+To enable the flag for a namespace with ChatOps, use the `--namespace` option.
+See [Process](controls.md#process).
+
#### Mixing actor types
Generally you should use only one type of actor in all invocations of `Feature.enabled?`
@@ -834,9 +849,10 @@ feature for a given feature group via the [`feature_group` parameter of the feat
The available feature groups are:
-| Group name | Scoped to | Description |
-| --------------------- | --------- | ----------- |
-| `gitlab_team_members` | Users | Enables the feature for users who are members of [`gitlab-com`](https://gitlab.com/gitlab-com) |
+| Group name | Scoped to | Description |
+| -------------------------- | --------- | ----------- |
+| `gitlab_team_members` | Users | Enables the feature for users who are members of [`gitlab-com`](https://gitlab.com/gitlab-com) |
+| `friends_of_the_slack_app` | Users | Enables the feature for direct human members of the internal `gitlab-com/ai-engineering/friends-of-the-slack-app` project, the early-access roster for GitLab Duo in Slack |
Feature groups can be enabled via the group name:
How this works
A scheduled CI job detects changes to doc/development/
files listed in .ai/principles/manifest.yml, then
uses the GitLab Duo Agent Platform Workflow API to distill updated
principles for the affected domains.
This MR was generated by https://gitlab.com/gitlab-org/gitlab/-/jobs/17489542895
Please review the checklist changes to ensure they accurately reflect the documentation updates.
Hand-fixes
- 3bcdc985: restore global rate-limit scope syntax, unregistered-key errors, and
RateLimitedServicecharacteristic-to-method mappings; remove the duplicate source footer infeature-flags.md. - Verified against scope and characteristic guidance at the actual
distilled_at_sha. Front matter is unchanged by the hand-fixes. The generated source-diff ranges predate that SHA, tracked in https://gitlab.com/gitlab-org/gitlab/-/issues/635955. - Both principle guards pass, with expected stale-fence warnings. The repeated loss of reviewed fixes is tracked in #631929.