Skip to content

Commit

Permalink
feat: add an ISO formatted timestamp in documents
Browse files Browse the repository at this point in the history
  • Loading branch information
bobeal committed Mar 8, 2024
1 parent 4855134 commit 4c877d6
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -63,6 +65,7 @@ public class ElasticsearchProvenanceReporter extends AbstractProvenanceReporter

private final Map<String, ElasticsearchClient> esClients = new HashMap<>();
private final ObjectMapper objectMapper = new ObjectMapper();
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

private ElasticsearchClient getElasticsearchClient(String elasticsearchUrl) throws MalformedURLException {
if (esClients.containsKey(elasticsearchUrl))
Expand Down Expand Up @@ -98,8 +101,11 @@ public void indexEvent(final Map<String, Object> event, final ReportingContext c
return;
}

final Long eventTimeMillis = (Long) event.get("event_time");

Map<String, Object> preparedEvent = new HashMap<>();
preparedEvent.put("event_time", event.get("event_time"));
preparedEvent.put("event_time", eventTimeMillis);
preparedEvent.put("event_time_iso", sdf.format(new Date(eventTimeMillis)));
preparedEvent.put("component_type", event.get("component_type"));
preparedEvent.put("component_url", event.get("component_url"));
preparedEvent.put("component_name", event.get("component_name"));
Expand Down

0 comments on commit 4c877d6

Please sign in to comment.