Skip to content

Commit

Permalink
debugmode: reduce the data we collect
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander committed Oct 25, 2024
1 parent f5e0d14 commit ee4c1e7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion api/pkg/filtermanager/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ func NewFilterWrapper(name string, f api.Filter) *FilterWrapper {

type ExecutionRecord struct {
PluginName string
Record map[string]time.Duration
Record time.Duration
}
4 changes: 2 additions & 2 deletions api/pkg/filtermanager/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ func (f *debugFilter) recordExecution(start time.Time, method string) {
}
for _, record := range records {
if record.PluginName == f.name {
record.Record[method] += duration
record.Record += duration
return
}
}
f.callbacks.PluginState().Set("debugMode", "executionRecords", append(records, model.ExecutionRecord{
PluginName: f.name,
Record: map[string]time.Duration{method: duration},
Record: duration,
}))
}

Expand Down
7 changes: 4 additions & 3 deletions api/pkg/filtermanager/wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ func TestDebugFilter(t *testing.T) {
t.Logf("get records %+v\n", records) // for debug when test failed
assert.Equal(t, 2, len(records))
assert.Equal(t, "two", records[0].PluginName)
assert.True(t, records[0].Record["DecodeHeaders"] > 0)
assert.True(t, records[0].Record > 0)
assert.Equal(t, "one", records[1].PluginName)
assert.True(t, records[1].Record["DecodeHeaders"] > 0)
assert.True(t, records[1].Record > 0)
decodeHeadersCost := records[1].Record

patches := gomonkey.ApplyMethodFunc(raw1, "DecodeData", func(data api.BufferInstance, endStream bool) api.ResultAction {
time.Sleep(100 * time.Millisecond)
Expand All @@ -58,6 +59,6 @@ func TestDebugFilter(t *testing.T) {
assert.Equal(t, "one", records[1].PluginName)
// Should be the sum of multiple calls
delta := 10 * time.Millisecond
rec := records[1].Record["DecodeData"]
rec := records[1].Record - decodeHeadersCost
assert.True(t, 200*time.Millisecond-delta < rec && rec < 200*time.Millisecond+delta, rec)
}
11 changes: 4 additions & 7 deletions plugins/plugins/debugmode/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type filter struct {
}

type executionPlugin struct {
Name string `json:"name"`
PerPhaseCostSeconds map[string]float64 `json:"per_phase_cost_seconds"`
Name string `json:"name"`
CostSeconds float64 `json:"cost_seconds"`
}

type SlowLogReport struct {
Expand Down Expand Up @@ -107,11 +107,8 @@ func (f *filter) OnLog(reqHeaders api.RequestHeaderMap, reqTrailers api.RequestT
executionRecords := r.([]model.ExecutionRecord)
for _, record := range executionRecords {
p := executionPlugin{
Name: record.PluginName,
}
p.PerPhaseCostSeconds = make(map[string]float64)
for k, v := range record.Record {
p.PerPhaseCostSeconds[k] = v.Seconds()
Name: record.PluginName,
CostSeconds: record.Record.Seconds(),
}
report.ExecutedPlugins = append(report.ExecutedPlugins, p)
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/tests/integration/debug_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestDebugModeSlowLog(t *testing.T) {
dp, err := dataplane.StartDataPlane(t, &dataplane.Option{
NoErrorLogCheck: true,
ExpectLogPattern: []string{
`slow log report:.+"executed_plugins":\[.+"name":"limitReq","per_phase_cost_seconds":\{"DecodeHeaders":.+`,
`slow log report:.+"executed_plugins":\[.+"name":"limitReq","cost_seconds":.+`,
},
})
if err != nil {
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestDebugModeSlowLogNoPlugin(t *testing.T) {
dp, err := dataplane.StartDataPlane(t, &dataplane.Option{
NoErrorLogCheck: true,
ExpectNoLogPattern: []string{
`slow log report:.+"executed_plugins":\[.+"name":"limitReq","per_phase_cost_seconds":\{"DecodeHeaders":.+`,
`slow log report:.+"executed_plugins":\[.+"name":"limitReq","cost_seconds":.+`,
},
ExpectLogPattern: []string{
`slow log report:.+"server":\["envoy"\]`,
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestDebugModeSlowLogWithFiltersFromConsumer(t *testing.T) {
LogLevel: "debug",
NoErrorLogCheck: true,
ExpectLogPattern: []string{
`slow log report:.+"executed_plugins":\[.+"name":"limitReq","per_phase_cost_seconds":\{"DecodeHeaders":.+`,
`slow log report:.+"executed_plugins":\[.+"name":"limitReq","cost_seconds":.+`,
},
})
if err != nil {
Expand Down

0 comments on commit ee4c1e7

Please sign in to comment.