From 435c627afd9dba6a05eeef81a10339146b145a3f Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sat, 17 Sep 2022 10:30:00 +0200 Subject: [PATCH] :sparkles: Make the audit log gc more agressive --- backend/src/app/config.clj | 2 -- backend/src/app/loggers/audit.clj | 21 ++++++++------------- backend/src/app/main.clj | 5 ++--- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/backend/src/app/config.clj b/backend/src/app/config.clj index e5ea68123..25bbe3bf0 100644 --- a/backend/src/app/config.clj +++ b/backend/src/app/config.clj @@ -94,7 +94,6 @@ (s/def ::telemetry-enabled ::us/boolean) (s/def ::audit-log-archive-uri ::us/string) -(s/def ::audit-log-gc-max-age ::dt/duration) (s/def ::admins ::us/set-of-strings) (s/def ::file-change-snapshot-every ::us/integer) @@ -212,7 +211,6 @@ ::admins ::allow-demo-users ::audit-log-archive-uri - ::audit-log-gc-max-age ::auth-token-cookie-name ::auth-token-cookie-max-age ::authenticated-cookie-name diff --git a/backend/src/app/loggers/audit.clj b/backend/src/app/loggers/audit.clj index ac9de126b..477217aa7 100644 --- a/backend/src/app/loggers/audit.clj +++ b/backend/src/app/loggers/audit.clj @@ -264,7 +264,7 @@ (let [n (archive-events cfg)] (if n (do - (aa/thread-sleep 200) + (aa/thread-sleep 100) (recur (+ total n))) (when (pos? total) (l/trace :hint "events chunk archived" :num total))))))))) @@ -345,23 +345,18 @@ (def sql:clean-archived "delete from audit_log - where archived_at is not null - and archived_at < now() - ?::interval") + where archived_at is not null") (defn- clean-archived - [{:keys [pool max-age]}] - (let [interval (db/interval max-age) - result (db/exec-one! pool [sql:clean-archived interval]) - result (:next.jdbc/update-count result)] - (l/debug :action "clean archived audit log" :removed result) + [{:keys [pool]}] + (let [result (db/exec-one! pool [sql:clean-archived]) + result (:next.jdbc/update-count result)] + (l/debug :hint "delete archived audit log entries" :deleted result) result)) -(s/def ::max-age ::cf/audit-log-gc-max-age) - (defmethod ig/pre-init-spec ::gc-task [_] - (s/keys :req-un [::db/pool ::max-age])) + (s/keys :req-un [::db/pool])) (defmethod ig/init-key ::gc-task [_ cfg] - (fn [_] - (clean-archived cfg))) + (partial clean-archived cfg)) diff --git a/backend/src/app/main.clj b/backend/src/app/main.clj index da3ff106c..f29871817 100644 --- a/backend/src/app/main.clj +++ b/backend/src/app/main.clj @@ -318,8 +318,7 @@ :http-client (ig/ref :app.http/client)} :app.loggers.audit/gc-task - {:max-age (cf/get :audit-log-gc-max-age cf/deletion-delay) - :pool (ig/ref :app.db/pool)} + {:pool (ig/ref :app.db/pool)} :app.loggers.loki/reporter {:uri (cf/get :loggers-loki-uri) @@ -395,7 +394,7 @@ :task :audit-log-archive}) (when (contains? cf/flags :audit-log-gc) - {:cron #app/cron "0 0 0 * * ?" ;; daily + {:cron #app/cron "30 */5 * * * ?" ;; every 5m :task :audit-log-gc})]} :app.worker/worker