Add pod logs by click: /api/pods + /api/logs endpoints
Deployment/StatefulSet/DaemonSet/CronJob details now show a pod + container picker with the pod's recent log tail (500 lines, no follow), sitting alongside the existing raw-manifest view. Pod resolution reuses buildGraph's ownerReferences-walking logic (ownerWorkloadID) so it stays consistent with the schedules-on edges already shown on the graph. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
8f9c650960
commit
2ac0ddb6ba
@@ -27,6 +27,8 @@
|
||||
#status { position: absolute; top: 8px; left: 8px; font-size: 11px; color: #666; }
|
||||
button { background: #1a1d24; color: #eee; border: 1px solid #333; border-radius: 4px; padding: 4px 8px; cursor: pointer; margin-bottom: 8px; }
|
||||
button:hover { background: #23262e; }
|
||||
select { background: #1a1d24; color: #eee; border: 1px solid #333; border-radius: 4px; padding: 4px; margin: 0 6px 8px 0; max-width: 100%; }
|
||||
#details-logs { max-height: 320px; overflow-y: auto; background: #0b0c0f; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -55,6 +57,14 @@
|
||||
<button id="close-details">закрыть</button>
|
||||
<h2 id="details-title"></h2>
|
||||
<div id="details-facts"></div>
|
||||
<div id="details-logs-section" style="display:none">
|
||||
<h2>Логи</h2>
|
||||
<select id="pod-select"></select>
|
||||
<select id="container-select"></select>
|
||||
<button id="load-logs">Обновить логи</button>
|
||||
<pre id="details-logs"></pre>
|
||||
</div>
|
||||
<h2>Манифест</h2>
|
||||
<pre id="details-yaml">загрузка...</pre>
|
||||
</div>
|
||||
</div>
|
||||
@@ -70,6 +80,8 @@ const KIND_SHAPE = {
|
||||
|
||||
let fullGraph = { nodes: [], edges: [] };
|
||||
let cy;
|
||||
let currentNode = null;
|
||||
const WORKLOAD_KINDS = new Set(['deployment', 'statefulset', 'daemonset', 'cronjob']);
|
||||
|
||||
async function loadGraph() {
|
||||
document.getElementById('status').textContent = 'загрузка...';
|
||||
@@ -161,6 +173,7 @@ function render() {
|
||||
}
|
||||
|
||||
async function showDetails(n) {
|
||||
currentNode = n;
|
||||
document.getElementById('details').classList.add('open');
|
||||
document.getElementById('details-title').textContent = `${n.kind}: ${n.label}`;
|
||||
const factsEl = document.getElementById('details-facts');
|
||||
@@ -170,8 +183,57 @@ async function showDetails(n) {
|
||||
const params = new URLSearchParams({ kind: n.kind, namespace: n.namespace || '', name: n.label });
|
||||
const resp = await fetch('/api/resource?' + params);
|
||||
yamlEl.textContent = resp.ok ? await resp.text() : 'не удалось получить манифест: ' + resp.status;
|
||||
|
||||
const logsSection = document.getElementById('details-logs-section');
|
||||
if (!WORKLOAD_KINDS.has(n.kind)) {
|
||||
logsSection.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
logsSection.style.display = 'block';
|
||||
await loadPodPickers(n, params);
|
||||
}
|
||||
|
||||
async function loadPodPickers(n, params) {
|
||||
const podSelect = document.getElementById('pod-select');
|
||||
const containerSelect = document.getElementById('container-select');
|
||||
const logsEl = document.getElementById('details-logs');
|
||||
podSelect.innerHTML = '<option>загрузка подов...</option>';
|
||||
containerSelect.innerHTML = '';
|
||||
logsEl.textContent = '';
|
||||
|
||||
const resp = await fetch('/api/pods?' + params);
|
||||
const pods = resp.ok ? await resp.json() : [];
|
||||
if (currentNode !== n) return; // user clicked a different node while this was in flight
|
||||
|
||||
if (!pods.length) {
|
||||
podSelect.innerHTML = '<option value="">нет живых подов</option>';
|
||||
logsEl.textContent = 'нет подов для этого workload прямо сейчас.';
|
||||
return;
|
||||
}
|
||||
podSelect.innerHTML = pods.map(p => `<option value="${p.name}">${p.name} (${p.phase})</option>`).join('');
|
||||
|
||||
const fillContainers = () => {
|
||||
const p = pods.find(p => p.name === podSelect.value);
|
||||
containerSelect.innerHTML = (p ? p.containers : []).map(c => `<option value="${c}">${c}</option>`).join('');
|
||||
};
|
||||
podSelect.onchange = () => { fillContainers(); fetchLogs(); };
|
||||
containerSelect.onchange = fetchLogs;
|
||||
fillContainers();
|
||||
await fetchLogs();
|
||||
}
|
||||
|
||||
async function fetchLogs() {
|
||||
const pod = document.getElementById('pod-select').value;
|
||||
const container = document.getElementById('container-select').value;
|
||||
const logsEl = document.getElementById('details-logs');
|
||||
if (!pod) return;
|
||||
logsEl.textContent = 'загрузка логов...';
|
||||
const params = new URLSearchParams({ namespace: currentNode.namespace || '', pod, container: container || '' });
|
||||
const resp = await fetch('/api/logs?' + params);
|
||||
logsEl.textContent = resp.ok ? (await resp.text() || '(логи пустые)') : 'не удалось получить логи: ' + resp.status;
|
||||
}
|
||||
|
||||
document.getElementById('load-logs').addEventListener('click', fetchLogs);
|
||||
document.getElementById('reload').addEventListener('click', loadGraph);
|
||||
document.getElementById('close-details').addEventListener('click', () => document.getElementById('details').classList.remove('open'));
|
||||
document.getElementById('show-system').addEventListener('change', () => { buildNsList(); render(); });
|
||||
|
||||
Reference in New Issue
Block a user