fix: logs for not running containers

This commit is contained in:
Andras Bacsai 2022-10-10 15:28:46 +02:00
parent d4b7318413
commit 6882e83d1e
4 changed files with 42 additions and 25 deletions

View File

@ -1243,7 +1243,10 @@ export async function getApplicationLogs(request: FastifyRequest<GetApplicationL
return { logs: sortedLogs }
// }
} catch (error) {
const { statusCode } = error;
const { statusCode, stderr } = error;
if (stderr.startsWith('Error: No such container')) {
return { logs: [], noContainer: true }
}
if (statusCode === 404) {
return {
logs: []

View File

@ -160,12 +160,12 @@
<span>Logs</span>
</li>
<li
class:text-stone-600={$status.application.overallStatus !== 'healthy'}
class:text-stone-600={$status.application.overallStatus === 'stopped'}
class="rounded"
class:bg-coollabs={$page.url.pathname === `/applications/${$page.params.id}/logs`}
>
<a
href={$status.application.overallStatus === 'healthy' ? `/applications/${$page.params.id}/logs` : ''}
href={$status.application.overallStatus !== 'stopped' ? `/applications/${$page.params.id}/logs` : ''}
class="no-underline w-full"
><svg
xmlns="http://www.w3.org/2000/svg"

View File

@ -394,10 +394,13 @@
{:else if $isDeploymentEnabled && !$page.url.pathname.startsWith(`/applications/${id}/configuration/`)}
<button
class="btn btn-sm gap-2 btn-primary"
class="btn btn-sm gap-2"
class:btn-error={$status.application.overallStatus === 'degraded'}
class:btn-primary={$status.application.overallStatus !== 'degraded'}
disabled={!$isDeploymentEnabled}
on:click={() => handleDeploySubmit(false)}
>
{#if $status.application.overallStatus !== 'degraded'}
<svg
xmlns="http://www.w3.org/2000/svg"
class="w-6 h-6"
@ -411,7 +414,26 @@
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M7 4v16l13 -8z" />
</svg>
{$status.application.overallStatus === 'degraded' ? 'Restart Degraded Services' : 'Deploy'}
{:else}
<svg
xmlns="http://www.w3.org/2000/svg"
class="w-6 h-6"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path
d="M16.3 5h.7a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-10a2 2 0 0 1 2 -2h5l-2.82 -2.82m0 5.64l2.82 -2.82"
transform="rotate(-45 12 12)"
/>
</svg>
{/if}
{$status.application.overallStatus === 'degraded' ? 'Restart Degraded Stack' : 'Deploy'}
</button>
{/if}
{#if $location && $status.application.overallStatus === 'healthy'}

View File

@ -5,8 +5,6 @@
import { errorNotification } from '$lib/common';
import { onMount, onDestroy } from 'svelte';
import Tooltip from '$lib/components/Tooltip.svelte';
import { status } from '$lib/store';
import { goto } from '$app/navigation';
let application: any = {};
let logsLoading = false;
@ -19,6 +17,8 @@
let position = 0;
let services: any = [];
let selectedService: any = null;
let noContainer = false;
const { id } = $page.params;
onMount(async () => {
const response = await get(`/applications/${id}`);
@ -33,7 +33,7 @@
name: ''
}
];
await selectService('')
await selectService('');
}
});
onDestroy(() => {
@ -50,27 +50,17 @@
}
return tempdockerComposeServices;
}
async function loadAllLogs() {
try {
logsLoading = true;
const data: any = await get(`/applications/${id}/logs`);
if (data?.logs) {
lastLog = data.logs[data.logs.length - 1];
logs = data.logs;
}
} catch (error) {
return errorNotification(error);
} finally {
logsLoading = false;
}
}
async function loadLogs() {
if (logsLoading) return;
try {
const newLogs: any = await get(
`/applications/${id}/logs/${selectedService}?since=${lastLog?.split(' ')[0] || 0}`
);
if (newLogs.noContainer) {
noContainer = true;
} else {
noContainer = false;
}
if (newLogs?.logs && newLogs.logs[newLogs.logs.length - 1] !== logs[logs.length - 1]) {
logs = logs.concat(newLogs.logs);
lastLog = newLogs.logs[newLogs.logs.length - 1];
@ -103,7 +93,7 @@
}
}
async function selectService(service: any, init: boolean = false) {
if (services.length === 1 && init) return
if (services.length === 1 && init) return;
if (loadLogsInterval) clearInterval(loadLogsInterval);
if (followingInterval) clearInterval(followingInterval);
@ -143,7 +133,9 @@
{#if selectedService}
<div class="flex flex-row justify-center space-x-2">
{#if logs.length === 0}
<div class="text-xl font-bold tracking-tighter">{$t('application.build.waiting_logs')}</div>
{#if noContainer}
<div class="text-xl font-bold tracking-tighter">Container not found / exited.</div>
{/if}
{:else}
<div class="relative w-full">
<div class="flex justify-start sticky space-x-2 pb-2">