Skip to content

Commit

Permalink
Added PHC-related logs
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Zavodskikh <[email protected]>
  • Loading branch information
Roman Zavodskikh committed Apr 22, 2024
1 parent 2330b75 commit 17f2584
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
5 changes: 3 additions & 2 deletions proxy/healthy_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type healthyEndpoints struct {
endpointRegistry *routing.EndpointRegistry
}

func (h *healthyEndpoints) filterHealthyEndpoints(endpoints []routing.LBEndpoint, rt *routing.Route) []routing.LBEndpoint {
func (h *healthyEndpoints) filterHealthyEndpoints(ctx *context, endpoints []routing.LBEndpoint) []routing.LBEndpoint {
if h == nil {
return endpoints
}
Expand All @@ -21,7 +21,8 @@ func (h *healthyEndpoints) filterHealthyEndpoints(endpoints []routing.LBEndpoint
filtered := make([]routing.LBEndpoint, 0, len(endpoints))
for _, e := range endpoints {
if p < e.Metrics.HealthCheckDropProbability() {
/* drop */
ctx.Logger().Infof("dropping endpoint %q due to passive health check: p=%0.2f, dropProbability=%0.2f",
e.Host, p, e.Metrics.HealthCheckDropProbability())
} else {
filtered = append(filtered, e)
}
Expand Down
7 changes: 4 additions & 3 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ func (p *Proxy) selectEndpoint(ctx *context) *routing.LBEndpoint {
rt := ctx.route
endpoints := rt.LBEndpoints
endpoints = p.fadein.filterFadeIn(endpoints, rt)
endpoints = p.heathlyEndpoints.filterHealthyEndpoints(endpoints, rt)
endpoints = p.heathlyEndpoints.filterHealthyEndpoints(ctx, endpoints)

lbctx := &routing.LBContext{
Request: ctx.request,
Expand Down Expand Up @@ -791,8 +791,9 @@ func WithParams(p Params) *Proxy {
defaultHTTPStatus = p.DefaultHTTPStatus
}

logger := &logging.DefaultLog{}
if p.EndpointRegistry == nil {
p.EndpointRegistry = routing.NewEndpointRegistry(routing.RegistryOptions{})
p.EndpointRegistry = routing.NewEndpointRegistry(routing.RegistryOptions{Logger: logger})
}

hostname := os.Getenv("HOSTNAME")
Expand Down Expand Up @@ -823,7 +824,7 @@ func WithParams(p Params) *Proxy {
maxLoops: p.MaxLoopbacks,
breakers: p.CircuitBreakers,
limiters: p.RateLimiters,
log: &logging.DefaultLog{},
log: logger,
defaultHTTPStatus: defaultHTTPStatus,
tracing: newProxyTracing(p.OpenTracing),
accessLogDisabled: p.AccessLogDisabled,
Expand Down
19 changes: 15 additions & 4 deletions routing/endpointregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/logging"
)

const defaultLastSeenTimeout = 1 * time.Minute
Expand Down Expand Up @@ -100,8 +101,9 @@ type EndpointRegistry struct {

quit chan struct{}

now func() time.Time
data sync.Map // map[string]*entry
now func() time.Time
data sync.Map // map[string]*entry
logger logging.Logger
}

var _ PostProcessor = &EndpointRegistry{}
Expand All @@ -112,6 +114,7 @@ type RegistryOptions struct {
StatsResetPeriod time.Duration
MinRequests int64
MaxHealthCheckDropProbability float64
Logger logging.Logger
}

func (r *EndpointRegistry) Do(routes []*Route) []*Route {
Expand Down Expand Up @@ -166,6 +169,9 @@ func (r *EndpointRegistry) updateStats() {
requests := e.totalRequests[curSlot].Load()
if requests > r.minRequests {
failedRoundTripsRatio := float64(failed) / float64(requests)
if failedRoundTripsRatio > 0 {
r.logger.Infof("passive health check: marking %q as unhealthy due to failed round trips ratio: %0.2f", key, failedRoundTripsRatio)
}
e.healthCheckDropProbability.Store(min(failedRoundTripsRatio, r.maxHealthCheckDropProbability))
} else {
e.healthCheckDropProbability.Store(0.0)
Expand All @@ -192,6 +198,10 @@ func NewEndpointRegistry(o RegistryOptions) *EndpointRegistry {
o.LastSeenTimeout = defaultLastSeenTimeout
}

if o.Logger == nil {
o.Logger = &logging.DefaultLog{}
}

registry := &EndpointRegistry{
lastSeenTimeout: o.LastSeenTimeout,
statsResetPeriod: o.StatsResetPeriod,
Expand All @@ -200,8 +210,9 @@ func NewEndpointRegistry(o RegistryOptions) *EndpointRegistry {

quit: make(chan struct{}),

now: time.Now,
data: sync.Map{},
now: time.Now,
data: sync.Map{},
logger: o.Logger,
}
if o.PassiveHealthCheckEnabled {
go registry.updateStats()
Expand Down

0 comments on commit 17f2584

Please sign in to comment.