Snapshots: Add snapshot enable config (#61587)

* Add config to remove Snapshot functionality (frontend is hidden and validation in the backend)
* Add test cases
* Remove unused mock on the test
* Moving Snapshot config from globar variables to settings.Cfg
* Removing warnings on code
This commit is contained in:
lean.dev
2023-01-26 10:28:11 -03:00
committed by GitHub
parent 928e2c9c9e
commit 7d8ec6199d
14 changed files with 191 additions and 99 deletions
@@ -15,13 +15,14 @@ import (
type DashboardSnapshotStore struct {
store db.DB
log log.Logger
cfg *setting.Cfg
}
// DashboardStore implements the Store interface
var _ dashboardsnapshots.Store = (*DashboardSnapshotStore)(nil)
func ProvideStore(db db.DB) *DashboardSnapshotStore {
return &DashboardSnapshotStore{store: db, log: log.New("dashboardsnapshot.store")}
func ProvideStore(db db.DB, cfg *setting.Cfg) *DashboardSnapshotStore {
return &DashboardSnapshotStore{store: db, log: log.New("dashboardsnapshot.store"), cfg: cfg}
}
// DeleteExpiredSnapshots removes snapshots with old expiry dates.
@@ -29,7 +30,7 @@ func ProvideStore(db db.DB) *DashboardSnapshotStore {
// Snapshot expiry is decided by the user when they share the snapshot.
func (d *DashboardSnapshotStore) DeleteExpiredSnapshots(ctx context.Context, cmd *dashboardsnapshots.DeleteExpiredSnapshotsCommand) error {
return d.store.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
if !setting.SnapShotRemoveExpired {
if !d.cfg.SnapShotRemoveExpired {
d.log.Warn("[Deprecated] The snapshot_remove_expired setting is outdated. Please remove from your config.")
return nil
}