(control) Add better timestamps for the events and message queue views

Adjust display precision based on distance into the past, full ms-accurate timestamps available via hover-action.
This commit is contained in:
Viktor Lofgren 2024-01-13 13:03:52 +01:00
parent 81eaf79a25
commit 2fefd0e4e3
6 changed files with 52 additions and 13 deletions

View File

@ -1,12 +1,26 @@
package nu.marginalia.control.sys.model; package nu.marginalia.control.sys.model;
import java.sql.Timestamp;
import java.time.LocalDate;
public record EventLogEntry( public record EventLogEntry(
long id, long id,
String serviceName, String serviceName,
String instanceFull, String instanceFull,
String eventTime,
String eventDateTime, String eventDateTime,
String eventType, String eventType,
String eventMessage) String eventMessage)
{ {
public String getEventTime() {
String retDateBase = eventDateTime.replace('T', ' ');
// if another day, return date, hour and minute
if (!eventDateTime.startsWith(LocalDate.now().toString())) {
// return hour minute and seconds
return retDateBase.substring(0, "YYYY-MM-DDTHH:MM".length());
}
else { // return date, hour and minute but not seconds or ms
return retDateBase.substring("YYYY-MM-DDT".length(), "YYYY-MM-DDTHH:MM:SS".length());
}
}
} }

View File

@ -1,5 +1,7 @@
package nu.marginalia.control.sys.model; package nu.marginalia.control.sys.model;
import java.time.LocalDate;
public record MessageQueueEntry ( public record MessageQueueEntry (
long id, long id,
long relatedId, long relatedId,
@ -10,7 +12,7 @@ public record MessageQueueEntry (
String ownerInstanceFull, String ownerInstanceFull,
long ownerTick, long ownerTick,
String state, String state,
String createdTime, String updatedTimeFull,
String updatedTime, String updatedTime,
int ttl int ttl
) )
@ -32,4 +34,30 @@ public record MessageQueueEntry (
default -> ""; default -> "";
}; };
} }
public String getCreatedTime() {
String retDateBase = updatedTimeFull.replace('T', ' ');
// if another day, return date, hour and minute
if (!updatedTimeFull.startsWith(LocalDate.now().toString())) {
// return hour minute and seconds
return retDateBase.substring(0, "YYYY-MM-DDTHH:MM".length());
}
else { // return date, hour and minute but not seconds or ms
return retDateBase.substring("YYYY-MM-DDT".length(), "YYYY-MM-DDTHH:MM:SS".length());
}
}
public String getUpdatedTime() {
String retDateBase = updatedTimeFull.replace('T', ' ');
// if another day, return date, hour and minute
if (!updatedTimeFull.startsWith(LocalDate.now().toString())) {
// return hour minute and seconds
return retDateBase.substring(0, "YYYY-MM-DDTHH:MM".length());
}
else { // return date, hour and minute but not seconds or ms
return retDateBase.substring("YYYY-MM-DDT".length(), "YYYY-MM-DDTHH:MM:SS".length());
}
}
} }

View File

