Skip to content

Commit

Permalink
Making parseslowlog less strict by accepting empty hosts and types. #29
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfireman committed Nov 15, 2018
1 parent b983d0d commit 12b6520
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/loadspec/logentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
numFields = 7
)

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`)
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`)
var subExpNames = matcherRE.SubexpNames()

type slowlogEntry struct {
Expand Down
12 changes: 12 additions & 0 deletions cmd/loadspec/logentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@ func TestDecodeSlowlogEntry(t *testing.T) {
is.Equal(logEntry.Source, `{"size":50,"query":{"term":{"status":"AVAILABLE"}}}`)
is.Equal(logEntry.SearchType, "QUERY_THEN_FETCH")
}

func TestDecodeSlowlogEntry_withType(t *testing.T) {
is := is.New(t)
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[]`)
is.Equal(logEntry.Timestamp, "2018-11-15 10:57:43,659")
is.Equal(logEntry.LogType, "index.search.slowlog.query")
is.Equal(logEntry.Host, "")
is.Equal(logEntry.Index, "test")
is.Equal(logEntry.Types, "")
is.Equal(logEntry.Source, `{"query":{"match":{"test":"test"}}}`)
is.Equal(logEntry.SearchType, "QUERY_THEN_FETCH")
}

0 comments on commit 12b6520

Please sign in to comment.