From 7f027ef0ecade63be16e9730c476fa824926d40f Mon Sep 17 00:00:00 2001 From: Ben Banfield-Zanin Date: Fri, 1 Aug 2025 14:29:50 +0100 Subject: [PATCH] Move the 503 -> 429 mapping into Synapse's frontend rather than HAProxy defaults --- charts/matrix-stack/configs/haproxy/haproxy.cfg.tpl | 12 +----------- .../configs/{haproxy => synapse}/429.http.tpl | 2 +- .../configs/synapse/partial-haproxy.cfg.tpl | 10 ++++++++++ charts/matrix-stack/templates/haproxy/_helpers.tpl | 2 -- charts/matrix-stack/templates/synapse/_helpers.tpl | 2 ++ 5 files changed, 14 insertions(+), 14 deletions(-) rename charts/matrix-stack/configs/{haproxy => synapse}/429.http.tpl (91%) diff --git a/charts/matrix-stack/configs/haproxy/haproxy.cfg.tpl b/charts/matrix-stack/configs/haproxy/haproxy.cfg.tpl index e7a1b71b..dfba3b95 100644 --- a/charts/matrix-stack/configs/haproxy/haproxy.cfg.tpl +++ b/charts/matrix-stack/configs/haproxy/haproxy.cfg.tpl @@ -1,5 +1,5 @@ {{- /* -Copyright 2024 New Vector Ltd +Copyright 2024-2025 New Vector Ltd SPDX-License-Identifier: AGPL-3.0-only */ -}} @@ -66,16 +66,6 @@ defaults compression algo gzip compression type text/plain text/html text/xml application/json text/css - # if we hit the maxconn on a server, and the queue timeout expires, we want - # to avoid returning 503, since that will cause cloudflare to mark us down. - # - # https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#1.3.1 says: - # - # 503 when no server was available to handle the request, or in response to - # monitoring requests which match the "monitor fail" condition - # - errorfile 503 /usr/local/etc/haproxy/429.http - # Use a consistent hashing scheme so that worker with balancing going down doesn't cause # the traffic for all others to be shuffled around. hash-type consistent sdbm diff --git a/charts/matrix-stack/configs/haproxy/429.http.tpl b/charts/matrix-stack/configs/synapse/429.http.tpl similarity index 91% rename from charts/matrix-stack/configs/haproxy/429.http.tpl rename to charts/matrix-stack/configs/synapse/429.http.tpl index cc35845a..aab60797 100644 --- a/charts/matrix-stack/configs/haproxy/429.http.tpl +++ b/charts/matrix-stack/configs/synapse/429.http.tpl @@ -1,5 +1,5 @@ {{- /* -Copyright 2024 New Vector Ltd +Copyright 2024-2025 New Vector Ltd SPDX-License-Identifier: AGPL-3.0-only */ -}} diff --git a/charts/matrix-stack/configs/synapse/partial-haproxy.cfg.tpl b/charts/matrix-stack/configs/synapse/partial-haproxy.cfg.tpl index f8425d57..84662e5d 100644 --- a/charts/matrix-stack/configs/synapse/partial-haproxy.cfg.tpl +++ b/charts/matrix-stack/configs/synapse/partial-haproxy.cfg.tpl @@ -25,6 +25,16 @@ frontend synapse-http-in # same as http log, with %Th (handshake time) log-format "%ci:%cp [%tr] %ft %b/%s %Th/%TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r" + # if we hit the maxconn on a server, and the queue timeout expires, we want + # to avoid returning 503, since that will cause cloudflare to mark us down. + # + # https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#1.3.1 says: + # + # 503 when no server was available to handle the request, or in response to + # monitoring requests which match the "monitor fail" condition + # + errorfile 503 /synapse/429.http + capture request header Host len 32 capture request header Referer len 200 capture request header User-Agent len 200 diff --git a/charts/matrix-stack/templates/haproxy/_helpers.tpl b/charts/matrix-stack/templates/haproxy/_helpers.tpl index 05e74d83..a51f19f9 100644 --- a/charts/matrix-stack/templates/haproxy/_helpers.tpl +++ b/charts/matrix-stack/templates/haproxy/_helpers.tpl @@ -20,8 +20,6 @@ app.kubernetes.io/version: {{ include "element-io.ess-library.labels.makeSafe" . {{- with required "element-io.haproxy.configmap-data missing context" .context -}} haproxy.cfg: | {{- tpl ($root.Files.Get "configs/haproxy/haproxy.cfg.tpl") (dict "root" $root "context" .) | nindent 2 }} -429.http: | -{{- (tpl ($root.Files.Get "configs/haproxy/429.http.tpl") dict) | nindent 2 }} {{- end -}} {{- end -}} diff --git a/charts/matrix-stack/templates/synapse/_helpers.tpl b/charts/matrix-stack/templates/synapse/_helpers.tpl index 75ee9e40..197c9669 100644 --- a/charts/matrix-stack/templates/synapse/_helpers.tpl +++ b/charts/matrix-stack/templates/synapse/_helpers.tpl @@ -223,6 +223,8 @@ redis.conf: | {{- define "element-io.synapse-haproxy.configmap-data" -}} {{- $root := .root -}} +429.http: | +{{- (tpl ($root.Files.Get "configs/haproxy/429.http.tpl") dict) | nindent 2 }} path_map_file: | {{- (tpl ($root.Files.Get "configs/synapse/path_map_file.tpl") (dict "root" $root)) | nindent 2 }} path_map_file_get: |