@ -11,6 +11,7 @@ import spark.Request;
import spark.Response; import spark.Response;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -108,7 +109,6 @@ public class EventLogService {
rs.getLong("ID"), rs.getLong("ID"),
rs.getString("SERVICE_NAME"), rs.getString("SERVICE_NAME"),
rs.getString("INSTANCE"), rs.getString("INSTANCE"),
rs.getTimestamp("EVENT_TIME").toLocalDateTime().toLocalTime().toString(),
rs.getTimestamp("EVENT_TIME").toLocalDateTime().toString(), rs.getTimestamp("EVENT_TIME").toLocalDateTime().toString(),
rs.getString("EVENT_TYPE"), rs.getString("EVENT_TYPE"),
rs.getString("EVENT_MESSAGE") rs.getString("EVENT_MESSAGE")
@ -143,7 +143,6 @@ public class EventLogService {
rs.getLong("ID"), rs.getLong("ID"),
rs.getString("SERVICE_NAME"), rs.getString("SERVICE_NAME"),
rs.getString("INSTANCE"), rs.getString("INSTANCE"),
rs.getTimestamp("EVENT_TIME").toLocalDateTime().toLocalTime().toString(),
rs.getTimestamp("EVENT_TIME").toLocalDateTime().toString(), rs.getTimestamp("EVENT_TIME").toLocalDateTime().toString(),
rs.getString("EVENT_TYPE"), rs.getString("EVENT_TYPE"),
rs.getString("EVENT_MESSAGE") rs.getString("EVENT_MESSAGE")
@ -155,6 +154,7 @@ public class EventLogService {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
} }
public List<EventLogEntry> getLastEntriesForTypeAndService(String typeName, String serviceName, long afterId, int n) { public List<EventLogEntry> getLastEntriesForTypeAndService(String typeName, String serviceName, long afterId, int n) {
try (var conn = dataSource.getConnection(); try (var conn = dataSource.getConnection();
var query = conn.prepareStatement(""" var query = conn.prepareStatement("""
@ -178,7 +178,6 @@ public class EventLogService {
rs.getLong("ID"), rs.getLong("ID"),
rs.getString("SERVICE_NAME"), rs.getString("SERVICE_NAME"),
rs.getString("INSTANCE"), rs.getString("INSTANCE"),
rs.getTimestamp("EVENT_TIME").toLocalDateTime().toLocalTime().toString(),
rs.getTimestamp("EVENT_TIME").toLocalDateTime().toString(), rs.getTimestamp("EVENT_TIME").toLocalDateTime().toString(),
rs.getString("EVENT_TYPE"), rs.getString("EVENT_TYPE"),
rs.getString("EVENT_MESSAGE") rs.getString("EVENT_MESSAGE")
@ -214,7 +213,6 @@ public class EventLogService {
rs.getLong("ID"), rs.getLong("ID"),
rs.getString("SERVICE_NAME"), rs.getString("SERVICE_NAME"),
rs.getString("INSTANCE"), rs.getString("INSTANCE"),
rs.getTimestamp("EVENT_TIME").toLocalDateTime().toLocalTime().toString(),
rs.getTimestamp("EVENT_TIME").toLocalDateTime().toString(), rs.getTimestamp("EVENT_TIME").toLocalDateTime().toString(),
rs.getString("EVENT_TYPE"), rs.getString("EVENT_TYPE"),
rs.getString("EVENT_MESSAGE") rs.getString("EVENT_MESSAGE")
@ -247,7 +245,6 @@ public class EventLogService {
rs.getLong("ID"), rs.getLong("ID"),
rs.getString("SERVICE_NAME"), rs.getString("SERVICE_NAME"),
rs.getString("INSTANCE"), rs.getString("INSTANCE"),
rs.getTimestamp("EVENT_TIME").toLocalDateTime().toLocalTime().toString(),
rs.getTimestamp("EVENT_TIME").toLocalDateTime().toString(), rs.getTimestamp("EVENT_TIME").toLocalDateTime().toString(),
rs.getString("EVENT_TYPE"), rs.getString("EVENT_TYPE"),
rs.getString("EVENT_MESSAGE") rs.getString("EVENT_MESSAGE")

View File

@ -364,8 +364,8 @@ public class MessageQueueService {
rs.getString("OWNER_INSTANCE"), rs.getString("OWNER_INSTANCE"),
rs.getLong("OWNER_TICK"), rs.getLong("OWNER_TICK"),
rs.getString("STATE"), rs.getString("STATE"),
rs.getTimestamp("CREATED_TIME").toLocalDateTime().toLocalTime().toString(), rs.getTimestamp("CREATED_TIME").toLocalDateTime().toString(),
rs.getTimestamp("UPDATED_TIME").toLocalDateTime().toLocalTime().toString(), rs.getTimestamp("UPDATED_TIME").toLocalDateTime().toString(),
rs.getInt("TTL")); rs.getInt("TTL"));
} }
} }

View File

@ -54,8 +54,8 @@
</tr> </tr>
{{/unless}} {{/unless}}
</table> </table>
</div>
</div> </div>
</div>
</body> </body>
{{> control/partials/foot-includes }} {{> control/partials/foot-includes }}
</html> </html>

View File

@ -44,7 +44,7 @@
<td><a href="/message-queue?inbox={{recipientInbox}}">{{recipientInbox}}</a></td> <td><a href="/message-queue?inbox={{recipientInbox}}">{{recipientInbox}}</a></td>
<td>{{function}}</td> <td>{{function}}</td>
<td>{{{readableUUID ownerInstanceFull}}}</td> <td>{{{readableUUID ownerInstanceFull}}}</td>
<td>{{createdTime}}</td> <td title="{{createdTimeFull}}">{{createdTime}}</td>
</tr> </tr>
<tr> <tr>
<td>{{ttl}}</td> <td>{{ttl}}</td>
@ -56,9 +56,9 @@
{{/if}} {{/if}}
</td> </td>
<td><a href="/message-queue?inbox={{senderInbox}}">{{senderInbox}}</a></td> <td><a href="/message-queue?inbox={{senderInbox}}">{{senderInbox}}</a></td>
<td>{{payload}}</td> <td style="word-break: break-all; font-family: monospace;">{{payload}}</td>
<td>{{ownerTick}}</td> <td>{{ownerTick}}</td>
<td>{{updatedTime}}</td> <td title="{{updatedTimeFull}}">{{updatedTime}}</td>
</tr> </tr>
{{/each}} {{/each}}
<tfoot> <tfoot>