mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
A provider whose discovery fails often enough now reads as unhealthy on every pod when redis.sharedState is on. The shared breaker uses the same threshold and open times as the local one. The discovered model sets stay local. With the switch off, the provider state runs its local code only and makes no store call.
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package traefikllmgateway
|
|
|
|
import "time"
|
|
|
|
// wireSharedState layers fleet-wide state over the local trackers. It is a no-op without a shared-state loop.
|
|
func (g *Gateway) wireSharedState(cfg *Config) {
|
|
if g.sharedState == nil {
|
|
return
|
|
}
|
|
ids := sharedStateIDs(cfg)
|
|
if g.failoverHealth != nil {
|
|
g.failoverHealth.share(newSharedBreaker(g.sharedState, sharedKindRequest, ids,
|
|
requestBreakerFailureThreshold, requestBreakerOpenDuration, requestBreakerMaxOpenDuration, 2*requestBreakerMaxOpenDuration))
|
|
}
|
|
if g.concurrency != nil {
|
|
g.concurrency.share(newSharedInflight(g.sharedState, ids, maxProviderTimeout(cfg)))
|
|
}
|
|
if g.registry != nil {
|
|
brk, err := validateBreakerConfig(cfg.Breaker)
|
|
if err != nil {
|
|
brk = breakerConfig{failureThreshold: defaultBreakerFailureThreshold, openBase: defaultBreakerOpenDuration, openMax: defaultBreakerMaxOpenDuration}
|
|
}
|
|
g.registry.shareBreaker(newSharedBreaker(g.sharedState, sharedKindDiscovery, ids,
|
|
brk.failureThreshold, brk.openBase, brk.openMax, 2*brk.openMax))
|
|
}
|
|
}
|
|
|
|
// maxProviderTimeout is the longest request timeout any provider can run, which bounds how long an in-flight count stays live.
|
|
func maxProviderTimeout(cfg *Config) time.Duration {
|
|
global, err := resolveRequestTimeout(cfg.RequestTimeout, "requestTimeout")
|
|
if err != nil {
|
|
global = defaultRequestTimeout
|
|
}
|
|
longest := global
|
|
for name, pc := range cfg.Providers {
|
|
if pc == nil {
|
|
continue
|
|
}
|
|
if d, perr := resolveProviderTimeout(name, pc.RequestTimeout, global); perr == nil && d > longest {
|
|
longest = d
|
|
}
|
|
}
|
|
return longest
|
|
}
|