feat: cleanup clickhouse db
This commit is contained in:
parent
9eeadd5882
commit
7dbde842d7
@ -2653,6 +2653,27 @@ export async function activatePlausibleUsers(request: FastifyRequest<OnlyId>, re
|
|||||||
return errorHandler({ status, message })
|
return errorHandler({ status, message })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export async function cleanupPlausibleLogs(request: FastifyRequest<OnlyId>, reply: FastifyReply) {
|
||||||
|
try {
|
||||||
|
const { id } = request.params
|
||||||
|
const teamId = request.user.teamId;
|
||||||
|
const {
|
||||||
|
destinationDockerId,
|
||||||
|
destinationDocker,
|
||||||
|
plausibleAnalytics: { postgresqlUser, postgresqlPassword, postgresqlDatabase }
|
||||||
|
} = await getServiceFromDB({ id, teamId });
|
||||||
|
if (destinationDockerId) {
|
||||||
|
await executeDockerCmd({
|
||||||
|
dockerId: destinationDocker.id,
|
||||||
|
command: `docker exec ${id}-clickhouse 'clickhouse-client -q "SELECT name FROM system.tables WHERE name LIKE '%log%';" | xargs -I{} clickhouse-client -q "TRUNCATE TABLE system.{};"'`
|
||||||
|
})
|
||||||
|
return await reply.code(201).send()
|
||||||
|
}
|
||||||
|
throw { status: 500, message: 'Could cleanup logs.' }
|
||||||
|
} catch ({ status, message }) {
|
||||||
|
return errorHandler({ status, message })
|
||||||
|
}
|
||||||
|
}
|
||||||
export async function activateWordpressFtp(request: FastifyRequest<ActivateWordpressFtp>, reply: FastifyReply) {
|
export async function activateWordpressFtp(request: FastifyRequest<ActivateWordpressFtp>, reply: FastifyReply) {
|
||||||
const { id } = request.params
|
const { id } = request.params
|
||||||
const { ftpEnabled } = request.body;
|
const { ftpEnabled } = request.body;
|
||||||
|
@ -4,6 +4,7 @@ import {
|
|||||||
activateWordpressFtp,
|
activateWordpressFtp,
|
||||||
checkService,
|
checkService,
|
||||||
checkServiceDomain,
|
checkServiceDomain,
|
||||||
|
cleanupPlausibleLogs,
|
||||||
deleteService,
|
deleteService,
|
||||||
deleteServiceSecret,
|
deleteServiceSecret,
|
||||||
deleteServiceStorage,
|
deleteServiceStorage,
|
||||||
@ -74,6 +75,7 @@ const root: FastifyPluginAsync = async (fastify): Promise<void> => {
|
|||||||
fastify.post<ServiceStartStop & SetWordpressSettings>('/:id/:type/settings', async (request, reply) => await setSettingsService(request, reply));
|
fastify.post<ServiceStartStop & SetWordpressSettings>('/:id/:type/settings', async (request, reply) => await setSettingsService(request, reply));
|
||||||
|
|
||||||
fastify.post<OnlyId>('/:id/plausibleanalytics/activate', async (request, reply) => await activatePlausibleUsers(request, reply));
|
fastify.post<OnlyId>('/:id/plausibleanalytics/activate', async (request, reply) => await activatePlausibleUsers(request, reply));
|
||||||
|
fastify.post<OnlyId>('/:id/plausibleanalytics/cleanup', async (request, reply) => await cleanupPlausibleLogs(request, reply));
|
||||||
fastify.post<ActivateWordpressFtp>('/:id/wordpress/ftp', async (request, reply) => await activateWordpressFtp(request, reply));
|
fastify.post<ActivateWordpressFtp>('/:id/wordpress/ftp', async (request, reply) => await activateWordpressFtp(request, reply));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@
|
|||||||
<a
|
<a
|
||||||
sveltekit:prefetch
|
sveltekit:prefetch
|
||||||
href="/"
|
href="/"
|
||||||
class="icons tooltip tooltip-right tooltip-primary bg-coolgray-200 hover:text-white"
|
class="icons tooltip tooltip-primary tooltip-right bg-coolgray-200 hover:text-white"
|
||||||
class:text-white={$page.url.pathname === '/'}
|
class:text-white={$page.url.pathname === '/'}
|
||||||
class:bg-coolgray-500={$page.url.pathname === '/'}
|
class:bg-coolgray-500={$page.url.pathname === '/'}
|
||||||
data-tip="Dashboard"
|
data-tip="Dashboard"
|
||||||
@ -245,7 +245,7 @@
|
|||||||
<a
|
<a
|
||||||
sveltekit:prefetch
|
sveltekit:prefetch
|
||||||
href="/databases"
|
href="/databases"
|
||||||
class="icons tooltip tooltip-primary tooltip-right bg-coolgray-200"
|
class="icons tooltip tooltip-primary tooltip-right bg-coolgray-200"
|
||||||
class:text-databases={$page.url.pathname.startsWith('/databases') ||
|
class:text-databases={$page.url.pathname.startsWith('/databases') ||
|
||||||
$page.url.pathname.startsWith('/new/database')}
|
$page.url.pathname.startsWith('/new/database')}
|
||||||
class:bg-coolgray-500={$page.url.pathname.startsWith('/databases') ||
|
class:bg-coolgray-500={$page.url.pathname.startsWith('/databases') ||
|
||||||
@ -271,7 +271,7 @@
|
|||||||
<a
|
<a
|
||||||
sveltekit:prefetch
|
sveltekit:prefetch
|
||||||
href="/services"
|
href="/services"
|
||||||
class="icons tooltip tooltip-primary tooltip-right bg-coolgray-200"
|
class="icons tooltip tooltip-primary tooltip-right bg-coolgray-200"
|
||||||
class:text-services={$page.url.pathname.startsWith('/services') ||
|
class:text-services={$page.url.pathname.startsWith('/services') ||
|
||||||
$page.url.pathname.startsWith('/new/service')}
|
$page.url.pathname.startsWith('/new/service')}
|
||||||
class:bg-coolgray-500={$page.url.pathname.startsWith('/services') ||
|
class:bg-coolgray-500={$page.url.pathname.startsWith('/services') ||
|
||||||
@ -300,7 +300,7 @@
|
|||||||
<a
|
<a
|
||||||
sveltekit:prefetch
|
sveltekit:prefetch
|
||||||
href="/iam"
|
href="/iam"
|
||||||
class="icons tooltip tooltip-primary tooltip-right bg-coolgray-200"
|
class="icons tooltip tooltip-primary tooltip-right bg-coolgray-200"
|
||||||
class:text-iam={$page.url.pathname.startsWith('/iam')}
|
class:text-iam={$page.url.pathname.startsWith('/iam')}
|
||||||
class:bg-coolgray-500={$page.url.pathname.startsWith('/iam')}
|
class:bg-coolgray-500={$page.url.pathname.startsWith('/iam')}
|
||||||
data-tip="IAM"
|
data-tip="IAM"
|
||||||
@ -324,7 +324,7 @@
|
|||||||
<a
|
<a
|
||||||
sveltekit:prefetch
|
sveltekit:prefetch
|
||||||
href={$appSession.teamId === '0' ? '/settings/global' : '/settings/ssh-keys'}
|
href={$appSession.teamId === '0' ? '/settings/global' : '/settings/ssh-keys'}
|
||||||
class="icons tooltip tooltip-primary tooltip-right bg-coolgray-200"
|
class="icons tooltip tooltip-primary tooltip-right bg-coolgray-200"
|
||||||
class:text-settings={$page.url.pathname.startsWith('/settings')}
|
class:text-settings={$page.url.pathname.startsWith('/settings')}
|
||||||
class:bg-coolgray-500={$page.url.pathname.startsWith('/settings')}
|
class:bg-coolgray-500={$page.url.pathname.startsWith('/settings')}
|
||||||
data-tip="Settings"
|
data-tip="Settings"
|
||||||
@ -348,7 +348,7 @@
|
|||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="icons tooltip tooltip-primary tooltip-right bg-coolgray-200 hover:text-error"
|
class="icons tooltip tooltip-primary tooltip-right bg-coolgray-200 hover:text-error"
|
||||||
data-tip="Logout"
|
data-tip="Logout"
|
||||||
on:click={logout}
|
on:click={logout}
|
||||||
>
|
>
|
||||||
|
@ -352,7 +352,7 @@
|
|||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
disabled={$disabledButton}
|
disabled={$disabledButton}
|
||||||
class="icons bg-transparent tooltip tooltip-bottom text-sm"
|
class="icons bg-transparent tooltip tooltip-primary tooltip-bottom text-sm"
|
||||||
data-tip="Secret"
|
data-tip="Secret"
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
@ -507,7 +507,7 @@
|
|||||||
type="submit"
|
type="submit"
|
||||||
disabled={!$appSession.isAdmin}
|
disabled={!$appSession.isAdmin}
|
||||||
class:hover:text-red-500={$appSession.isAdmin}
|
class:hover:text-red-500={$appSession.isAdmin}
|
||||||
class="icons bg-transparent tooltip tooltip-bottom text-sm"
|
class="icons bg-transparent tooltip tooltip-primary tooltip-bottom text-sm"
|
||||||
data-tip={$appSession.isAdmin
|
data-tip={$appSession.isAdmin
|
||||||
? $t('application.delete_application')
|
? $t('application.delete_application')
|
||||||
: $t('application.permission_denied_delete_application')}
|
: $t('application.permission_denied_delete_application')}
|
||||||
|
@ -249,7 +249,7 @@
|
|||||||
class:bg-coolgray-500={$page.url.pathname === `/databases/${id}`}
|
class:bg-coolgray-500={$page.url.pathname === `/databases/${id}`}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="icons bg-transparent tooltip tooltip-bottom text-sm disabled:text-red-500"
|
class="icons bg-transparent tooltip tooltip-primary tooltip-bottom text-sm disabled:text-red-500"
|
||||||
data-tip={$t('application.configurations')}
|
data-tip={$t('application.configurations')}
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
|
@ -125,6 +125,17 @@
|
|||||||
return errorNotification(error);
|
return errorNotification(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async function cleanupLogs() {
|
||||||
|
try {
|
||||||
|
await post(`/services/${id}/${service.type}/cleanup`, { id: service.id });
|
||||||
|
return addToast({
|
||||||
|
message: 'Cleared DB Logs',
|
||||||
|
type: 'success'
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return errorNotification(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if (browser && window.location.hostname === 'demo.coolify.io' && !service.fqdn) {
|
if (browser && window.location.hostname === 'demo.coolify.io' && !service.fqdn) {
|
||||||
service.fqdn = `http://${cuid()}.demo.coolify.io`;
|
service.fqdn = `http://${cuid()}.demo.coolify.io`;
|
||||||
@ -170,11 +181,14 @@
|
|||||||
>
|
>
|
||||||
{/if}
|
{/if}
|
||||||
{#if service.type === 'plausibleanalytics' && $status.service.isRunning}
|
{#if service.type === 'plausibleanalytics' && $status.service.isRunning}
|
||||||
<button on:click|preventDefault={setEmailsToVerified} disabled={loadingVerification}
|
<button class="btn btn-sm" on:click|preventDefault={setEmailsToVerified} disabled={loadingVerification}
|
||||||
>{loadingVerification
|
>{loadingVerification
|
||||||
? $t('forms.verifying')
|
? $t('forms.verifying')
|
||||||
: $t('forms.verify_emails_without_smtp')}</button
|
: $t('forms.verify_emails_without_smtp')}</button
|
||||||
>
|
>
|
||||||
|
<button class="btn btn-sm" on:click|preventDefault={cleanupLogs}
|
||||||
|
>Cleanup Unnecessary Database Logs</button
|
||||||
|
>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -91,11 +91,8 @@ label {
|
|||||||
@apply inline-block w-64 text-xs tracking-tight md:text-sm;
|
@apply inline-block w-64 text-xs tracking-tight md:text-sm;
|
||||||
}
|
}
|
||||||
.btn {
|
.btn {
|
||||||
@apply text-white tracking-tighter;
|
@apply text-white text-base;
|
||||||
}
|
}
|
||||||
/*button, .button {
|
|
||||||
@apply rounded bg-coolgray-200 p-2 px-3 text-sm outline-none transition-all duration-100 hover:bg-coolgray-500 disabled:cursor-not-allowed disabled:bg-coolblack disabled:text-stone-600;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
a {
|
a {
|
||||||
@apply underline hover:text-white;
|
@apply underline hover:text-white;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user