Skip to content

Commit 67505f3

Browse files
FEATURE (healthcheck): Add databases healthcheck
1 parent 1b2acbc commit 67505f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2621
-388
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div align="center">
22
<img src="assets/logo.svg" alt="Postgresus Logo" width="250"/>
33

4-
<h3>PostgreSQL backup and restore tool</h3>
5-
<p>Free, open source and self-hosted solution for automated PostgreSQL backups with multiple storage options and notifications</p>
4+
<h3>PostgreSQL monitoring and backup</h3>
5+
<p>Free, open source and self-hosted solution for automated PostgreSQL monitoring and backups with multiple storage options and notifications</p>
66

77
<p>
88
<a href="#-features">Features</a> •

backend/.env.development.example

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,18 @@ DATABASE_URL=postgres://postgres:Q1234567@dev-db:5437/postgresus?sslmode=disable
1010
# migrations
1111
GOOSE_DRIVER=postgres
1212
GOOSE_DBSTRING=postgres://postgres:Q1234567@dev-db:5437/postgresus?sslmode=disable
13-
GOOSE_MIGRATION_DIR=./migrations
13+
GOOSE_MIGRATION_DIR=./migrations
14+
# testing
15+
# to get Google Drive env variables: add storage in UI and copy data from added storage here
16+
TEST_GOOGLE_DRIVE_CLIENT_ID=
17+
TEST_GOOGLE_DRIVE_CLIENT_SECRET=
18+
TEST_GOOGLE_DRIVE_TOKEN_JSON=
19+
# testing DBs
20+
TEST_POSTGRES_13_PORT=5001
21+
TEST_POSTGRES_14_PORT=5002
22+
TEST_POSTGRES_15_PORT=5003
23+
TEST_POSTGRES_16_PORT=5004
24+
TEST_POSTGRES_17_PORT=5005
25+
# testing S3
26+
TEST_MINIO_PORT=9000
27+
TEST_MINIO_CONSOLE_PORT=9001

