Skip to content

Commit

Permalink
Be more lenient with fieldnames in Grok Processor (elastic#21745)
Browse files Browse the repository at this point in the history
  • Loading branch information
original-brownbear committed Jun 29, 2018
1 parent 5925611 commit 5318e38
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions libs/grok/src/main/java/org/elasticsearch/grok/Grok.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final class Grok {
"%\\{" +
"(?<name>" +
"(?<pattern>[A-z0-9]+)" +
"(?::(?<subname>[A-z0-9_:.-]+))?" +
"(?::(?<subname>[[:alnum:]@\\[\\]_:.-]+))?" +
")" +
"(?:=(?<definition>" +
"(?:" +
Expand Down Expand Up @@ -81,11 +81,11 @@ public final class Grok {
public Grok(Map<String, String> patternBank, String grokPattern) {
this(patternBank, grokPattern, true, ThreadWatchdog.noop());
}

public Grok(Map<String, String> patternBank, String grokPattern, ThreadWatchdog threadWatchdog) {
this(patternBank, grokPattern, true, threadWatchdog);
}

Grok(Map<String, String> patternBank, String grokPattern, boolean namedCaptures) {
this(patternBank, grokPattern, namedCaptures, ThreadWatchdog.noop());
}
Expand Down
13 changes: 11 additions & 2 deletions libs/grok/src/test/java/org/elasticsearch/grok/GrokTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,10 @@ public void testMultipleNamedCapturesWithSameName() {
expected.put("num", "1");
assertThat(grok.captures("12"), equalTo(expected));
}

public void testExponentialExpressions() {
AtomicBoolean run = new AtomicBoolean(true); // to avoid a lingering thread when test has completed

String grokPattern = "Bonsuche mit folgender Anfrage: Belegart->\\[%{WORD:param2},(?<param5>(\\s*%{NOTSPACE})*)\\] " +
"Zustand->ABGESCHLOSSEN Kassennummer->%{WORD:param9} Bonnummer->%{WORD:param10} Datum->%{DATESTAMP_OTHER:param11}";
String logLine = "Bonsuche mit folgender Anfrage: Belegart->[EINGESCHRAENKTER_VERKAUF, VERKAUF, NACHERFASSUNG] " +
Expand All @@ -439,4 +439,13 @@ public void testExponentialExpressions() {
run.set(false);
assertThat(e.getMessage(), equalTo("grok pattern matching was interrupted after [200] ms"));
}

public void testUnicodeFieldnames() {
for(String fieldName : Arrays.asList("@metadata", "@metädata", "@metädat[a]")) {
String line = "foo";
Grok grok = new Grok(basePatterns, "%{WORD:" + fieldName + "}");
Map<String, Object> matches = grok.captures(line);
assertEquals("foo", matches.get(fieldName));
}
}
}

0 comments on commit 5318e38

Please sign in to comment.