Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rename] Fix imports in the libs module. #385

Merged
merged 1 commit into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* This differs from a morton encoded value which interleaves lat/lon (y/x).
*
* NOTE: this will replace {@code org.elasticsearch.common.geo.GeoHashUtils}
* NOTE: this will replace {@code org.opensearch.common.geo.GeoHashUtils}
*/
public class Geohash {
private static final char[] BASE_32 = {'0', '1', '2', '3', '4', '5', '6',
Expand Down
144 changes: 72 additions & 72 deletions libs/grok/src/test/java/org/opensearch/grok/GrokTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@
public class GrokTests extends OpenSearchTestCase {
public void testMatchWithoutCaptures() {
Grok grok = new Grok(Grok.BUILTIN_PATTERNS, "value", logger::warn);
assertThat(grok.captures("value"), equalTo(org.elasticsearch.common.collect.Map.of()));
assertThat(grok.captures("prefix_value"), equalTo(org.elasticsearch.common.collect.Map.of()));
assertThat(grok.captures("value"), equalTo(org.opensearch.common.collect.Map.of()));
assertThat(grok.captures("prefix_value"), equalTo(org.opensearch.common.collect.Map.of()));
assertThat(grok.captures("no_match"), nullValue());
}

public void testCaputuresBytes() {
Grok grok = new Grok(Grok.BUILTIN_PATTERNS, "%{NUMBER:n:int}", logger::warn);
byte[] utf8 = "10".getBytes(StandardCharsets.UTF_8);
assertThat(captureBytes(grok, utf8, 0, utf8.length), equalTo(org.elasticsearch.common.collect.Map.of("n", 10)));
assertThat(captureBytes(grok, utf8, 0, 1), equalTo(org.elasticsearch.common.collect.Map.of("n", 1)));
assertThat(captureBytes(grok, utf8, 0, utf8.length), equalTo(org.opensearch.common.collect.Map.of("n", 10)));
assertThat(captureBytes(grok, utf8, 0, 1), equalTo(org.opensearch.common.collect.Map.of("n", 1)));
utf8 = "10 11 12".getBytes(StandardCharsets.UTF_8);
assertThat(captureBytes(grok, utf8, 0, 2), equalTo(org.elasticsearch.common.collect.Map.of("n", 10)));
assertThat(captureBytes(grok, utf8, 3, 2), equalTo(org.elasticsearch.common.collect.Map.of("n", 11)));
assertThat(captureBytes(grok, utf8, 6, 2), equalTo(org.elasticsearch.common.collect.Map.of("n", 12)));
assertThat(captureBytes(grok, utf8, 0, 2), equalTo(org.opensearch.common.collect.Map.of("n", 10)));
assertThat(captureBytes(grok, utf8, 3, 2), equalTo(org.opensearch.common.collect.Map.of("n", 11)));
assertThat(captureBytes(grok, utf8, 6, 2), equalTo(org.opensearch.common.collect.Map.of("n", 12)));
}

private Map<String, Object> captureBytes(Grok grok, byte[] utf8, int offset, int length) {
Expand All @@ -87,15 +87,15 @@ public void testSimpleSyslogLine() {
Grok grok = new Grok(Grok.BUILTIN_PATTERNS, "%{SYSLOGLINE}", logger::warn);
assertCaptureConfig(
grok,
org.elasticsearch.common.collect.Map.ofEntries(
org.elasticsearch.common.collect.Map.entry("facility", STRING),
org.elasticsearch.common.collect.Map.entry("logsource", STRING),
org.elasticsearch.common.collect.Map.entry("message", STRING),
org.elasticsearch.common.collect.Map.entry("pid", STRING),
org.elasticsearch.common.collect.Map.entry("priority", STRING),
org.elasticsearch.common.collect.Map.entry("program", STRING),
org.elasticsearch.common.collect.Map.entry("timestamp", STRING),
org.elasticsearch.common.collect.Map.entry("timestamp8601", STRING)
org.opensearch.common.collect.Map.ofEntries(
org.opensearch.common.collect.Map.entry("facility", STRING),
org.opensearch.common.collect.Map.entry("logsource", STRING),
org.opensearch.common.collect.Map.entry("message", STRING),
org.opensearch.common.collect.Map.entry("pid", STRING),
org.opensearch.common.collect.Map.entry("priority", STRING),
org.opensearch.common.collect.Map.entry("program", STRING),
org.opensearch.common.collect.Map.entry("timestamp", STRING),
org.opensearch.common.collect.Map.entry("timestamp8601", STRING)
)
);
Map<String, Object> matches = grok.captures(line);
Expand All @@ -122,16 +122,16 @@ public void testSyslog5424Line() {
Grok grok = new Grok(Grok.BUILTIN_PATTERNS, "%{SYSLOG5424LINE}", logger::warn);
assertCaptureConfig(
grok,
org.elasticsearch.common.collect.Map.ofEntries(
org.elasticsearch.common.collect.Map.entry("syslog5424_app", STRING),
org.elasticsearch.common.collect.Map.entry("syslog5424_host", STRING),
org.elasticsearch.common.collect.Map.entry("syslog5424_msg", STRING),
org.elasticsearch.common.collect.Map.entry("syslog5424_msgid", STRING),
org.elasticsearch.common.collect.Map.entry("syslog5424_pri", STRING),
org.elasticsearch.common.collect.Map.entry("syslog5424_proc", STRING),
org.elasticsearch.common.collect.Map.entry("syslog5424_sd", STRING),
org.elasticsearch.common.collect.Map.entry("syslog5424_ts", STRING),
org.elasticsearch.common.collect.Map.entry("syslog5424_ver", STRING)
org.opensearch.common.collect.Map.ofEntries(
org.opensearch.common.collect.Map.entry("syslog5424_app", STRING),
org.opensearch.common.collect.Map.entry("syslog5424_host", STRING),
org.opensearch.common.collect.Map.entry("syslog5424_msg", STRING),
org.opensearch.common.collect.Map.entry("syslog5424_msgid", STRING),
org.opensearch.common.collect.Map.entry("syslog5424_pri", STRING),
org.opensearch.common.collect.Map.entry("syslog5424_proc", STRING),
org.opensearch.common.collect.Map.entry("syslog5424_sd", STRING),
org.opensearch.common.collect.Map.entry("syslog5424_ts", STRING),
org.opensearch.common.collect.Map.entry("syslog5424_ver", STRING)
)
);
Map<String, Object> matches = grok.captures(line);
Expand All @@ -149,14 +149,14 @@ public void testSyslog5424Line() {
public void testDatePattern() {
String line = "fancy 12-12-12 12:12:12";
Grok grok = new Grok(Grok.BUILTIN_PATTERNS, "(?<timestamp>%{DATE_EU} %{TIME})", logger::warn);
assertCaptureConfig(grok, org.elasticsearch.common.collect.Map.of("timestamp", STRING));
assertCaptureConfig(grok, org.opensearch.common.collect.Map.of("timestamp", STRING));
Map<String, Object> matches = grok.captures(line);
assertEquals("12-12-12 12:12:12", matches.get("timestamp"));
}

public void testNilCoercedValues() {
Grok grok = new Grok(Grok.BUILTIN_PATTERNS, "test (N/A|%{BASE10NUM:duration:float}ms)", logger::warn);
assertCaptureConfig(grok, org.elasticsearch.common.collect.Map.of("duration", FLOAT));
assertCaptureConfig(grok, org.opensearch.common.collect.Map.of("duration", FLOAT));
Map<String, Object> matches = grok.captures("test 28.4ms");
assertEquals(28.4f, matches.get("duration"));
matches = grok.captures("test N/A");
Expand All @@ -165,7 +165,7 @@ public void testNilCoercedValues() {

public void testNilWithNoCoercion() {
Grok grok = new Grok(Grok.BUILTIN_PATTERNS, "test (N/A|%{BASE10NUM:duration}ms)", logger::warn);
assertCaptureConfig(grok, org.elasticsearch.common.collect.Map.of("duration", STRING));
assertCaptureConfig(grok, org.opensearch.common.collect.Map.of("duration", STRING));
Map<String, Object> matches = grok.captures("test 28.4ms");
assertEquals("28.4", matches.get("duration"));
matches = grok.captures("test N/A");
Expand All @@ -178,13 +178,13 @@ public void testUnicodeSyslog() {
"%{GREEDYDATA:syslog_message}", logger::warn);
assertCaptureConfig(
grok,
org.elasticsearch.common.collect.Map.ofEntries(
org.elasticsearch.common.collect.Map.entry("syslog_hostname", STRING),
org.elasticsearch.common.collect.Map.entry("syslog_message", STRING),
org.elasticsearch.common.collect.Map.entry("syslog_pid", STRING),
org.elasticsearch.common.collect.Map.entry("syslog_pri", STRING),
org.elasticsearch.common.collect.Map.entry("syslog_program", STRING),
org.elasticsearch.common.collect.Map.entry("syslog_timestamp", STRING)
org.opensearch.common.collect.Map.ofEntries(
org.opensearch.common.collect.Map.entry("syslog_hostname", STRING),
org.opensearch.common.collect.Map.entry("syslog_message", STRING),
org.opensearch.common.collect.Map.entry("syslog_pid", STRING),
org.opensearch.common.collect.Map.entry("syslog_pri", STRING),
org.opensearch.common.collect.Map.entry("syslog_program", STRING),
org.opensearch.common.collect.Map.entry("syslog_timestamp", STRING)
)
);
Map<String, Object> matches = grok.captures("<22>Jan 4 07:50:46 mailmaster postfix/policy-spf[9454]: : " +
Expand All @@ -197,21 +197,21 @@ public void testUnicodeSyslog() {

public void testNamedFieldsWithWholeTextMatch() {
Grok grok = new Grok(Grok.BUILTIN_PATTERNS, "%{DATE_EU:stimestamp}", logger::warn);
assertCaptureConfig(grok, org.elasticsearch.common.collect.Map.of("stimestamp", STRING));
assertCaptureConfig(grok, org.opensearch.common.collect.Map.of("stimestamp", STRING));
Map<String, Object> matches = grok.captures("11/01/01");
assertThat(matches.get("stimestamp"), equalTo("11/01/01"));
}

public void testWithOniguramaNamedCaptures() {
Grok grok = new Grok(Grok.BUILTIN_PATTERNS, "(?<foo>\\w+)", logger::warn);
assertCaptureConfig(grok, org.elasticsearch.common.collect.Map.of("foo", STRING));
assertCaptureConfig(grok, org.opensearch.common.collect.Map.of("foo", STRING));
Map<String, Object> matches = grok.captures("hello world");
assertThat(matches.get("foo"), equalTo("hello"));
}

public void testISO8601() {
Grok grok = new Grok(Grok.BUILTIN_PATTERNS, "^%{TIMESTAMP_ISO8601}$", logger::warn);
assertCaptureConfig(grok, org.elasticsearch.common.collect.Map.of());
assertCaptureConfig(grok, org.opensearch.common.collect.Map.of());
List<String> timeMessages = Arrays.asList(
"2001-01-01T00:00:00",
"1974-03-02T04:09:09",
Expand All @@ -236,7 +236,7 @@ public void testISO8601() {

public void testNotISO8601() {
Grok grok = new Grok(Grok.BUILTIN_PATTERNS, "^%{TIMESTAMP_ISO8601}$", logger::warn);
assertCaptureConfig(grok, org.elasticsearch.common.collect.Map.of());
assertCaptureConfig(grok, org.opensearch.common.collect.Map.of());
List<String> timeMessages = Arrays.asList(
"2001-13-01T00:00:00", // invalid month
"2001-00-01T00:00:00", // invalid month
Expand Down Expand Up @@ -276,7 +276,7 @@ public void testNoNamedCaptures() {
String text = "wowza !!!Tal!!! - Tal";
String pattern = "%{EXCITED_NAME} - %{NAME}";
Grok g = new Grok(bank, pattern, false, logger::warn);
assertCaptureConfig(g, org.elasticsearch.common.collect.Map.of("EXCITED_NAME_0", STRING, "NAME_21", STRING, "NAME_22", STRING));
assertCaptureConfig(g, org.opensearch.common.collect.Map.of("EXCITED_NAME_0", STRING, "NAME_21", STRING, "NAME_22", STRING));

assertEquals("(?<EXCITED_NAME_0>!!!(?<NAME_21>Tal)!!!) - (?<NAME_22>Tal)", g.toRegex(pattern));
assertEquals(true, g.match(text));
Expand Down Expand Up @@ -351,7 +351,7 @@ public void testCircularReference() {
public void testBooleanCaptures() {
String pattern = "%{WORD:name}=%{WORD:status:boolean}";
Grok g = new Grok(Grok.BUILTIN_PATTERNS, pattern, logger::warn);
assertCaptureConfig(g, org.elasticsearch.common.collect.Map.of("name", STRING, "status", BOOLEAN));
assertCaptureConfig(g, org.opensearch.common.collect.Map.of("name", STRING, "status", BOOLEAN));

String text = "active=true";
Map<String, Object> expected = new HashMap<>();
Expand Down Expand Up @@ -379,7 +379,7 @@ public void testNumericCaptures() {

String pattern = "%{NUMBER:bytes:float} %{NUMBER:id:long} %{NUMBER:rating:double}";
Grok g = new Grok(bank, pattern, logger::warn);
assertCaptureConfig(g, org.elasticsearch.common.collect.Map.of("bytes", FLOAT, "id", LONG, "rating", DOUBLE));
assertCaptureConfig(g, org.opensearch.common.collect.Map.of("bytes", FLOAT, "id", LONG, "rating", DOUBLE));

String text = "12009.34 20000000000 4820.092";
Map<String, Object> expected = new HashMap<>();
Expand Down Expand Up @@ -427,7 +427,7 @@ public void testNumericCapturesCoercion() {

String pattern = "%{NUMBER:bytes:float} %{NUMBER:status} %{NUMBER}";
Grok g = new Grok(bank, pattern, logger::warn);
assertCaptureConfig(g, org.elasticsearch.common.collect.Map.of("bytes", FLOAT, "status", STRING));
assertCaptureConfig(g, org.opensearch.common.collect.Map.of("bytes", FLOAT, "status", STRING));

String text = "12009.34 200 9032";
Map<String, Object> expected = new HashMap<>();
Expand All @@ -445,8 +445,8 @@ public void testGarbageTypeNameBecomesString() {

String pattern = "%{NUMBER:f:not_a_valid_type}";
Grok g = new Grok(bank, pattern, logger::warn);
assertCaptureConfig(g, org.elasticsearch.common.collect.Map.of("f", STRING));
assertThat(g.captures("12009.34"), equalTo(org.elasticsearch.common.collect.Map.of("f", "12009.34")));
assertCaptureConfig(g, org.opensearch.common.collect.Map.of("f", STRING));
assertThat(g.captures("12009.34"), equalTo(org.opensearch.common.collect.Map.of("f", "12009.34")));
}

public void testApacheLog() {
Expand All @@ -456,19 +456,19 @@ public void testApacheLog() {
Grok grok = new Grok(Grok.BUILTIN_PATTERNS, "%{COMBINEDAPACHELOG}", logger::warn);
assertCaptureConfig(
grok,
org.elasticsearch.common.collect.Map.ofEntries(
org.elasticsearch.common.collect.Map.entry("agent", STRING),
org.elasticsearch.common.collect.Map.entry("auth", STRING),
org.elasticsearch.common.collect.Map.entry("bytes", STRING),
org.elasticsearch.common.collect.Map.entry("clientip", STRING),
org.elasticsearch.common.collect.Map.entry("httpversion", STRING),
org.elasticsearch.common.collect.Map.entry("ident", STRING),
org.elasticsearch.common.collect.Map.entry("rawrequest", STRING),
org.elasticsearch.common.collect.Map.entry("referrer", STRING),
org.elasticsearch.common.collect.Map.entry("request", STRING),
org.elasticsearch.common.collect.Map.entry("response", STRING),
org.elasticsearch.common.collect.Map.entry("timestamp", STRING),
org.elasticsearch.common.collect.Map.entry("verb", STRING)
org.opensearch.common.collect.Map.ofEntries(
org.opensearch.common.collect.Map.entry("agent", STRING),
org.opensearch.common.collect.Map.entry("auth", STRING),
org.opensearch.common.collect.Map.entry("bytes", STRING),
org.opensearch.common.collect.Map.entry("clientip", STRING),
org.opensearch.common.collect.Map.entry("httpversion", STRING),
org.opensearch.common.collect.Map.entry("ident", STRING),
org.opensearch.common.collect.Map.entry("rawrequest", STRING),
org.opensearch.common.collect.Map.entry("referrer", STRING),
org.opensearch.common.collect.Map.entry("request", STRING),
org.opensearch.common.collect.Map.entry("response", STRING),
org.opensearch.common.collect.Map.entry("timestamp", STRING),
org.opensearch.common.collect.Map.entry("verb", STRING)
)
);
Map<String, Object> matches = grok.captures(logLine);
Expand Down Expand Up @@ -533,18 +533,18 @@ public void testComplete() {
Grok grok = new Grok(bank, pattern, logger::warn);
assertCaptureConfig(
grok,
org.elasticsearch.common.collect.Map.ofEntries(
org.elasticsearch.common.collect.Map.entry("agent", STRING),
org.elasticsearch.common.collect.Map.entry("auth", STRING),
org.elasticsearch.common.collect.Map.entry("bytes", INTEGER),
org.elasticsearch.common.collect.Map.entry("clientip", STRING),
org.elasticsearch.common.collect.Map.entry("httpversion", STRING),
org.elasticsearch.common.collect.Map.entry("ident", STRING),
org.elasticsearch.common.collect.Map.entry("referrer", STRING),
org.elasticsearch.common.collect.Map.entry("request", STRING),
org.elasticsearch.common.collect.Map.entry("response", INTEGER),
org.elasticsearch.common.collect.Map.entry("timestamp", STRING),
org.elasticsearch.common.collect.Map.entry("verb", STRING)
org.opensearch.common.collect.Map.ofEntries(
org.opensearch.common.collect.Map.entry("agent", STRING),
org.opensearch.common.collect.Map.entry("auth", STRING),
org.opensearch.common.collect.Map.entry("bytes", INTEGER),
org.opensearch.common.collect.Map.entry("clientip", STRING),
org.opensearch.common.collect.Map.entry("httpversion", STRING),
org.opensearch.common.collect.Map.entry("ident", STRING),
org.opensearch.common.collect.Map.entry("referrer", STRING),
org.opensearch.common.collect.Map.entry("request", STRING),
org.opensearch.common.collect.Map.entry("response", INTEGER),
org.opensearch.common.collect.Map.entry("timestamp", STRING),
org.opensearch.common.collect.Map.entry("verb", STRING)
)
);

Expand Down Expand Up @@ -578,7 +578,7 @@ public void testMultipleNamedCapturesWithSameName() {
Map<String, String> bank = new HashMap<>();
bank.put("SINGLEDIGIT", "[0-9]");
Grok grok = new Grok(bank, "%{SINGLEDIGIT:num}%{SINGLEDIGIT:num}", logger::warn);
assertCaptureConfig(grok, org.elasticsearch.common.collect.Map.of("num", STRING));
assertCaptureConfig(grok, org.opensearch.common.collect.Map.of("num", STRING));

Map<String, Object> expected = new HashMap<>();
expected.put("num", "1");
Expand Down