mirror of
https://forge.darkest.space/hyperhive/hyperhive.git
synced 2026-12-03 13:31:02 +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
|
|
@ -257,7 +257,7 @@ in
|
|||
so every agent on one host shares one budget. The default covers about a
|
||||
hundred agents on a host cold-starting at once, each costing one store
|
||||
login and read for its first query. Requests over the rate and its burst
|
||||
are answered 403.
|
||||
are answered 429.
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
@ -267,7 +267,7 @@ in
|
|||
description = ''
|
||||
Requests a client address may make above
|
||||
{option}`services.hyperhive.deploy.victorialogs.authRate` before nginx
|
||||
answers 403, served without delay.
|
||||
answers 429, served without delay.
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
@ -331,7 +331,11 @@ in
|
|||
"~^Bearer [0-9a-f]{64}$" /__swarm_logs_grafana_auth;
|
||||
default /__hive_authelia;
|
||||
}
|
||||
limit_req_zone $binary_remote_addr zone=swarm_logs_agent_auth:1m rate=${deployCfg.victorialogs.authRate};
|
||||
map $http_authorization $swarm_logs_agent_limit_key {
|
||||
"~^Bearer swarm-agent\." $binary_remote_addr;
|
||||
default "";
|
||||
}
|
||||
limit_req_zone $swarm_logs_agent_limit_key zone=swarm_logs_agent_auth:1m rate=${deployCfg.victorialogs.authRate};
|
||||
map $http_authorization $swarm_logs_ingest_nocache {
|
||||
"" 1;
|
||||
default 0;
|
||||
|
|
@ -420,12 +424,36 @@ in
|
|||
# Three checks: an agent's own `swarm-agent.` bearer goes to
|
||||
# `swarm-logs-auth`, Grafana's 64-hex bearer to `swarm-metrics-auth`,
|
||||
# anything else to authelia (`appendHttpConfig` above picks).
|
||||
#
|
||||
# The agents' rate limit and the 503 hand-on are set on this location;
|
||||
# see `@swarm_logs_auth_failed` below.
|
||||
"^~ /select/logsql/" = {
|
||||
# No URI part, so the request path and its query string reach
|
||||
# the store as the caller sent them.
|
||||
proxyPass = upstream;
|
||||
extraConfig = ''
|
||||
limit_req zone=swarm_logs_agent_auth burst=${toString deployCfg.victorialogs.authBurst} nodelay;
|
||||
limit_req_status 429;
|
||||
auth_request /__swarm_logs_auth;
|
||||
auth_request_set $swarm_logs_auth_status $upstream_status;
|
||||
error_page 500 = @swarm_logs_auth_failed;
|
||||
'';
|
||||
};
|
||||
|
||||
# Where a failed `auth_request` lands: the 503 the responder answered
|
||||
# when its store could not, and a 500 for any other status.
|
||||
# `auth_request` turns every subrequest status but 2xx, 401 and 403
|
||||
# into a 500, so this is how a 503 reaches the caller. For the same
|
||||
# reason the rate limit is on the query location and not in the agent
|
||||
# subrequest: there a 429 would become a 500. `limit_req` runs before
|
||||
# `auth_request` and skips a request whose key is empty, which
|
||||
# `swarm_logs_agent_limit_key` makes of every non-agent request.
|
||||
"@swarm_logs_auth_failed" = {
|
||||
extraConfig = ''
|
||||
if ($swarm_logs_auth_status = 503) {
|
||||
return 503;
|
||||
}
|
||||
return 500;
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
@ -458,16 +486,12 @@ in
|
|||
# The `Authorization` header rides the subrequest unchanged.
|
||||
#
|
||||
# Any well-formed agent bearer the responder has not recently granted
|
||||
# costs a secret store login and read, so the rate per client address
|
||||
# is capped here, ahead of the responder. 403 when over: the only
|
||||
# statuses `auth_request` passes through are 401 and 403, and
|
||||
# `swarm-logs` retries a 401.
|
||||
# costs a secret store login and read; the rate per client address is
|
||||
# capped on the query location, ahead of this subrequest.
|
||||
"= /__swarm_logs_agent_auth" = {
|
||||
proxyPass = "http://unix:${logsAuthSocket}:/";
|
||||
extraConfig = ''
|
||||
internal;
|
||||
limit_req zone=swarm_logs_agent_auth burst=${toString deployCfg.victorialogs.authBurst} nodelay;
|
||||
limit_req_status 403;
|
||||
proxy_pass_request_body off;
|
||||
proxy_set_header Content-Length "";
|
||||
'';
|
||||
|
|
|
|||
|
|
@ -96,8 +96,20 @@ let
|
|||
# `error_page 401 =302` follows it and reads authelia's login page as a 200
|
||||
# holding no series. `/__metrics_read_auth` picks the check from the
|
||||
# caller's `Authorization` (`appendHttpConfig` below).
|
||||
#
|
||||
# The agents' rate limit is here and not in the agent subrequest:
|
||||
# `auth_request` turns any subrequest status but 2xx, 401 and 403 into a 500,
|
||||
# so a limit hit there could not reach the caller as a 429. `limit_req` runs
|
||||
# before `auth_request` and does not count a request whose key is empty,
|
||||
# which `swarm_metrics_agent_limit_key` makes of every request that is not
|
||||
# an agent's. A responder answering 503 (its store cannot answer) is the one
|
||||
# other subrequest status handed on, by `@swarm_metrics_auth_failed`.
|
||||
readAuth = ''
|
||||
limit_req zone=swarm_metrics_agent_auth burst=${toString deployCfg.victoriametrics.agentAuthBurst} nodelay;
|
||||
limit_req_status 429;
|
||||
auth_request /__metrics_read_auth;
|
||||
auth_request_set $swarm_metrics_auth_status $upstream_status;
|
||||
error_page 500 = @swarm_metrics_auth_failed;
|
||||
'';
|
||||
readLocations =
|
||||
let
|
||||
|
|
@ -336,7 +348,7 @@ in
|
|||
costs a secret store login and read, whether the bearer is right or not.
|
||||
|
||||
Keyed by client address, so every agent on one host shares one budget.
|
||||
Requests over the rate and its burst are answered 403.
|
||||
Requests over the rate and its burst are answered 429.
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
@ -346,7 +358,7 @@ in
|
|||
description = ''
|
||||
Requests a client address may make above
|
||||
{option}`services.hyperhive.deploy.victoriametrics.agentAuthRate` before
|
||||
nginx answers 403, served without delay.
|
||||
nginx answers 429, served without delay.
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
@ -418,7 +430,11 @@ in
|
|||
"~^Bearer " /__metrics_grafana_auth;
|
||||
default /__metrics_authelia;
|
||||
}
|
||||
limit_req_zone $binary_remote_addr zone=swarm_metrics_agent_auth:1m rate=${deployCfg.victoriametrics.agentAuthRate};
|
||||
map $http_authorization $swarm_metrics_agent_limit_key {
|
||||
"~^Bearer swarm-agent\." $binary_remote_addr;
|
||||
default "";
|
||||
}
|
||||
limit_req_zone $swarm_metrics_agent_limit_key zone=swarm_metrics_agent_auth:1m rate=${deployCfg.victoriametrics.agentAuthRate};
|
||||
map $http_authorization $swarm_metrics_ingest_nocache {
|
||||
"" 1;
|
||||
default 0;
|
||||
|
|
@ -449,6 +465,16 @@ in
|
|||
# its queries, and authenticates none of them.
|
||||
"/".return = "403";
|
||||
|
||||
# Where a failed read-location `auth_request` lands: the 503 the
|
||||
# responder answered when its store could not, and a 500 for any
|
||||
# other status.
|
||||
"@swarm_metrics_auth_failed".extraConfig = ''
|
||||
if ($swarm_metrics_auth_status = 503) {
|
||||
return 503;
|
||||
}
|
||||
return 500;
|
||||
'';
|
||||
|
||||
# The swarm UI's quick link opens the bare domain. The store's own
|
||||
# index page links mostly to paths refused above, so send it to vmui.
|
||||
"= /".return = "302 /vmui/";
|
||||
|
|
@ -508,14 +534,11 @@ in
|
|||
# An agent's bearer, checked by `swarm-metrics-agent-auth`. Any
|
||||
# well-formed agent bearer the responder has not recently granted
|
||||
# costs a store login and read, so the rate per client address is
|
||||
# capped here. 403 when over: `auth_request` passes only 401 and 403
|
||||
# through, and `swarm-metrics` retries a 401.
|
||||
# capped on the read locations (`readAuth`), ahead of this subrequest.
|
||||
"= /__metrics_agent_auth" = {
|
||||
proxyPass = "http://unix:${agentAuthSocket}:/";
|
||||
extraConfig = ''
|
||||
internal;
|
||||
limit_req zone=swarm_metrics_agent_auth burst=${toString deployCfg.victoriametrics.agentAuthBurst} nodelay;
|
||||
limit_req_status 403;
|
||||
proxy_pass_request_body off;
|
||||
proxy_set_header Content-Length "";
|
||||
'';
|
||||
|
|
|
|||
Loading…
Reference in a new issue