diff --git a/conf/defaults.ini b/conf/defaults.ini index e1acf689bb5..b3a459c7df1 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -1422,6 +1422,11 @@ concurrent_query_limit = # Enable the Query history 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. +expire_time = 7 + #################################### Internal Grafana Metrics ############ # Metrics available at HTTP URL /metrics and /metrics/plugins/:pluginId [metrics] diff --git a/docs/sources/explore/_index.md b/docs/sources/explore/_index.md index 640c9785aa2..2d9a88253dc 100644 --- a/docs/sources/explore/_index.md +++ b/docs/sources/explore/_index.md @@ -137,7 +137,7 @@ Available in Grafana 7.3 and later versions. The Share shortened link capability allows you to create smaller and simpler URLs of the format /goto/:uid instead of using longer URLs with query parameters. To create a shortened link to the executed query, click the **Share** option in the Explore toolbar. -A shortened link will automatically get deleted after seven (7) days from its creation if it's never used. If a link is used at least once, it won't ever get deleted. +A shortened link that is not accessed will automatically get deleted after a [configurable period](https://grafana.com/docs/grafana//setup-grafana/configure-grafana/#short_links) (defaulting to seven days). If a link is used at least once, it won't be deleted. ### Sharing shortened links with absolute time diff --git a/docs/sources/setup-grafana/configure-grafana/_index.md b/docs/sources/setup-grafana/configure-grafana/_index.md index 114f1ae6bd7..0cbd5fa157a 100644 --- a/docs/sources/setup-grafana/configure-grafana/_index.md +++ b/docs/sources/setup-grafana/configure-grafana/_index.md @@ -1779,6 +1779,16 @@ Enable or disable the Query history. Default is `enabled`.
+## [short_links] + +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. + +
+ ## [metrics] For detailed instructions, refer to [Internal Grafana metrics]({{< relref "../set-up-grafana-monitoring" >}}). diff --git a/pkg/services/cleanup/cleanup.go b/pkg/services/cleanup/cleanup.go index 3b1a2c5e201..46037db3b4e 100644 --- a/pkg/services/cleanup/cleanup.go +++ b/pkg/services/cleanup/cleanup.go @@ -257,7 +257,7 @@ func (srv *CleanUpService) expireOldVerifications(ctx context.Context) { func (srv *CleanUpService) deleteStaleShortURLs(ctx context.Context) { logger := srv.log.FromContext(ctx) cmd := shorturls.DeleteShortUrlCommand{ - OlderThan: time.Now().Add(-time.Hour * 24 * 7), + OlderThan: time.Now().Add(-time.Duration(srv.Cfg.ShortLinkExpiration*24) * time.Hour), } if err := srv.ShortURLService.DeleteStaleShortURLs(ctx, &cmd); err != nil { logger.Error("Problem deleting stale short urls", "error", err.Error()) diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index ed864575f6d..478d28afdcf 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -516,6 +516,9 @@ type Cfg struct { // Experimental scope settings ScopesListScopesURL string ScopesListDashboardsURL string + + //Short Links + ShortLinkExpiration int } // AddChangePasswordLink returns if login form is disabled or not since @@ -1158,6 +1161,14 @@ func (cfg *Cfg) parseINIFile(iniFile *ini.File) error { queryHistory := iniFile.Section("query_history") cfg.QueryHistoryEnabled = queryHistory.Key("enabled").MustBool(true) + shortLinks := iniFile.Section("short_links") + cfg.ShortLinkExpiration = shortLinks.Key("expire_time").MustInt(7) + + if cfg.ShortLinkExpiration > 365 { + cfg.Logger.Warn("short_links expire_time must be less than 366 days. Setting to 365 days") + cfg.ShortLinkExpiration = 365 + } + panelsSection := iniFile.Section("panels") cfg.DisableSanitizeHtml = panelsSection.Key("disable_sanitize_html").MustBool(false)