From 3a26543eac025fad8c16a6af5909b58ffd4f8ee9 Mon Sep 17 00:00:00 2001 From: vthacker Date: Thu, 1 Feb 2024 13:51:33 -0800 Subject: [PATCH] parse timestamp field in a try-catch --- .../opensearch/BulkApiRequestParser.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/kaldb/src/main/java/com/slack/kaldb/bulkIngestApi/opensearch/BulkApiRequestParser.java b/kaldb/src/main/java/com/slack/kaldb/bulkIngestApi/opensearch/BulkApiRequestParser.java index d32ba7d6ed..3d3b5cdda3 100644 --- a/kaldb/src/main/java/com/slack/kaldb/bulkIngestApi/opensearch/BulkApiRequestParser.java +++ b/kaldb/src/main/java/com/slack/kaldb/bulkIngestApi/opensearch/BulkApiRequestParser.java @@ -46,25 +46,32 @@ public static Map> parseRequest(byte[] postBody) throws * logstash sets that) 3. Use the current time from the ingestMetadata */ public static long getTimestampFromIngestDocument(IngestDocument ingestDocument) { - // assumption that the provided timestamp is in millis - // at some point both th unit and field need to be configurable - // when we do that, remember to change the called to appropriately remove the field - if (ingestDocument.hasField("timestamp")) { - return ingestDocument.getFieldValue("timestamp", Long.class); - } - - if (ingestDocument.hasField("_timestamp")) { - return ingestDocument.getFieldValue("_timestamp", Long.class); - } if (ingestDocument.hasField("@timestamp")) { String dateString = ingestDocument.getFieldValue("@timestamp", String.class); LocalDateTime localDateTime = - LocalDateTime.parse(dateString, DateTimeFormatter.ISO_DATE_TIME); + LocalDateTime.parse(dateString, DateTimeFormatter.ISO_DATE_TIME); Instant instant = localDateTime.toInstant(ZoneOffset.UTC); return instant.toEpochMilli(); } + try { + // assumption that the provided timestamp is in millis + // at some point both th unit and field need to be configurable + // when we do that, remember to change the called to appropriately remove the field + if (ingestDocument.hasField("timestamp")) { + return ingestDocument.getFieldValue("timestamp", Long.class); + } + + if (ingestDocument.hasField("_timestamp")) { + return ingestDocument.getFieldValue("_timestamp", Long.class); + } + } catch (Exception e) { + LOG.warn("Unable to parse timestamp from ingest document", e); + } + + + return ((ZonedDateTime) ingestDocument .getIngestMetadata()