Skip to content

Commit 67237dd

Browse files
committed
chore: fixup review issues, remove hardcoded sleep
1 parent 12c2f7d commit 67237dd

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

router/cmd/flightrecorder/module/module.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func init() {
2222
type FlightRecorder struct {
2323
OutputPath string `mapstructure:"outputPath"`
2424
RecordMultiple bool `mapstructure:"recordMultiple"`
25-
RequestLatencyRecordThreshold int `mapstructure:"requestLatencyRecordThreshold"`
25+
RequestLatencyRecordThreshold uint64 `mapstructure:"requestLatencyRecordThreshold"`
2626

2727
requestLatencyRecordThresholdDuration time.Duration
2828

@@ -53,11 +53,20 @@ func (m *FlightRecorder) Provision(ctx *core.ModuleContext) error {
5353
return fmt.Errorf("failed to create output directory: %w", err)
5454
}
5555

56-
m.fl = trace.NewFlightRecorder(trace.FlightRecorderConfig{
57-
MinAge: m.requestLatencyRecordThresholdDuration * 2,
56+
// 10MB minimum
57+
var maxBytes uint64 = 10 * 1024 * 1024
58+
59+
// We actually want ~10MB/s of MinAge
60+
// 1000ms = 1 second, 1000 is close enough to 1024
61+
// sub in the uint milliseconds count for one of the factors
62+
// if it would result in a value greater than default maxBytes
63+
if m.RequestLatencyRecordThreshold*2 > 1024 {
64+
maxBytes = (m.RequestLatencyRecordThreshold * 2) * 1024 * 10
65+
}
5866

59-
// 10 MB/s of MinAge
60-
MaxBytes: 10 * 1024 * 1024 * uint64(m.requestLatencyRecordThresholdDuration*2/time.Second),
67+
m.fl = trace.NewFlightRecorder(trace.FlightRecorderConfig{
68+
MinAge: m.requestLatencyRecordThresholdDuration,
69+
MaxBytes: maxBytes,
6170
})
6271

6372
m.fl.Start()
@@ -76,8 +85,6 @@ func (m *FlightRecorder) RouterOnRequest(ctx core.RequestContext, next http.Hand
7685

7786
next.ServeHTTP(ctx.ResponseWriter(), ctx.Request())
7887

79-
time.Sleep(150 * time.Millisecond)
80-
8188
requestDuration := time.Since(start)
8289

8390
if m.fl.Enabled() && requestDuration > m.requestLatencyRecordThresholdDuration {
@@ -92,10 +99,9 @@ func (m *FlightRecorder) RouterOnRequest(ctx core.RequestContext, next http.Hand
9299
func (m *FlightRecorder) RecordTrace(operationName string) {
93100
// Generate timestamped filename
94101
filename := fmt.Sprintf("trace-%s-%s.out", operationName, time.Now().Format("2006-01-02-15-04-05"))
95-
filepath := filepath.Join(m.OutputPath, filename)
96102

97103
// Create the file
98-
file, err := os.Create(filepath)
104+
file, err := os.Create(filepath.Join(m.OutputPath, filename))
99105
if err != nil {
100106
m.Logger.Error("failed to create trace file: %w", zap.Error(err))
101107
return

0 commit comments

Comments
 (0)