Skip to content

Commit 12b6520

Browse files
committed
Making parseslowlog less strict by accepting empty hosts and types. #29
1 parent b983d0d commit 12b6520

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

cmd/loadspec/logentry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const (
1414
numFields = 7
1515
)
1616

17-
var matcherRE = regexp.MustCompile(`\[(?P<ts>[^]]+)\].?\[.*\].?\[(?P<log_type>[^]]+)\].?\[(?P<host>[^]]+)\].?\[(?P<index>[^]]+)\].?\[.*\].*types\[(?P<types>[^]]+)\].*search_type\[(?P<search_type>[^]]+)\].*source\[(?P<source>.*)\], extra_source`)
17+
var matcherRE = regexp.MustCompile(`\[(?P<ts>[^]]+)\].?\[.*\].?\[(?P<log_type>[^]]+)\].?\[(?P<host>.*)\].?\[(?P<index>[^]]+)\].?\[.*\].*types\[(?P<types>.*)\].*stats.*search_type\[(?P<search_type>[^]]+)\].*source\[(?P<source>.*)\], extra_source`)
1818
var subExpNames = matcherRE.SubexpNames()
1919

2020
type slowlogEntry struct {

cmd/loadspec/logentry_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,15 @@ func TestDecodeSlowlogEntry(t *testing.T) {
1414
is.Equal(logEntry.Source, `{"size":50,"query":{"term":{"status":"AVAILABLE"}}}`)
1515
is.Equal(logEntry.SearchType, "QUERY_THEN_FETCH")
1616
}
17+
18+
func TestDecodeSlowlogEntry_withType(t *testing.T) {
19+
is := is.New(t)
20+
logEntry := decodeSlowlogEntry(`[2018-11-15 10:57:43,659][WARN ][index.search.slowlog.query] [] [test][0] took[23.3ms], took_millis[23], types[], stats[], search_type[QUERY_THEN_FETCH], total_shards[5], source[{"query":{"match":{"test":"test"}}}], extra_source[]`)
21+
is.Equal(logEntry.Timestamp, "2018-11-15 10:57:43,659")
22+
is.Equal(logEntry.LogType, "index.search.slowlog.query")
23+
is.Equal(logEntry.Host, "")
24+
is.Equal(logEntry.Index, "test")
25+
is.Equal(logEntry.Types, "")
26+
is.Equal(logEntry.Source, `{"query":{"match":{"test":"test"}}}`)
27+
is.Equal(logEntry.SearchType, "QUERY_THEN_FETCH")
28+
}

0 commit comments

Comments
 (0)