Add x-gitaly-cost RPC cost trailer for rate-limiting

During DDoS incidents, Rails and Workhorse have no way to know the cost of a Gitaly RPC. This MR adds a standalone interceptor that sets the x-gitaly-cost gRPC trailer on every RPC response.

Cost = static weight per RPC type + ceil(total_bytes_transferred / 1MiB)

Rails will use the x-gitaly-cost trailer via a gRPC client interceptor and forwards it as an x-gitlab-score-gitaly HTTP response header. Cloudflare uses this for complexity-based rate limiting, accumulating scores per namespace and blocking when the budget is exceeded.

Rails MR to add per-resource cost headers. gitlab!230708 (merged)

Closes #7133

Edited by Divya Rani

Merge request reports

Loading