Skip to content

Commit

Permalink
executor: Fix the parse problematic slow log panic issue due to empty…
Browse files Browse the repository at this point in the history
… value string (#58258) (#58270)

close #58147
  • Loading branch information
ti-chi-bot authored Dec 16, 2024
1 parent 0e847c3 commit 6d05536
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
15 changes: 15 additions & 0 deletions executor/slow_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ func splitByColon(line string) (fields []string, values []string) {
fields = append(fields, line[start:current])
parseKey = false
current += 2 // bypass ": "
if current >= lineLength {
// last empty value
values = append(values, "")
}
} else {
start = current
if current < lineLength && (line[current] == '{' || line[current] == '[') {
Expand All @@ -588,6 +592,13 @@ func splitByColon(line string) (fields []string, values []string) {
for current < lineLength && line[current] != ' ' {
current++
}
// Meet empty value cases: "Key: Key:"
if current > 0 && line[current-1] == ':' {
values = append(values, "")
current = start
parseKey = true
continue
}
}
values = append(values, line[start:mathutil.Min(current, len(line))])
parseKey = true
Expand All @@ -597,6 +608,10 @@ func splitByColon(line string) (fields []string, values []string) {
logutil.BgLogger().Warn("slow query parse slow log error", zap.String("Error", errMsg), zap.String("Log", line))
return nil, nil
}
if len(fields) != len(values) {
logutil.BgLogger().Warn("slow query parse slow log error", zap.Int("field_count", len(fields)), zap.Int("value_count", len(values)), zap.String("Log", line))
return nil, nil
}
return fields, values
}

Expand Down
9 changes: 8 additions & 1 deletion executor/slow_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ func TestSplitbyColon(t *testing.T) {
{
"123a",
[]string{"123a"},
[]string{},
[]string{""},
},
{
"1a: 2b",
Expand Down Expand Up @@ -557,9 +557,16 @@ func TestSplitbyColon(t *testing.T) {
[]string{"Time"},
[]string{"2021-09-08T14:39:54.506967433+08:00"},
},
{

"Cop_proc_avg: 0 Cop_proc_addr: Cop_proc_max: Cop_proc_min: ",
[]string{"Cop_proc_avg", "Cop_proc_addr", "Cop_proc_max", "Cop_proc_min"},
[]string{"0", "", "", ""},
},
}
for _, c := range cases {
resFields, resValues := splitByColon(c.line)
logutil.BgLogger().Info(c.line)
require.Equal(t, c.fields, resFields)
require.Equal(t, c.values, resValues)
}
Expand Down

0 comments on commit 6d05536

Please # to comment.