backend/cmd/main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ import (
1717
"postgresus-backend/internal/features/backups"
1818
"postgresus-backend/internal/features/databases"
1919
"postgresus-backend/internal/features/disk"
20-
"postgresus-backend/internal/features/healthcheck"
20+
healthcheck_attempt "postgresus-backend/internal/features/healthcheck/attempt"
21+
healthcheck_config "postgresus-backend/internal/features/healthcheck/config"
2122
"postgresus-backend/internal/features/notifiers"
2223
"postgresus-backend/internal/features/restores"
2324
"postgresus-backend/internal/features/storages"
25+
system_healthcheck "postgresus-backend/internal/features/system/healthcheck"
2426
"postgresus-backend/internal/features/users"
2527
env_utils "postgresus-backend/internal/util/env"
2628
files_utils "postgresus-backend/internal/util/files"
@@ -129,7 +131,9 @@ func setUpRoutes(r *gin.Engine) {
129131
databaseController := databases.GetDatabaseController()
130132
backupController := backups.GetBackupController()
131133
restoreController := restores.GetRestoreController()
132-
healthcheckController := healthcheck.GetHealthcheckController()
134+
healthcheckController := system_healthcheck.GetHealthcheckController()
135+
healthcheckConfigController := healthcheck_config.GetHealthcheckConfigController()
136+
healthcheckAttemptController := healthcheck_attempt.GetHealthcheckAttemptController()
133137
diskController := disk.GetDiskController()
134138

135139
downdetectContoller.RegisterRoutes(v1)
@@ -141,10 +145,13 @@ func setUpRoutes(r *gin.Engine) {
141145
restoreController.RegisterRoutes(v1)
142146
healthcheckController.RegisterRoutes(v1)
143147
diskController.RegisterRoutes(v1)
148+
healthcheckConfigController.RegisterRoutes(v1)
149+
healthcheckAttemptController.RegisterRoutes(v1)
144150
}
145151

146152
func setUpDependencies() {
147153
backups.SetupDependencies()
154+
healthcheck_config.SetupDependencies()
148155
}
149156

150157
func runBackgroundTasks(log *slog.Logger) {
@@ -162,6 +169,10 @@ func runBackgroundTasks(log *slog.Logger) {
162169
go runWithPanicLogging(log, "restore background service", func() {
163170
restores.GetRestoreBackgroundService().Run()
164171
})
172+
173+
go runWithPanicLogging(log, "healthcheck attempt background service", func() {
174+
healthcheck_attempt.GetHealthcheckAttemptBackgroundService().RunBackgroundTasks()
175+
})
165176
}
166177

167178
func runWithPanicLogging(log *slog.Logger, serviceName string, fn func()) {

backend/docker-compose.yml.example

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,72 @@ services:
1717
- ./pgdata:/var/lib/postgresql/data
1818
container_name: dev-db
1919
command: -p 5437
20-
shm_size: 10gb
20+
shm_size: 10gb
21+
22+
# Test MinIO container
23+
test-minio:
24+
image: minio/minio:latest
25+
ports:
26+
- "${TEST_MINIO_PORT:-9000}:9000"
27+
- "${TEST_MINIO_CONSOLE_PORT:-9001}:9001"
28+
environment:
29+
- MINIO_ROOT_USER=testuser
30+
- MINIO_ROOT_PASSWORD=testpassword
31+
container_name: test-minio
32+
command: server /data --console-address ":9001"
33+
34+
# Test PostgreSQL containers
35+
test-postgres-13:
36+
image: postgres:13
37+
ports:
38+
- "${TEST_POSTGRES_13_PORT}:5432"
39+
environment:
40+
- POSTGRES_DB=testdb
41+
- POSTGRES_USER=testuser
42+
- POSTGRES_PASSWORD=testpassword
43+
container_name: test-postgres-13
44+
shm_size: 1gb
45+
46+
test-postgres-14:
47+
image: postgres:14
48+
ports:
49+
- "${TEST_POSTGRES_14_PORT}:5432"
50+
environment:
51+
- POSTGRES_DB=testdb
52+
- POSTGRES_USER=testuser
53+
- POSTGRES_PASSWORD=testpassword
54+
container_name: test-postgres-14
55+
shm_size: 1gb
56+
57+
test-postgres-15:
58+
image: postgres:15
59+
ports:
60+
- "${TEST_POSTGRES_15_PORT}:5432"
61+
environment:
62+
- POSTGRES_DB=testdb
63+
- POSTGRES_USER=testuser
64+
- POSTGRES_PASSWORD=testpassword
65+
container_name: test-postgres-15
66+
shm_size: 1gb
67+
68+
test-postgres-16:
69+
image: postgres:16
70+
ports:
71+
- "${TEST_POSTGRES_16_PORT}:5432"
72+
environment:
73+
- POSTGRES_DB=testdb
74+
- POSTGRES_USER=testuser
75+
- POSTGRES_PASSWORD=testpassword
76+
container_name: test-postgres-16
77+
shm_size: 1gb
78+
79+
test-postgres-17:
80+
image: postgres:17
81+
ports:
82+
- "${TEST_POSTGRES_17_PORT}:5432"
83+
environment:
84+
- POSTGRES_DB=testdb
85+
- POSTGRES_USER=testuser
86+
- POSTGRES_PASSWORD=testpassword
87+
container_name: test-postgres-17
88+
shm_size: 1gb

backend/go.mod

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module postgresus-backend
33
go 1.23.3
44

55
require (
6-
github.com/docker/go-connections v0.5.0
76
github.com/gin-contrib/cors v1.7.5
87
github.com/gin-gonic/gin v1.10.0
98
github.com/golang-jwt/jwt/v4 v4.5.2
@@ -19,7 +18,6 @@ require (
1918
github.com/swaggo/files v1.0.1
2019
github.com/swaggo/gin-swagger v1.6.0
2120
github.com/swaggo/swag v1.16.4
22-
github.com/testcontainers/testcontainers-go v0.37.0
2321
golang.org/x/crypto v0.39.0
2422
gorm.io/driver/postgres v1.5.11
2523
gorm.io/gorm v1.26.1
@@ -32,31 +30,20 @@ require (
3230
github.com/google/s2a-go v0.1.9 // indirect
3331
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
3432
github.com/googleapis/gax-go/v2 v2.14.2 // indirect
33+
google.golang.org/genproto/googleapis/api v0.0.0-20250528174236-200df99c418a // indirect
3534
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822 // indirect
3635
google.golang.org/grpc v1.73.0 // indirect
3736
)
3837

3938
require (
40-
dario.cat/mergo v1.0.2 // indirect
41-
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect
4239
github.com/BurntSushi/toml v1.5.0 // indirect
4340
github.com/KyleBanks/depth v1.2.1 // indirect
44-
github.com/Microsoft/go-winio v0.6.2 // indirect
4541
github.com/PuerkitoBio/purell v1.1.1 // indirect
4642
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
4743
github.com/bytedance/sonic v1.13.2 // indirect
4844
github.com/bytedance/sonic/loader v0.2.4 // indirect
49-
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
5045
github.com/cloudwego/base64x v0.1.5 // indirect
51-
github.com/containerd/errdefs v1.0.0 // indirect
52-
github.com/containerd/errdefs/pkg v0.3.0 // indirect
53-
github.com/containerd/log v0.1.0 // indirect
54-
github.com/containerd/platforms v0.2.1 // indirect
55-
github.com/cpuguy83/dockercfg v0.3.2 // indirect
5646
github.com/davecgh/go-spew v1.1.1 // indirect
57-
github.com/distribution/reference v0.6.0 // indirect
58-
github.com/docker/docker v28.2.2+incompatible // indirect
59-
github.com/docker/go-units v0.5.0 // indirect
6047
github.com/dustin/go-humanize v1.0.1 // indirect
6148
github.com/ebitengine/purego v0.8.4 // indirect
6249
github.com/felixge/httpsnoop v1.0.4 // indirect
@@ -75,7 +62,6 @@ require (
7562
github.com/go-playground/validator/v10 v10.26.0 // indirect
7663
github.com/go-sql-driver/mysql v1.9.2 // indirect
7764
github.com/goccy/go-json v0.10.5 // indirect
78-
github.com/gogo/protobuf v1.3.2 // indirect
7965
github.com/jackc/pgpassfile v1.0.0 // indirect
8066
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
8167
github.com/jackc/puddle/v2 v2.2.2 // indirect
@@ -86,47 +72,28 @@ require (
8672
github.com/klauspost/compress v1.18.0 // indirect
8773
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
8874
github.com/leodido/go-urn v1.4.0 // indirect
89-
github.com/lufia/plan9stats v0.0.0-20250317134145-8bc96cf8fc35 // indirect
90-
github.com/magiconair/properties v1.8.10 // indirect
9175
github.com/mailru/easyjson v0.7.6 // indirect
9276
github.com/mattn/go-isatty v0.0.20 // indirect
9377
github.com/minio/crc64nvme v1.0.1 // indirect
9478
github.com/minio/md5-simd v1.1.2 // indirect
95-
github.com/moby/docker-image-spec v1.3.1 // indirect
96-
github.com/moby/go-archive v0.1.0 // indirect
97-
github.com/moby/patternmatcher v0.6.0 // indirect
98-
github.com/moby/sys/atomicwriter v0.1.0 // indirect
99-
github.com/moby/sys/sequential v0.6.0 // indirect
100-
github.com/moby/sys/user v0.4.0 // indirect
101-
github.com/moby/sys/userns v0.1.0 // indirect
102-
github.com/moby/term v0.5.2 // indirect
10379
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
10480
github.com/modern-go/reflect2 v1.0.2 // indirect
105-
github.com/morikuni/aec v1.0.0 // indirect
106-
github.com/opencontainers/go-digest v1.0.0 // indirect
107-
github.com/opencontainers/image-spec v1.1.1 // indirect
10881
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
10982
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c // indirect
110-
github.com/pkg/errors v0.9.1 // indirect
11183
github.com/pmezard/go-difflib v1.0.0 // indirect
11284
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
11385
github.com/rogpeppe/go-internal v1.14.1 // indirect
11486
github.com/rs/xid v1.6.0 // indirect
115-
github.com/sirupsen/logrus v1.9.3 // indirect
11687
github.com/stretchr/objx v0.5.2 // indirect
11788
github.com/tinylib/msgp v1.3.0 // indirect
118-
github.com/tklauser/go-sysconf v0.3.15 // indirect
119-
github.com/tklauser/numcpus v0.10.0 // indirect
12089
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
12190
github.com/ugorji/go/codec v1.2.12 // indirect
12291
github.com/yusufpapurcu/wmi v1.2.4 // indirect
12392
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
12493
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
12594
go.opentelemetry.io/otel v1.36.0 // indirect
126-
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.36.0 // indirect
12795
go.opentelemetry.io/otel/metric v1.36.0 // indirect
12896
go.opentelemetry.io/otel/trace v1.36.0 // indirect
129-
go.opentelemetry.io/proto/otlp v1.7.0 // indirect
13097
golang.org/x/arch v0.17.0 // indirect
13198
golang.org/x/net v0.41.0 // indirect
13299
golang.org/x/oauth2 v0.30.0

0 commit comments

Comments
 (0)