From 12b652082c6288aa816cb2221721f758a421f24d Mon Sep 17 00:00:00 2001 From: Daniel Fireman Date: Thu, 15 Nov 2018 10:47:04 -0300 Subject: [PATCH] Making parseslowlog less strict by accepting empty hosts and types. #29 --- cmd/loadspec/logentry.go | 2 +- cmd/loadspec/logentry_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/loadspec/logentry.go b/cmd/loadspec/logentry.go index e884d41..c9213f5 100644 --- a/cmd/loadspec/logentry.go +++ b/cmd/loadspec/logentry.go @@ -14,7 +14,7 @@ const ( numFields = 7 ) -var matcherRE = regexp.MustCompile(`\[(?P[^]]+)\].?\[.*\].?\[(?P[^]]+)\].?\[(?P[^]]+)\].?\[(?P[^]]+)\].?\[.*\].*types\[(?P[^]]+)\].*search_type\[(?P[^]]+)\].*source\[(?P.*)\], extra_source`) +var matcherRE = regexp.MustCompile(`\[(?P[^]]+)\].?\[.*\].?\[(?P[^]]+)\].?\[(?P.*)\].?\[(?P[^]]+)\].?\[.*\].*types\[(?P.*)\].*stats.*search_type\[(?P[^]]+)\].*source\[(?P.*)\], extra_source`) var subExpNames = matcherRE.SubexpNames() type slowlogEntry struct { diff --git a/cmd/loadspec/logentry_test.go b/cmd/loadspec/logentry_test.go index f1d71fd..0b48f73 100644 --- a/cmd/loadspec/logentry_test.go +++ b/cmd/loadspec/logentry_test.go @@ -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") +}