|
7 | 7 |
|
8 | 8 | import org.elasticsearch.common.collect.Tuple;
|
9 | 9 | import org.elasticsearch.common.util.set.Sets;
|
| 10 | +import org.elasticsearch.xpack.core.ml.filestructurefinder.FieldStats; |
10 | 11 | import org.elasticsearch.xpack.core.ml.filestructurefinder.FileStructure;
|
11 | 12 | import org.elasticsearch.xpack.ml.filestructurefinder.TimestampFormatFinder.TimestampMatch;
|
12 | 13 |
|
13 | 14 | import java.util.Collections;
|
14 | 15 | import java.util.Set;
|
| 16 | +import java.util.stream.Collectors; |
| 17 | + |
| 18 | +import static org.hamcrest.Matchers.hasItem; |
| 19 | +import static org.hamcrest.Matchers.not; |
15 | 20 |
|
16 | 21 | public class TextLogFileStructureFinderTests extends FileStructureTestCase {
|
17 | 22 |
|
@@ -127,6 +132,11 @@ public void testCreateConfigsGivenElasticsearchLog() throws Exception {
|
127 | 132 | assertEquals("\\[%{TIMESTAMP_ISO8601:timestamp}\\]\\[%{LOGLEVEL:loglevel} \\]\\[.*", structure.getGrokPattern());
|
128 | 133 | assertEquals("timestamp", structure.getTimestampField());
|
129 | 134 | assertEquals(Collections.singletonList("ISO8601"), structure.getJodaTimestampFormats());
|
| 135 | + FieldStats messageFieldStats = structure.getFieldStats().get("message"); |
| 136 | + assertNotNull(messageFieldStats); |
| 137 | + for (String statMessage : messageFieldStats.getTopHits().stream().map(m -> (String) m.get("value")).collect(Collectors.toList())) { |
| 138 | + assertThat(structureFinder.getSampleMessages(), hasItem(statMessage)); |
| 139 | + } |
130 | 140 | }
|
131 | 141 |
|
132 | 142 | public void testCreateConfigsGivenElasticsearchLogAndTimestampFieldOverride() throws Exception {
|
@@ -158,6 +168,11 @@ public void testCreateConfigsGivenElasticsearchLogAndTimestampFieldOverride() th
|
158 | 168 | assertEquals("\\[%{TIMESTAMP_ISO8601:my_time}\\]\\[%{LOGLEVEL:loglevel} \\]\\[.*", structure.getGrokPattern());
|
159 | 169 | assertEquals("my_time", structure.getTimestampField());
|
160 | 170 | assertEquals(Collections.singletonList("ISO8601"), structure.getJodaTimestampFormats());
|
| 171 | + FieldStats messageFieldStats = structure.getFieldStats().get("message"); |
| 172 | + assertNotNull(messageFieldStats); |
| 173 | + for (String statMessage : messageFieldStats.getTopHits().stream().map(m -> (String) m.get("value")).collect(Collectors.toList())) { |
| 174 | + assertThat(structureFinder.getSampleMessages(), hasItem(statMessage)); |
| 175 | + } |
161 | 176 | }
|
162 | 177 |
|
163 | 178 | public void testCreateConfigsGivenElasticsearchLogAndGrokPatternOverride() throws Exception {
|
@@ -191,6 +206,13 @@ public void testCreateConfigsGivenElasticsearchLogAndGrokPatternOverride() throw
|
191 | 206 | "\\[%{JAVACLASS:class} *\\] \\[%{HOSTNAME:node}\\] %{JAVALOGMESSAGE:message}", structure.getGrokPattern());
|
192 | 207 | assertEquals("timestamp", structure.getTimestampField());
|
193 | 208 | assertEquals(Collections.singletonList("ISO8601"), structure.getJodaTimestampFormats());
|
| 209 | + FieldStats messageFieldStats = structure.getFieldStats().get("message"); |
| 210 | + assertNotNull(messageFieldStats); |
| 211 | + for (String statMessage : messageFieldStats.getTopHits().stream().map(m -> (String) m.get("value")).collect(Collectors.toList())) { |
| 212 | + // In this case the "message" field was output by the Grok pattern, so "message" |
| 213 | + // at the end of the processing will _not_ contain a complete sample message |
| 214 | + assertThat(structureFinder.getSampleMessages(), not(hasItem(statMessage))); |
| 215 | + } |
194 | 216 | }
|
195 | 217 |
|
196 | 218 | public void testCreateConfigsGivenElasticsearchLogAndImpossibleGrokPatternOverride() {
|
|
0 commit comments