PostgreSQL backup tool with Point-In-Time-Recovery and restore verification
TypeScript backupbackupsdatabasedatabase-backupdevopsdockergolangkubernetesmariadbmongodbmysqlpgpostgrespostgresqls3self-hostedsystem-administrationtoolsweb-ui
FIX (healthcheck): Fix heathcheck failed attempts for the agent (#538)
Rostislav Duginf10fb81d67d7
diff --git a/backend/internal/features/healthcheck/config/controller_test.go b/backend/internal/features/healthcheck/config/controller_test.goindex 235f5ca7..adc608f5 100644--- a/backend/internal/features/healthcheck/config/controller_test.go+++ b/backend/internal/features/healthcheck/config/controller_test.go@@ -10,6 +10,7 @@ import ("github.com/stretchr/testify/assert""databasus-backend/internal/features/databases"+ "databasus-backend/internal/features/databases/databases/postgresql"users_enums "databasus-backend/internal/features/users/enums"users_testing "databasus-backend/internal/features/users/testing"workspaces_controllers "databasus-backend/internal/features/workspaces/controllers"@@ -313,6 +314,52 @@ func Test_GetHealthcheckConfig_ReturnsDefaultConfigForNewDatabase(t *testing.T)workspaces_testing.RemoveTestWorkspace(workspace, router)}+func Test_SaveHealthcheckConfig_WhenDatabaseIsAgentManaged_BlocksEnable(t *testing.T) {+ router := createTestRouter()+ owner := users_testing.CreateTestUser(users_enums.UserRoleMember)+ workspace := workspaces_testing.CreateTestWorkspace("Test Workspace", owner, router)++ database := createTestWalDatabaseViaAPI("Test WAL Database", workspace.ID, owner.Token, router)++ enableRequest := HealthcheckConfigDTO{+ DatabaseID: database.ID,+ IsHealthcheckEnabled: true,+ IsSentNotificationWhenUnavailable: true,+ IntervalMinutes: 5,+ AttemptsBeforeConcideredAsDown: 3,+ StoreAttemptsDays: 7,+ }++ enableResp := test_utils.MakePostRequest(+ t,+ router,+ "/api/v1/healthcheck-config",+ "Bearer "+owner.Token,+ enableRequest,+ http.StatusBadRequest,+ )+ assert.Contains(t, string(enableResp.Body), "agent-managed")++ disableRequest := enableRequest+ disableRequest.IsHealthcheckEnabled = false++ var disableResp map[string]string+ test_utils.MakePostRequestAndUnmarshal(+ t,+ router,+ "/api/v1/healthcheck-config",+ "Bearer "+owner.Token,+ disableRequest,+ http.StatusOK,+ &disableResp,+ )+ assert.Contains(t, disableResp["message"], "successfully")++ // Cleanup+ databases.RemoveTestDatabase(database)+ workspaces_testing.RemoveTestWorkspace(workspace, router)+}+func createTestDatabaseViaAPI(name string,workspaceID uuid.UUID,@@ -344,3 +391,38 @@ func createTestDatabaseViaAPI(}return &database}++func createTestWalDatabaseViaAPI(+ name string,+ workspaceID uuid.UUID,+ token string,+ router *gin.Engine,+) *databases.Database {+ request := databases.Database{+ WorkspaceID: &workspaceID,+ Name: name,+ Type: databases.DatabaseTypePostgres,+ Postgresql: &postgresql.PostgresqlDatabase{+ BackupType: postgresql.PostgresBackupTypeWalV1,+ CpuCount: 1,+ },+ }++ w := workspaces_testing.MakeAPIRequest(+ router,+ "POST",+ "/api/v1/databases/create",+ "Bearer "+token,+ request,+ )++ if w.Code != http.StatusCreated {+ panic("Failed to create WAL database")+ }++ var database databases.Database+ if err := json.Unmarshal(w.Body.Bytes(), &database); err != nil {+ panic(err)+ }+ return &database+}diff --git a/backend/internal/features/healthcheck/config/service.go b/backend/internal/features/healthcheck/config/service.goindex d6b3194a..e318bd98 100644--- a/backend/internal/features/healthcheck/config/service.go+++ b/backend/internal/features/healthcheck/config/service.go@@ -51,6 +51,10 @@ func (s *HealthcheckConfigService) Save(return errors.New("insufficient permissions to modify healthcheck config")}+ if database.IsAgentManagedBackup() && configDTO.IsHealthcheckEnabled {+ return errors.New("healthcheck cannot be enabled for agent-managed databases")+ }+healthcheckConfig := configDTO.ToDTO()s.logger.Info("healthcheck config", "config", healthcheckConfig)diff --git a/backend/migrations/20260512000000_disable_healthcheck_for_agent_dbs.sql b/backend/migrations/20260512000000_disable_healthcheck_for_agent_dbs.sqlnew file mode 100644index 00000000..fb7daeb3--- /dev/null+++ b/backend/migrations/20260512000000_disable_healthcheck_for_agent_dbs.sql@@ -0,0 +1,25 @@+-- +goose Up+-- +goose StatementBegin+UPDATE healthcheck_configs+SET is_healthcheck_enabled = FALSE+WHERE database_id IN (+ SELECT pd.database_id+ FROM postgresql_databases pd+ WHERE pd.backup_type = 'WAL_V1'+);++UPDATE databases+SET health_status = NULL+WHERE id IN (+ SELECT pd.database_id+ FROM postgresql_databases pd+ WHERE pd.backup_type = 'WAL_V1'+);+-- +goose StatementEnd++-- +goose Down+-- +goose StatementBegin+-- No-op: rolling this back would silently re-enable healthchecks+-- that are guaranteed to fail for agent-managed (WAL_V1) databases.+SELECT 1;+-- +goose StatementEnddiff --git a/frontend/src/features/databases/ui/DatabaseComponent.tsx b/frontend/src/features/databases/ui/DatabaseComponent.tsxindex a5721a00..8123c329 100644--- a/frontend/src/features/databases/ui/DatabaseComponent.tsx+++ b/frontend/src/features/databases/ui/DatabaseComponent.tsx@@ -130,14 +130,16 @@ export const DatabaseComponent = ({{currentTab === 'backups' && (<>- <HealthckeckAttemptsComponent- database={database}- onVisibilityChange={handleHealthcheckVisibilityChange}- />+ {!isWalDatabase && (+ <HealthckeckAttemptsComponent+ database={database}+ onVisibilityChange={handleHealthcheckVisibilityChange}+ />+ )}<BackupsComponentdatabase={database}isCanManageDBs={isCanManageDBs}- isDirectlyUnderTab={!isHealthcheckVisible}+ isDirectlyUnderTab={isWalDatabase || !isHealthcheckVisible}scrollContainerRef={scrollContainerRef}onNavigateToBilling={() => setCurrentTab('billing')}/>diff --git a/frontend/src/features/databases/ui/DatabaseConfigComponent.tsx b/frontend/src/features/databases/ui/DatabaseConfigComponent.tsxindex 824a49af..a3a3e8f2 100644--- a/frontend/src/features/databases/ui/DatabaseConfigComponent.tsx+++ b/frontend/src/features/databases/ui/DatabaseConfigComponent.tsx@@ -9,7 +9,7 @@ import { Button, Input } from 'antd';import { useEffect, useState } from 'react';import { backupConfigApi } from '../../../entity/backups';-import { type Database, databaseApi } from '../../../entity/databases';+import { type Database, PostgresBackupType, databaseApi } from '../../../entity/databases';import type { UserProfile } from '../../../entity/users';import { ToastHelper } from '../../../shared/toast';import { ConfirmationComponent } from '../../../shared/ui';@@ -168,6 +168,8 @@ export const DatabaseConfigComponent = ({});};+ const isWalDatabase = database.postgresql?.backupType === PostgresBackupType.WAL_V1;+return (<div className="relative w-full rounded-tr-md rounded-br-md rounded-bl-md bg-white p-3 shadow sm:p-5 dark:bg-gray-800">{isRemoving && (@@ -334,33 +336,38 @@ export const DatabaseConfigComponent = ({</div><div className="flex flex-col gap-6 lg:flex-row lg:flex-wrap lg:gap-10">- <div className="w-full lg:w-[400px]">- <div className="mt-5 flex items-center font-bold">- <div>Healthcheck settings</div>-- {!isEditHealthcheckSettings && isCanManageDBs ? (- <div className="ml-2 h-4 w-4 cursor-pointer" onClick={() => startEdit('healthcheck')}>- <img src="/icons/pen-gray.svg" />- </div>- ) : (- <div />- )}- </div>+ {!isWalDatabase && (+ <div className="w-full lg:w-[400px]">+ <div className="mt-5 flex items-center font-bold">+ <div>Healthcheck settings</div>++ {!isEditHealthcheckSettings && isCanManageDBs ? (+ <div+ className="ml-2 h-4 w-4 cursor-pointer"+ onClick={() => startEdit('healthcheck')}+ >+ <img src="/icons/pen-gray.svg" />+ </div>+ ) : (+ <div />+ )}+ </div>- <div className="mt-1 text-sm">- {isEditHealthcheckSettings ? (- <EditHealthcheckConfigComponent- databaseId={database.id}- onClose={() => {- setIsEditHealthcheckSettings(false);- loadSettings();- }}- />- ) : (- <ShowHealthcheckConfigComponent databaseId={database.id} />- )}+ <div className="mt-1 text-sm">+ {isEditHealthcheckSettings ? (+ <EditHealthcheckConfigComponent+ databaseId={database.id}+ onClose={() => {+ setIsEditHealthcheckSettings(false);+ loadSettings();+ }}+ />+ ) : (+ <ShowHealthcheckConfigComponent databaseId={database.id} />+ )}+ </div></div>- </div>+ )}<div className="w-full lg:w-[400px]"><div className="mt-5 flex items-center font-bold">