Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-Core
Commits
eb80b193
Verified
Commit
eb80b193
authored
4 years ago
by
Tom Teichler
Browse files
Options
Downloads
Patches
Plain Diff
Add health checks for media and db backups. Closes
#378
parent
d23be3b6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!495
Resolve "Add health check for dbbackup"
Pipeline
#5958
passed
4 years ago
Stage: test
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
aleksis/core/apps.py
+9
-1
9 additions, 1 deletion
aleksis/core/apps.py
aleksis/core/health_checks.py
+58
-0
58 additions, 0 deletions
aleksis/core/health_checks.py
aleksis/core/settings.py
+2
-0
2 additions, 0 deletions
aleksis/core/settings.py
with
69 additions
and
1 deletion
aleksis/core/apps.py
+
9
−
1
View file @
eb80b193
...
...
@@ -53,9 +53,17 @@ class CoreConfig(AppConfig):
self
.
_load_data_checks
()
from
.health_checks
import
DataChecksHealthCheckBackend
from
.health_checks
import
(
BackupJobHealthCheck
,
DataChecksHealthCheckBackend
,
DbBackupAgeHealthCheck
,
MediaBackupAgeHealthCheck
,
)
plugin_dir
.
register
(
DataChecksHealthCheckBackend
)
plugin_dir
.
register
(
DbBackupAgeHealthCheck
)
plugin_dir
.
register
(
MediaBackupAgeHealthCheck
)
plugin_dir
.
register
(
BackupJobHealthCheck
)
@classmethod
def
_load_data_checks
(
cls
):
...
...
This diff is collapsed.
Click to expand it.
aleksis/core/health_checks.py
+
58
−
0
View file @
eb80b193
from
datetime
import
datetime
from
django.conf
import
settings
from
django.utils.translation
import
gettext
as
_
from
dbbackup
import
utils
as
dbbackup_utils
from
dbbackup.storage
import
get_storage
from
django_celery_results.models
import
TaskResult
from
health_check.backends
import
BaseHealthCheckBackend
from
aleksis.core.models
import
DataCheckResult
...
...
@@ -16,3 +22,55 @@ class DataChecksHealthCheckBackend(BaseHealthCheckBackend):
def
identifier
(
self
):
return
self
.
__class__
.
__name__
class
BaseBackupHealthCheck
(
BaseHealthCheckBackend
):
"""
Common base class for backup age checks.
"""
critical_service
=
False
def
check_status
(
self
):
storage
=
get_storage
()
last_backup
=
storage
.
list_backups
(
content_type
=
self
.
content_type
)[
-
1
]
last_backup_time
=
dbbackup_utils
.
filename_to_date
(
last_backup
)
time_gone_since_backup
=
last_backup_time
-
datetime
.
now
()
# Check if backup is older than configured time
if
time_gone_since_backup
.
seconds
>
settings
.
DBBACKUP_SECONDS
:
self
.
add_error
(
_
(
f
"
Last backup
{
time_gone_since_backup
}
!
"
))
class
DbBackupAgeHealthCheck
(
BaseBackupHealthCheck
):
"""
Checks if last backup file is less than configured seconds ago.
"""
content_type
=
"
db
"
def
identifier
(
self
):
return
self
.
__class__
.
__name__
class
MediaBackupAgeHealthCheck
(
BaseBackupHealthCheck
):
"""
Checks if last backup file is less than configured seconds ago.
"""
content_type
=
"
media
"
def
identifier
(
self
):
return
self
.
__class__
.
__name__
class
BackupJobHealthCheck
(
BaseHealthCheckBackend
):
"""
Checks if last backup file is less than configured seconds ago.
"""
critical_service
=
False
def
check_status
(
self
):
task
=
TaskResult
.
objects
.
filter
(
task_name
=
"
aleksis.core.tasks.backup_data
"
)
# Check if state is success
if
not
task
.
last
():
self
.
add_error
(
_
(
"
No backup result found!
"
))
if
task
.
last
()
and
task
.
last
().
status
!=
"
SUCCESS
"
:
self
.
add_error
(
_
(
f
"
{
task
.
last
().
status
}
-
{
task
.
last
().
result
}
"
))
def
identifier
(
self
):
return
self
.
__class__
.
__name__
This diff is collapsed.
Click to expand it.
aleksis/core/settings.py
+
2
−
0
View file @
eb80b193
...
...
@@ -730,4 +730,6 @@ HEALTH_CHECK = {
"
MEMORY_MIN
"
:
_settings
.
get
(
"
health.memory_min_mb
"
,
500
),
}
DBBACKUP_SECONDS
=
_settings
.
get
(
"
backup.seconds
"
,
7200
)
PROMETHEUS_EXPORT_MIGRATIONS
=
False
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment