mirror of
https://forge.darkest.space/hyperhive/hyperhive.git
synced 2026-12-02 13:00:57 +01:00
gateway: answer 503 for a store outage and 429 for the rate limit, and retry both in swarm-logs and swarm-metrics
This commit is contained in:
parent
57b071cc34
commit
790cdd43c8
2 changed files with 709 additions and 125 deletions
|
|
@ -1276,7 +1276,11 @@ let
|
|||
&& lib.all (
|
||||
r:
|
||||
lib.hasInfix "auth_request /__metrics_read_auth;" r.extraConfig
|
||||
&& !(lib.hasInfix "error_page" r.extraConfig)
|
||||
&& !(lib.hasInfix "error_page 401" r.extraConfig)
|
||||
&& lib.hasInfix "limit_req zone=swarm_metrics_agent_auth burst=${toString v.agentAuthBurst} nodelay;" r.extraConfig
|
||||
&& lib.hasInfix "limit_req_status 429;" r.extraConfig
|
||||
&& lib.hasInfix "auth_request_set $swarm_metrics_auth_status $upstream_status;" r.extraConfig
|
||||
&& lib.hasInfix "error_page 500 = @swarm_metrics_auth_failed;" r.extraConfig
|
||||
) (lib.attrValues reads)
|
||||
&& lib.hasInfix "map \$http_authorization \$swarm_metrics_read_auth_target" http
|
||||
&& lib.hasInfix agentArm http
|
||||
|
|
@ -1299,10 +1303,12 @@ let
|
|||
&& lib.hasInfix "--surface metrics" agentUnit.serviceConfig.ExecStart
|
||||
&& lib.hasInfix "--verdict-ttl ${toString v.agentAuthVerdictTtl}" agentUnit.serviceConfig.ExecStart
|
||||
&& agentUnit.serviceConfig.LoadCredential == unit.serviceConfig.LoadCredential
|
||||
&& lib.hasInfix "limit_req_zone $binary_remote_addr zone=swarm_metrics_agent_auth:1m rate=${v.agentAuthRate};" http
|
||||
&&
|
||||
lib.hasInfix "limit_req zone=swarm_metrics_agent_auth burst=${toString v.agentAuthBurst} nodelay;"
|
||||
l."= /__metrics_agent_auth".extraConfig
|
||||
&& lib.hasInfix "limit_req_zone $swarm_metrics_agent_limit_key zone=swarm_metrics_agent_auth:1m rate=${v.agentAuthRate};" http
|
||||
&& lib.hasInfix "\"~^Bearer swarm-agent\\.\" $binary_remote_addr;" http
|
||||
&& !(lib.hasInfix "limit_req" l."= /__metrics_agent_auth".extraConfig)
|
||||
&& lib.hasInfix "if ($swarm_metrics_auth_status = 503) {" l."@swarm_metrics_auth_failed".extraConfig
|
||||
&& lib.hasInfix "return 503;" l."@swarm_metrics_auth_failed".extraConfig
|
||||
&& lib.hasInfix "return 500;" l."@swarm_metrics_auth_failed".extraConfig
|
||||
&& !(lib.hasInfix "limit_req" l."= /__metrics_grafana_auth".extraConfig)
|
||||
&& lib.hasInfix "auth_request /__metrics_authelia;" l."^~ /vmui/".extraConfig
|
||||
&& lib.hasInfix "error_page 401 =302" l."^~ /vmui/".extraConfig
|
||||
|
|
@ -1416,9 +1422,9 @@ let
|
|||
q = v."logs.t.local".locations."^~ /select/logsql/".extraConfig;
|
||||
browser = v."logs.t.local".locations."/".extraConfig;
|
||||
in
|
||||
!(lib.hasInfix "error_page" q)
|
||||
!(lib.hasInfix "error_page 401" q)
|
||||
&& !(lib.hasInfix "auth.t.local" q)
|
||||
&& lib.hasInfix "error_page" browser
|
||||
&& lib.hasInfix "error_page 401" browser
|
||||
&& lib.hasInfix "auth.t.local" browser;
|
||||
}
|
||||
{
|
||||
|
|
@ -1526,9 +1532,11 @@ let
|
|||
}
|
||||
{
|
||||
# Every agent bearer the responder has not recently granted costs a
|
||||
# store login and read, so its location carries the per-address limit.
|
||||
# The responder gets the grant TTL from the option. The query and
|
||||
# authelia locations carry no limit of their own.
|
||||
# store login and read, so the query location limits per address, as a
|
||||
# 429 the caller sees, and only for an agent's bearer. A responder 503
|
||||
# is handed on by the named location. The responder gets the grant TTL
|
||||
# from the option. The agent subrequest and the authelia location carry
|
||||
# no limit of their own.
|
||||
name = "agent bearer checks are rate-limited per address and granted for a TTL";
|
||||
ok =
|
||||
let
|
||||
|
|
@ -1537,12 +1545,20 @@ let
|
|||
unit = allLocal.systemd.services.swarm-logs-auth;
|
||||
v = allLocal.services.hyperhive.deploy.victorialogs;
|
||||
in
|
||||
lib.hasInfix "limit_req_zone $binary_remote_addr zone=swarm_logs_agent_auth:1m rate=${v.authRate};" http
|
||||
lib.hasInfix "limit_req_zone $swarm_logs_agent_limit_key zone=swarm_logs_agent_auth:1m rate=${v.authRate};" http
|
||||
&& lib.hasInfix "\"~^Bearer swarm-agent\\.\" $binary_remote_addr;" http
|
||||
&&
|
||||
lib.hasInfix "limit_req zone=swarm_logs_agent_auth burst=${toString v.authBurst} nodelay;"
|
||||
l."= /__swarm_logs_agent_auth".extraConfig
|
||||
&& lib.hasInfix "limit_req_status 403;" l."= /__swarm_logs_agent_auth".extraConfig
|
||||
&& !(lib.hasInfix "limit_req" l."^~ /select/logsql/".extraConfig)
|
||||
l."^~ /select/logsql/".extraConfig
|
||||
&& lib.hasInfix "limit_req_status 429;" l."^~ /select/logsql/".extraConfig
|
||||
&& !(lib.hasInfix "limit_req" l."= /__swarm_logs_agent_auth".extraConfig)
|
||||
&&
|
||||
lib.hasInfix "auth_request_set $swarm_logs_auth_status $upstream_status;"
|
||||
l."^~ /select/logsql/".extraConfig
|
||||
&& lib.hasInfix "error_page 500 = @swarm_logs_auth_failed;" l."^~ /select/logsql/".extraConfig
|
||||
&& lib.hasInfix "if ($swarm_logs_auth_status = 503) {" l."@swarm_logs_auth_failed".extraConfig
|
||||
&& lib.hasInfix "return 503;" l."@swarm_logs_auth_failed".extraConfig
|
||||
&& lib.hasInfix "return 500;" l."@swarm_logs_auth_failed".extraConfig
|
||||
&& !(lib.hasInfix "limit_req" l."= /__hive_authelia".extraConfig)
|
||||
&& lib.hasInfix "--verdict-ttl 60" unit.serviceConfig.ExecStart;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -507,7 +507,7 @@ let
|
|||
let
|
||||
h = allLocal.services.hyperhive;
|
||||
locs = allLocal.services.nginx.virtualHosts.${h.swarm.victorialogs.domain}.locations;
|
||||
checksOf = l: lib.filter (lib.hasPrefix "auth_request") (lib.splitString "\n" l.extraConfig);
|
||||
checksOf = l: lib.filter (lib.hasPrefix "auth_request /") (lib.splitString "\n" l.extraConfig);
|
||||
in
|
||||
h.deploy.victorialogs.enable
|
||||
&& locs ? "= /metrics"
|
||||
|
|
|
|||
Loading…
Reference in a new issue