made load method private and add another static getter that users of Grok can use to get the builtin patterns.
This commit is contained in:
parent
3fad16e76c
commit
9c405e8595
|
@ -28,10 +28,7 @@ import org.joni.Region;
|
||||||
import org.joni.Syntax;
|
import org.joni.Syntax;
|
||||||
import org.joni.exception.ValueException;
|
import org.joni.exception.ValueException;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -59,6 +56,17 @@ public final class Grok {
|
||||||
")?" + "\\}";
|
")?" + "\\}";
|
||||||
private static final Regex GROK_PATTERN_REGEX = new Regex(GROK_PATTERN.getBytes(StandardCharsets.UTF_8), 0,
|
private static final Regex GROK_PATTERN_REGEX = new Regex(GROK_PATTERN.getBytes(StandardCharsets.UTF_8), 0,
|
||||||
GROK_PATTERN.getBytes(StandardCharsets.UTF_8).length, Option.NONE, UTF8Encoding.INSTANCE, Syntax.DEFAULT);
|
GROK_PATTERN.getBytes(StandardCharsets.UTF_8).length, Option.NONE, UTF8Encoding.INSTANCE, Syntax.DEFAULT);
|
||||||
|
|
||||||
|
private static final Map<String, String> builtinPatterns;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
builtinPatterns = loadBuiltinPatterns();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new UncheckedIOException("unable to load built-in grok patterns", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final Map<String, String> patternBank;
|
private final Map<String, String> patternBank;
|
||||||
private final boolean namedCaptures;
|
private final boolean namedCaptures;
|
||||||
private final Regex compiledExpression;
|
private final Regex compiledExpression;
|
||||||
|
@ -182,14 +190,17 @@ public final class Grok {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> getBuiltinPatterns() {
|
||||||
|
return builtinPatterns;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, String> loadBuiltinPatterns() throws IOException {
|
||||||
// Code for loading built-in grok patterns packaged with the jar file:
|
// Code for loading built-in grok patterns packaged with the jar file:
|
||||||
private static final String[] PATTERN_NAMES = new String[] {
|
String[] PATTERN_NAMES = new String[] {
|
||||||
"aws", "bacula", "bro", "exim", "firewalls", "grok-patterns", "haproxy",
|
"aws", "bacula", "bro", "exim", "firewalls", "grok-patterns", "haproxy",
|
||||||
"java", "junos", "linux-syslog", "mcollective-patterns", "mongodb", "nagios",
|
"java", "junos", "linux-syslog", "mcollective-patterns", "mongodb", "nagios",
|
||||||
"postgresql", "rails", "redis", "ruby"
|
"postgresql", "rails", "redis", "ruby"
|
||||||
};
|
};
|
||||||
|
|
||||||
public static Map<String, String> loadBuiltinPatterns() throws IOException {
|
|
||||||
Map<String, String> builtinPatterns = new HashMap<>();
|
Map<String, String> builtinPatterns = new HashMap<>();
|
||||||
for (String pattern : PATTERN_NAMES) {
|
for (String pattern : PATTERN_NAMES) {
|
||||||
try(InputStream is = Grok.class.getResourceAsStream("/patterns/" + pattern)) {
|
try(InputStream is = Grok.class.getResourceAsStream("/patterns/" + pattern)) {
|
||||||
|
|
|
@ -38,8 +38,8 @@ public class GrokTests extends ESTestCase {
|
||||||
private Map<String, String> basePatterns;
|
private Map<String, String> basePatterns;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws IOException {
|
public void setup() {
|
||||||
basePatterns = Grok.loadBuiltinPatterns();
|
basePatterns = Grok.getBuiltinPatterns();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMatchWithoutCaptures() {
|
public void testMatchWithoutCaptures() {
|
||||||
|
|
|
@ -50,14 +50,7 @@ import org.elasticsearch.rest.RestHandler;
|
||||||
|
|
||||||
public class IngestCommonPlugin extends Plugin implements ActionPlugin, IngestPlugin {
|
public class IngestCommonPlugin extends Plugin implements ActionPlugin, IngestPlugin {
|
||||||
|
|
||||||
static final Map<String, String> GROK_PATTERNS;
|
static final Map<String, String> GROK_PATTERNS = Grok.getBuiltinPatterns();
|
||||||
static {
|
|
||||||
try {
|
|
||||||
GROK_PATTERNS = Grok.loadBuiltinPatterns();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new UncheckedIOException("unable to load built-in grok patterns", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IngestCommonPlugin() {
|
public IngestCommonPlugin() {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue