SHA256
fix(debug-api): починить сборку после merge и унифицировать буфер debug-логов
This commit is contained in:
@@ -18,6 +18,7 @@ import java.net.SocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* GET /debug/ws/clients
|
||||
@@ -43,7 +44,7 @@ public class DebugClientsServlet extends HttpServlet {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ConnectionContext> contexts = ActiveConnectionsRegistry.getInstance().getAllConnectionsSnapshot();
|
||||
Set<ConnectionContext> contexts = ActiveConnectionsRegistry.getInstance().getAllConnectionsSnapshot();
|
||||
List<ObjectNode> rows = new ArrayList<>();
|
||||
for (ConnectionContext ctx : contexts) {
|
||||
Session ws = ctx.getWsSession();
|
||||
|
||||
@@ -8,6 +8,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import server.logic.ws_protocol.JSON.ActiveConnectionsRegistry;
|
||||
import server.logic.ws_protocol.JSON.ConnectionContext;
|
||||
import server.logic.ws_protocol.JSON.debug.DebugRunLogBuffer;
|
||||
import server.logic.ws_protocol.JSON.push.WsEventSender;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import server.logic.ws_protocol.JSON.debug.DebugRunLogBuffer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
package server.debug;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Потокобезопасный in-memory буфер debug-логов.
|
||||
*/
|
||||
public final class DebugRunLogBuffer {
|
||||
|
||||
public static final class Entry {
|
||||
public long ts;
|
||||
public String level;
|
||||
public String runId;
|
||||
public String source;
|
||||
public String sessionId;
|
||||
public String login;
|
||||
public String message;
|
||||
public String details;
|
||||
}
|
||||
|
||||
private static final DebugRunLogBuffer INSTANCE = new DebugRunLogBuffer(5_000);
|
||||
|
||||
public static DebugRunLogBuffer getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private final int capacity;
|
||||
private final Deque<Entry> entries = new ArrayDeque<>();
|
||||
|
||||
private DebugRunLogBuffer(int capacity) {
|
||||
this.capacity = Math.max(100, capacity);
|
||||
}
|
||||
|
||||
public synchronized String newRunId() {
|
||||
return "dbg-" + UUID.randomUUID();
|
||||
}
|
||||
|
||||
public synchronized void clear() {
|
||||
entries.clear();
|
||||
}
|
||||
|
||||
public synchronized void add(String level, String runId, String source, String sessionId, String login, String message, String details) {
|
||||
Entry e = new Entry();
|
||||
e.ts = System.currentTimeMillis();
|
||||
e.level = safe(level, "info");
|
||||
e.runId = safe(runId, "");
|
||||
e.source = safe(source, "server");
|
||||
e.sessionId = safe(sessionId, "");
|
||||
e.login = safe(login, "");
|
||||
e.message = safe(message, "");
|
||||
e.details = safe(details, "");
|
||||
|
||||
entries.addLast(e);
|
||||
while (entries.size() > capacity) {
|
||||
entries.removeFirst();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized List<Entry> tail(int limit, String runIdFilter) {
|
||||
int capped = Math.max(1, Math.min(limit, 1000));
|
||||
String filter = safe(runIdFilter, "");
|
||||
|
||||
List<Entry> out = new ArrayList<>(capped);
|
||||
Object[] arr = entries.toArray();
|
||||
for (int i = arr.length - 1; i >= 0 && out.size() < capped; i--) {
|
||||
Entry e = (Entry) arr[i];
|
||||
if (!filter.isBlank() && !filter.equals(e.runId)) continue;
|
||||
out.add(e);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static String safe(String value, String fallback) {
|
||||
String s = value == null ? "" : value.trim();
|
||||
return s.isBlank() ? fallback : s;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user