From 0a255ac5fb24ebb3271df0a0ede5f03f98d31604 Mon Sep 17 00:00:00 2001 From: Igor Date: Wed, 16 Oct 2024 10:36:54 +0200 Subject: [PATCH] ShareInternally: Make stale short link expiry optional (#88137) Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com> Co-authored-by: Isabel Matwawana <76437239+imatwawana@users.noreply.github.com> Co-authored-by: Irene Rodriguez Co-authored-by: Jack Baldry --- conf/defaults.ini | 3 ++- docs/sources/setup-grafana/configure-grafana/_index.md | 6 +++++- pkg/services/cleanup/cleanup.go | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index 8daf5ef4a88..b52599aab85 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -1559,7 +1559,8 @@ enabled = true #################################### Short Links ############################# [short_links] -# Short links which are never accessed will be deleted as cleanup. Time is in days. Default is 7 days. Max is 365. 0 means they will be deleted approximately every 10 minutes. +# Short links that are never accessed will be deleted as cleanup. Time is set up in days. The default is 7 days. Maximum value is 365. +# 0 means they will be deleted approximately every 10 minutes. A negative value (such as -1) will disable expiration. expire_time = 7 #################################### Internal Grafana Metrics ############ diff --git a/docs/sources/setup-grafana/configure-grafana/_index.md b/docs/sources/setup-grafana/configure-grafana/_index.md index de2e43e06c3..a623d95d122 100644 --- a/docs/sources/setup-grafana/configure-grafana/_index.md +++ b/docs/sources/setup-grafana/configure-grafana/_index.md @@ -1872,7 +1872,11 @@ Configures settings around the short link feature. ### expire_time -Short links which are never accessed are considered expired or stale, and will be deleted as cleanup. Set the expiration time in days. Default is `7` days. Maximum is `365` days, and setting above the maximum will have `365` set instead. Setting `0` means the short links will be cleaned up approximately every 10 minutes. +Short links that are never accessed are considered expired or stale and will be deleted as cleanup. Set the expiration time in days. The default is `7` days. The maximum is `365` days, and setting above the maximum will have `365` set instead. Setting `0` means the short links will be cleaned up approximately every 10 minutes. A negative value such as `-1` will disable expiry. + +{{< admonition type="caution" >}} +Short links without an expiration increase the size of the database and can’t be deleted. +{{< /admonition >}}
diff --git a/pkg/services/cleanup/cleanup.go b/pkg/services/cleanup/cleanup.go index 7604a402017..240bcf532fd 100644 --- a/pkg/services/cleanup/cleanup.go +++ b/pkg/services/cleanup/cleanup.go @@ -103,12 +103,15 @@ func (srv *CleanUpService) clean(ctx context.Context) { {"delete expired images", srv.deleteExpiredImages}, {"cleanup old annotations", srv.cleanUpOldAnnotations}, {"expire old user invites", srv.expireOldUserInvites}, - {"delete stale short URLs", srv.deleteStaleShortURLs}, {"delete stale query history", srv.deleteStaleQueryHistory}, {"expire old email verifications", srv.expireOldVerifications}, {"cleanup trash dashboards", srv.cleanUpTrashDashboards}, } + if srv.Cfg.ShortLinkExpiration > 0 { + cleanupJobs = append(cleanupJobs, cleanUpJob{"delete stale short URLs", srv.deleteStaleShortURLs}) + } + logger := srv.log.FromContext(ctx) logger.Debug("Starting cleanup jobs", "jobs", fmt.Sprintf("%v", cleanupJobs))