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 f8ffbe8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
4 changes: 2 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,7 @@ 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 %s due to passive health check", e.Host)
} else {
filtered = append(filtered, e)
}
Expand Down
2 changes: 1 addition & 1 deletion 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
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 %s as unhealthy due to failed round trips ratio: %f", 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 f8ffbe8

Please sign in to comment.