feat: bound egress check URL references
Some checks are pending
ci / proto (push) Waiting to run
ci / test (ubuntu-latest) (push) Waiting to run
ci / test (windows-latest) (push) Waiting to run
ci / race (push) Waiting to run
ci / integration (push) Waiting to run

This commit is contained in:
youfak 2026-08-02 08:23:58 +08:00
parent ec2ae8838a
commit 1939225f11
4 changed files with 23 additions and 0 deletions

View File

@ -464,6 +464,8 @@ proxyAuth:
- 明确绝对过期时间优先于响应 TTL响应 TTL 优先于配置 `lifecycle.ttl`
- 距离过期不足 `allocationSafetyMargin` 时停止新分配。
- `check.jitter` 为调度抖动百分比,避免所有 Proxy 同时探测。
- `check.urls` 最多 16 个规范化 HTTP/HTTPS URL作为 EGRESS 检查的有界目标集;
BASIC 检查不依赖该字段。
- 第一次有意义失败进入 SUSPECT达到 `maxConsecutiveFailures` 后才进入
UNHEALTHY。

View File

@ -5,6 +5,10 @@ import (
"time"
)
// MaximumCheckURLs bounds per-upstream EGRESS references. The bound keeps
// scheduling and proxy cleanup proportional to a fixed configuration limit.
const MaximumCheckURLs = 16
const (
MaximumPoolSize = 1_000_000
MaximumExactCounter = int64(1<<53 - 1)

View File

@ -1,6 +1,7 @@
package config
import (
"fmt"
"strings"
"testing"
"time"
@ -59,3 +60,16 @@ func TestValidateUsesEffectiveCheckAndRejectsUnsafeURLs(t *testing.T) {
}
}
}
func TestValidateRejectsUnboundedCheckURLReferences(t *testing.T) {
cfg := mustLoadValidConfig(t)
upstream := cfg.Upstreams["provider-a"]
upstream.Check.URLs = make([]string, MaximumCheckURLs+1)
for index := range upstream.Check.URLs {
upstream.Check.URLs[index] = fmt.Sprintf("https://egress-%d.example/check", index)
}
cfg.Upstreams["provider-a"] = upstream
if err := Validate(cfg); err == nil || !strings.Contains(err.Error(), "at most") {
t.Fatalf("Validate(unbounded check URLs) error = %v, want maximum URL error", err)
}
}

View File

@ -588,6 +588,9 @@ func validateCheck(scope string, check Check) error {
if err := requirePositive(scope+".maxConsecutiveFailures", check.MaxConsecutiveFailures); err != nil {
return err
}
if len(check.URLs) > MaximumCheckURLs {
return fmt.Errorf("validate %s.urls: supports at most %d URLs", scope, MaximumCheckURLs)
}
seenURLs := make(map[string]struct{}, len(check.URLs))
for index, rawURL := range check.URLs {
if rawURL == "" || strings.TrimSpace(rawURL) != rawURL {