Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make min-drop-probability of PHC optional #3067

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions docs/operation/operation.md
Original file line number Diff line number Diff line change
Expand Up @@ -907,13 +907,17 @@ in previous period are, the stronger reduction is) amount of requests compared t

Having this, we expect less requests to fail because a lot of them would be sent to endpoints that seem to be healthy instead.

To enable this feature, you need to provide `-passive-health-check` option having all forementioned parameters
(`period`, `min-requests`, `min-drop-probability`, `max-drop-probability`) defined,
for instance: `-passive-health-check=period=1s,min-requests=10,min-drop-probability=0.05,max-drop-probability=0.9`.
To enable this feature, you need to provide `-passive-health-check` option having forementioned parameters
(`period`, `min-requests`, `min-drop-probability`, `max-drop-probability`) defined.
`period`, `min-requests`, `max-drop-probability` are required parameters, it is not possible for PHC to be enabled without
them explicitly defined by user. `min-drop-probability` is implicitly defined as `0.0` if not explicitly set by user.
Valid examples of `-passive-health-check` are:

You need to define all parameters on your side, there are no defaults, and skipper will not run if PHC params are passed only partially.
+ `-passive-health-check=period=1s,min-requests=10,min-drop-probability=0.05,max-drop-probability=0.9`
+ `-passive-health-check=period=1s,min-requests=10,max-drop-probability=0.9`

However, Skipper will run without this feature, if no `-passive-health-check` is provided at all.
If `-passive-health-check` option is provided, but some required parameters are not defined, Skipper will not start.
Skipper will run without this feature, if no `-passive-health-check` is provided at all.

The parameters of `-passive-health-check` option are:

Expand Down
35 changes: 21 additions & 14 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"
"unicode/utf8"

"golang.org/x/exp/maps"
Copy link
Member

@AlexanderYastrebov AlexanderYastrebov May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now in stdlib, see https://pkg.go.dev/maps

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but there is no maps.Keys method on the stdlib page.
image
https://pkg.go.dev/maps

The experimental for comparison.
image
https://pkg.go.dev/golang.org/x/exp/maps

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, indeed golang/go#61538. Thanks for checking

"golang.org/x/time/rate"

ot "github.com/opentracing/opentracing-go"
Expand Down Expand Up @@ -169,10 +170,16 @@ func InitPassiveHealthChecker(o map[string]string) (bool, *PassiveHealthCheck, e
}

result := &PassiveHealthCheck{}
keysInitialized := make(map[string]struct{})
requiredParams := map[string]struct{}{
"period": {},
"max-drop-probability": {},
"min-requests": {},
}

for key, value := range o {
delete(requiredParams, key)
switch key {
/* required parameters */
case "period":
period, err := time.ParseDuration(value)
if err != nil {
Expand All @@ -191,15 +198,6 @@ func InitPassiveHealthChecker(o map[string]string) (bool, *PassiveHealthCheck, e
return false, nil, fmt.Errorf("passive health check: invalid minRequests value: %s", value)
}
result.MinRequests = int64(minRequests)
case "min-drop-probability":
minDropProbability, err := strconv.ParseFloat(value, 64)
if err != nil {
return false, nil, fmt.Errorf("passive health check: invalid minDropProbability value: %s", value)
}
if minDropProbability < 0 || minDropProbability > 1 {
return false, nil, fmt.Errorf("passive health check: invalid minDropProbability value: %s", value)
}
result.MinDropProbability = minDropProbability
case "max-drop-probability":
maxDropProbability, err := strconv.ParseFloat(value, 64)
if err != nil {
Expand All @@ -209,15 +207,24 @@ func InitPassiveHealthChecker(o map[string]string) (bool, *PassiveHealthCheck, e
return false, nil, fmt.Errorf("passive health check: invalid maxDropProbability value: %s", value)
}
result.MaxDropProbability = maxDropProbability

/* optional parameters */
case "min-drop-probability":
minDropProbability, err := strconv.ParseFloat(value, 64)
if err != nil {
return false, nil, fmt.Errorf("passive health check: invalid minDropProbability value: %s", value)
}
if minDropProbability < 0 || minDropProbability > 1 {
return false, nil, fmt.Errorf("passive health check: invalid minDropProbability value: %s", value)
}
result.MinDropProbability = minDropProbability
default:
return false, nil, fmt.Errorf("passive health check: invalid parameter: key=%s,value=%s", key, value)
}

keysInitialized[key] = struct{}{}
}

if len(keysInitialized) != 4 {
return false, nil, fmt.Errorf("passive health check: missing required parameters")
if len(requiredParams) != 0 {
RomanZavodskikh marked this conversation as resolved.
Show resolved Hide resolved
return false, nil, fmt.Errorf("passive health check: missing required parameters %+v", maps.Keys(requiredParams))
}
if result.MinDropProbability >= result.MaxDropProbability {
return false, nil, fmt.Errorf("passive health check: minDropProbability should be less than maxDropProbability")
Expand Down
18 changes: 17 additions & 1 deletion proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2452,7 +2452,23 @@ func TestInitPassiveHealthChecker(t *testing.T) {
},
expectedEnabled: false,
expectedParams: nil,
expectedError: fmt.Errorf("passive health check: missing required parameters"),
expectedError: fmt.Errorf("passive health check: missing required parameters [max-drop-probability]"),
},
{
inputArg: map[string]string{
"period": "1m",
"min-requests": "10",
"max-drop-probability": "0.9",
/* using default max-drop-probability */
},
expectedEnabled: true,
expectedParams: &PassiveHealthCheck{
Period: 1 * time.Minute,
MinRequests: 10,
MaxDropProbability: 0.9,
MinDropProbability: 0.0,
},
expectedError: nil,
},
} {
t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) {
Expand Down
Loading