Add spec and test for monitoring
This commit is contained in:
parent
2fb682e94b
commit
c18a4c9a8b
2 changed files with 51 additions and 9 deletions
|
@ -1 +1,45 @@
|
|||
(ns dda.backup.monitoring.domain)
|
||||
(ns dda.backup.monitoring.domain
|
||||
(:require
|
||||
[dda.backup.restic.domain :as rd]
|
||||
[orchestra.core :refer [defn-spec]]
|
||||
[clojure.spec.alpha :as s]))
|
||||
|
||||
(s/def ::type #{"gauge"})
|
||||
(s/def ::labels map?)
|
||||
(s/def ::metric-value pos?)
|
||||
(s/def ::metric-element (s/keys :req-un [::labels ::metric-value]))
|
||||
(s/def ::value (s/+ ::metric-element))
|
||||
(s/def ::metric (s/keys :req-un [::type
|
||||
::value]))
|
||||
(s/def ::backup-size (s/spec ::metric-value))
|
||||
|
||||
(s/def ::docstring string?)
|
||||
(s/def ::__name__ string?)
|
||||
(s/def ::baseLabels (s/keys :req-un [::__name__]))
|
||||
|
||||
(s/def ::monitoring-data (s/keys :req-un [::baseLabels
|
||||
::docstring
|
||||
::metric]))
|
||||
|
||||
(s/def ::monitoring-data-seq (s/+ ::monitoring-data))
|
||||
|
||||
(s/def ::fqdn string?)
|
||||
|
||||
|
||||
(s/def ::monitoring-config
|
||||
(s/keys :req-un [::fqdn
|
||||
::backup-size
|
||||
::rd/restic-repository
|
||||
::rd/backup-path]))
|
||||
|
||||
(defn-spec monitoring-data ::monitoring-data-seq
|
||||
[config ::monitoring-config]
|
||||
(let [{:keys [fqdn backup-size restic-repository backup-path]} config]
|
||||
[{:baseLabels {:__name__ "backup_size"},
|
||||
:docstring "Backup size in MB",
|
||||
:metric {:type "gauge",
|
||||
:value [{:labels
|
||||
{:app_name "c4k-forgejo"
|
||||
:fqdn fqdn
|
||||
:restic_repo (str restic-repository "/" backup-path)},
|
||||
:value backup-size}]}}]))
|
|
@ -4,19 +4,17 @@
|
|||
[clojure.spec.test.alpha :as st]
|
||||
[dda.backup.monitoring.domain :as cut]))
|
||||
|
||||
(deftest should-calculate-backup-files-command
|
||||
(deftest should-generate-monitoring-data
|
||||
(is (= [{:baseLabels {:__name__ "backup_size"},
|
||||
:docstring "Backup size in MB",
|
||||
:metric {:type "gauge",
|
||||
:value [{:labels
|
||||
{:app_name "c4k-forgejo"
|
||||
:fqdn "repo.prod.meissa.de"
|
||||
:restic_repo "s3://..."},
|
||||
:restic_repo "repo/dir-at-repo"},
|
||||
:value 123}]}}]
|
||||
(cut/backup-files-command {:restic-repository "repo"
|
||||
:backup-path "dir-at-repo"
|
||||
:execution-directory "dir-to-backup"
|
||||
:days-to-keep 39
|
||||
:months-to-keep 3
|
||||
:files ["file2" "file2"]}))))
|
||||
(cut/monitoring-data {:fqdn "repo.prod.meissa.de"
|
||||
:restic-repository "repo"
|
||||
:backup-path "dir-at-repo"
|
||||
:backup-size 123}))))
|
||||
|
||||
|
|
Loading…
Reference in a new issue