-
Notifications
You must be signed in to change notification settings - Fork 341
/
fail_closed.go
79 lines (65 loc) · 1.75 KB
/
fail_closed.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package ratelimit
import (
"github.com/zalando/skipper/filters"
"github.com/zalando/skipper/routing"
)
type failClosedSpec struct{}
type failClosed struct{}
type FailClosedPostProcessor struct{}
func NewFailClosedPostProcessor() *FailClosedPostProcessor {
return &FailClosedPostProcessor{}
}
// Do is implementing a PostProcessor interface to change the filter
// configs at filter processing time. The fail open/closed decision
// needs to be done once and can be processed before we activate the
// new routes.
func (*FailClosedPostProcessor) Do(routes []*routing.Route) []*routing.Route {
for _, r := range routes {
var failClosed bool
for _, f := range r.Filters {
if f.Name == filters.RatelimitFailClosedName {
failClosed = true
break
}
}
// no config changes detected
if !failClosed {
continue
}
for _, f := range r.Filters {
switch f.Name {
// leaky bucket has no Settings
case filters.ClusterLeakyBucketRatelimitName:
lf, ok := f.Filter.(*leakyBucketFilter)
if ok {
lf.failClosed = true
}
case filters.BackendRateLimitName:
bf, ok := f.Filter.(*BackendRatelimit)
if ok {
bf.Settings.FailClosed = true
}
case
filters.ClientRatelimitName,
filters.ClusterClientRatelimitName,
filters.ClusterRatelimitName:
ff, ok := f.Filter.(*filter)
if ok {
ff.settings.FailClosed = true
}
}
}
}
return routes
}
func NewFailClosed() filters.Spec {
return &failClosedSpec{}
}
func (*failClosedSpec) Name() string {
return filters.RatelimitFailClosedName
}
func (*failClosedSpec) CreateFilter([]interface{}) (filters.Filter, error) {
return &failClosed{}, nil
}
func (*failClosed) Request(filters.FilterContext) {}
func (*failClosed) Response(filters.FilterContext) {}