Commit a241cb7d by Johannes Edmeier

Handle non epoch timestamp in trace-legacy converter

parent 25f4003f
...@@ -20,7 +20,10 @@ import de.codecentric.boot.admin.server.domain.values.Endpoint; ...@@ -20,7 +20,10 @@ import de.codecentric.boot.admin.server.domain.values.Endpoint;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.time.DateTimeException;
import java.time.Instant; import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
...@@ -54,6 +57,8 @@ public class LegacyEndpointConverters { ...@@ -54,6 +57,8 @@ public class LegacyEndpointConverters {
}; };
private static final Jackson2JsonDecoder DECODER; private static final Jackson2JsonDecoder DECODER;
private static final Jackson2JsonEncoder ENCODER; private static final Jackson2JsonEncoder ENCODER;
private static final DateTimeFormatter TIMESTAMP_PATTERN = DateTimeFormatter.ofPattern(
"yyyy-MM-dd'T'HH:mm:ss.SSSZ");
static { static {
ObjectMapper om = Jackson2ObjectMapperBuilder.json() ObjectMapper om = Jackson2ObjectMapperBuilder.json()
...@@ -157,7 +162,7 @@ public class LegacyEndpointConverters { ...@@ -157,7 +162,7 @@ public class LegacyEndpointConverters {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static Map<String, Object> convertHttptrace(Map<String, Object> in) { private static Map<String, Object> convertHttptrace(Map<String, Object> in) {
Map<String, Object> out = new LinkedHashMap<>(); Map<String, Object> out = new LinkedHashMap<>();
out.put("timestamp", Instant.ofEpochMilli((Long) in.get("timestamp"))); out.put("timestamp", getInstant(in.get("timestamp")));
Map<String, Object> in_info = (Map<String, Object>) in.get("info"); Map<String, Object> in_info = (Map<String, Object>) in.get("info");
if (in_info != null) { if (in_info != null) {
Map<String, Object> request = new LinkedHashMap<>(); Map<String, Object> request = new LinkedHashMap<>();
...@@ -254,4 +259,17 @@ public class LegacyEndpointConverters { ...@@ -254,4 +259,17 @@ public class LegacyEndpointConverters {
return converted; return converted;
}).collect(toList()); }).collect(toList());
} }
private static Instant getInstant(Object o) {
try {
if (o instanceof String) {
return OffsetDateTime.parse((String) o, TIMESTAMP_PATTERN).toInstant();
} else if (o instanceof Long) {
return Instant.ofEpochMilli((Long) o);
}
} catch (DateTimeException | ClassCastException e) {
return null;
}
return null;
}
} }
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
"timeTaken": 2 "timeTaken": 2
}, },
{ {
"timestamp": "2018-02-04T21:58:45.290Z", "timestamp": "2018-02-19T17:34:51.207Z",
"request": { "request": {
"method": "GET", "method": "GET",
"uri": "", "uri": "",
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
} }
}, },
{ {
"timestamp": 1517781525290, "timestamp": "2018-02-19T17:34:51.207+0000",
"info": { "info": {
"method": "GET", "method": "GET",
"path": "", "path": "",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment