Skip to content

Commit

Permalink
pass default period to define what means skipper to be slow
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 Sep 6, 2024
1 parent 6e7c62a commit b073f6c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 8 additions & 1 deletion proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ type Params struct {
// FlightRecorderTargetURL is the target to write the trace
// to. Supported targets are http URL and file URL.
FlightRecorderTargetURL string

// FlightRecorderPeriod is the time.Duration that is used for
// a slow skipper. If skipper is detected to be slow it tries
// to write out a trace as configured by the FlightRecorderTargetURL.
FlightRecorderPeriod time.Duration
}

type (
Expand Down Expand Up @@ -464,6 +469,7 @@ type Proxy struct {
onPanicSometimes rate.Sometimes
flightRecorder *trace.FlightRecorder
flightRecorderURL *url.URL
flightRecorderPeriod time.Duration
}

// proxyError is used to wrap errors during proxying and to indicate
Expand Down Expand Up @@ -896,6 +902,7 @@ func WithParams(p Params) *Proxy {
onPanicSometimes: rate.Sometimes{First: 3, Interval: 1 * time.Minute},
flightRecorder: p.FlightRecorder,
flightRecorderURL: frURL,
flightRecorderPeriod: p.FlightRecorderPeriod,
}
}

Expand All @@ -904,7 +911,7 @@ func (p *Proxy) writeTraceIfTooSlow(ctx *context) {
return
}

var d time.Duration
d := p.flightRecorderPeriod
if e, ok := ctx.StateBag()[filters.TraceName]; ok {
d = e.(time.Duration)
}
Expand Down
12 changes: 8 additions & 4 deletions skipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2050,18 +2050,20 @@ func run(o Options, sig chan os.Signal, idleConnsCH chan struct{}) error {
routing := routing.New(ro)
defer routing.Close()

frPeriod := defaultFlightRecorderPeriod
var fr *trace.FlightRecorder
if o.FlightRecorderTargetURL != "" {
fr = trace.NewFlightRecorder()

if o.FlightRecorderPeriod != 0 {
fr.SetPeriod(o.FlightRecorderPeriod)
} else {
fr.SetPeriod(defaultFlightRecorderPeriod)
frPeriod = o.FlightRecorderPeriod
}
fr.SetPeriod(frPeriod)

frSize := defaultFlightRecorderSize
if o.FlightRecorderSize != 0 {
fr.SetSize(o.FlightRecorderSize)
frSize = o.FlightRecorderSize
} else {
fr.SetSize(defaultFlightRecorderSize)
}
Expand All @@ -2071,9 +2073,10 @@ func run(o Options, sig chan os.Signal, idleConnsCH chan struct{}) error {
log.Errorf("Failed to start FlightRecorder: %v", err)
fr.Stop()
fr = nil
} else {
log.Infof("FlightRecorder started with config (%s, %d) target: %s", frPeriod, frSize, o.FlightRecorderTargetURL)
}
}
log.Infof("FlightRecorder: %v", fr)

proxyFlags := proxy.Flags(o.ProxyOptions) | o.ProxyFlags
proxyParams := proxy.Params{
Expand Down Expand Up @@ -2105,6 +2108,7 @@ func run(o Options, sig chan os.Signal, idleConnsCH chan struct{}) error {
PassiveHealthCheck: passiveHealthCheck,
FlightRecorder: fr,
FlightRecorderTargetURL: o.FlightRecorderTargetURL,
FlightRecorderPeriod: frPeriod,
}

if o.EnableBreakers || len(o.BreakerSettings) > 0 {
Expand Down

0 comments on commit b073f6c

Please sign in to comment.