Skip to content

Commit

Permalink
refactor: move blocks around to make it more reasonable
Browse files Browse the repository at this point in the history
Signed-off-by: Sandor Szücs <sandor.szuecs@zalando.de>
  • Loading branch information
szuecs committed Jul 5, 2022
1 parent ec20ccc commit d704159
Showing 1 changed file with 43 additions and 42 deletions.
85 changes: 43 additions & 42 deletions filters/shedder/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,44 +95,7 @@ type Options struct {
Tracer opentracing.Tracer
}

type AdmissionControlSpec struct {
tracer opentracing.Tracer
}

type admissionControl struct {
once sync.Once
mu sync.Mutex
quit chan struct{}
closed bool

metrics metrics.Metrics
metricSuffix string
tracer opentracing.Tracer

mode mode
windowSize int
minRps int
d time.Duration
successThreshold float64 // (0,1]
maxRejectProbability float64 // (0,1]
exponent float64 // >0

averageRpsFactor float64
totals []int64
success []int64
counter *atomic.Int64
successCounter *atomic.Int64
}

func NewAdmissionControl(o Options) filters.Spec {
tracer := o.Tracer
if tracer == nil {
tracer = &opentracing.NoopTracer{}
}
return &AdmissionControlSpec{
tracer: tracer,
}
}
type admissionControlPre struct{}

// Do removes duplcate filters, because we can only handle one in a
// chain. The last one will override the others.
Expand Down Expand Up @@ -160,6 +123,11 @@ func (spec *admissionControlPre) Do(routes []*eskip.Route) []*eskip.Route {
return routes
}

type admissionControlPost struct {
mu sync.Mutex // required for testing
filters map[string]*admissionControl
}

// Do implements routing.PostProcessor and makes it possible to close goroutines.
func (spec *admissionControlPost) Do(routes []*routing.Route) []*routing.Route {
inUse := make(map[string]struct{})
Expand Down Expand Up @@ -191,10 +159,43 @@ func (spec *admissionControlPost) Do(routes []*routing.Route) []*routing.Route {
return routes
}

type admissionControlPre struct{}
type admissionControlPost struct {
mu sync.Mutex
filters map[string]*admissionControl
type AdmissionControlSpec struct {
tracer opentracing.Tracer
}

type admissionControl struct {
once sync.Once
mu sync.Mutex
quit chan struct{}
closed bool

metrics metrics.Metrics
metricSuffix string
tracer opentracing.Tracer

mode mode
windowSize int
minRps int
d time.Duration
successThreshold float64 // (0,1]
maxRejectProbability float64 // (0,1]
exponent float64 // >0

averageRpsFactor float64
totals []int64
success []int64
counter *atomic.Int64
successCounter *atomic.Int64
}

func NewAdmissionControl(o Options) filters.Spec {
tracer := o.Tracer
if tracer == nil {
tracer = &opentracing.NoopTracer{}
}
return &AdmissionControlSpec{
tracer: tracer,
}
}

func (*AdmissionControlSpec) PreProcessor() *admissionControlPre {
Expand Down

0 comments on commit d704159

Please sign in to comment.