Skip to content

Commit 19e3f53

Browse files
committed
Manage a static list of DateTimeFormatters
rather than re-creating them on each invocation.
1 parent 079e1f2 commit 19e3f53

File tree

1 file changed

+4
-4
lines changed
  • modules/ingest-common/src/main/java/org/elasticsearch/ingest/common

1 file changed

+4
-4
lines changed

modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CefParser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.regex.Matcher;
3535
import java.util.regex.Pattern;
3636
import java.util.stream.Collectors;
37+
import java.util.stream.Stream;
3738

3839
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
3940
import static java.time.temporal.ChronoField.HOUR_OF_DAY;
@@ -290,7 +291,7 @@ enum DataType {
290291
* List of allowed timestamp formats for CEF spec v27, see: Appendix A: Date Formats
291292
* <a href="https://www.microfocus.com/documentation/arcsight/arcsight-smartconnectors-24.2/pdfdoc/cef-implementation-standard/cef-implementation-standard.pdf">documentation</a>
292293
*/
293-
private static final List<String> TIME_LAYOUTS = List.of(
294+
private static final List<DateTimeFormatter> TIME_FORMATS = Stream.of(
294295
"MMM dd HH:mm:ss.SSS zzz",
295296
"MMM dd HH:mm:ss.SSS",
296297
"MMM dd HH:mm:ss zzz",
@@ -299,7 +300,7 @@ enum DataType {
299300
"MMM dd yyyy HH:mm:ss.SSS",
300301
"MMM dd yyyy HH:mm:ss zzz",
301302
"MMM dd yyyy HH:mm:ss"
302-
);
303+
).map(p -> DateTimeFormatter.ofPattern(p, Locale.ROOT)).toList();
303304

304305
private static final List<ChronoField> CHRONO_FIELDS = List.of(
305306
NANO_OF_SECOND,
@@ -492,9 +493,8 @@ ZonedDateTime toTimestamp(String value) {
492493
// Not a millisecond timestamp, continue to format parsing
493494
}
494495
// Try parsing with different layouts
495-
for (String layout : TIME_LAYOUTS) {
496+
for (DateTimeFormatter formatter : TIME_FORMATS) {
496497
try {
497-
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(layout, Locale.ROOT);
498498
TemporalAccessor accessor = formatter.parse(value);
499499
// if there is no year nor year-of-era, we fall back to the current one and
500500
// fill the rest of the date up with the parsed date

0 commit comments

Comments
 (0)