Skip to content

Commit

Permalink
chore: use existing
Browse files Browse the repository at this point in the history
  • Loading branch information
nick134-bit committed Aug 19, 2024
1 parent 6d8538d commit a33fbfa
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions internal/proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ func newServer(name, addr string, cfg config.Config, kind ProxyKind) (*Server, e
cfg: cfg,
successes: ttlslice.New[int](),
failures: ttlslice.New[int](),
healthyThreshold: cfg.HealthyThreshold,
requestTimeout: cfg.ProxyRequestTimeout,
lastHealthCheck: time.Now().UTC(),
healthInterval: cfg.CheckHealthInterval,
healthy: atomic.Bool{},
kind: kind,
}
Expand All @@ -51,9 +48,6 @@ type Server struct {
healthy atomic.Bool

requestCount atomic.Int64
healthInterval time.Duration
healthyThreshold time.Duration
requestTimeout time.Duration
cfg config.Config
successes *ttlslice.Slice[int]
failures *ttlslice.Slice[int]
Expand All @@ -62,7 +56,7 @@ type Server struct {
func (s *Server) Healthy() bool {
now := time.Now().UTC()
//Add different config value if wanted
if now.Sub(s.lastHealthCheck) >= s.healthInterval {
if now.Sub(s.lastHealthCheck) >= s.cfg.CheckHealthInterval {
slog.Info("checking health", "name", s.name)
err := checkEndpoint(s.url.String(), s.kind)
healthy := err == nil
Expand All @@ -76,7 +70,7 @@ func (s *Server) Healthy() bool {
}
}

return s.pings.Last() < s.healthyThreshold && s.healthy.Load()
return s.pings.Last() < s.cfg.HealthyThreshold && s.healthy.Load()
}
func (s *Server) ErrorRate() float64 {
suss := len(s.successes.List())
Expand Down

0 comments on commit a33fbfa

Please sign in to comment.