Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pkg/executor/slow_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,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 @@ -607,6 +611,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:min(current, len(line))])
parseKey = true
Expand All @@ -616,6 +627,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 pkg/executor/slow_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ func TestSplitbyColon(t *testing.T) {
{
"123a",
[]string{"123a"},
[]string{},
[]string{""},
},
{
"1a: 2b",
Expand Down Expand Up @@ -593,9 +593,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