From b073f6c1cbfbdb0455ce1f9a1a1d88e43a3738e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandor=20Sz=C3=BCcs?= Date: Mon, 1 Jul 2024 17:02:12 +0200 Subject: [PATCH] pass default period to define what means skipper to be slow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sandor Szücs --- proxy/proxy.go | 9 ++++++++- skipper.go | 12 ++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/proxy/proxy.go b/proxy/proxy.go index 197bd6d127..965efe5c47 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -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 ( @@ -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 @@ -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, } } @@ -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) } diff --git a/skipper.go b/skipper.go index 1f31b21269..ce473cbc73 100644 --- a/skipper.go +++ b/skipper.go @@ -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) } @@ -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{ @@ -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 {