Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
98b4074c
Commit
98b4074c
authored
Nov 17, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring: minor refactor of clean up dashboard history PR #9882
parent
aaa465a1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
32 deletions
+32
-32
conf/defaults.ini
+3
-3
conf/sample.ini
+1
-2
pkg/services/cleanup/cleanup.go
+1
-1
pkg/services/sqlstore/dashboard_version.go
+27
-26
No files found.
conf/defaults.ini
View file @
98b4074c
...
...
@@ -187,10 +187,10 @@ snapshot_remove_expired = true
# remove snapshots after 90 days
snapshot_TTL_days
=
90
#################################### Dashboards History ##################
#################################### Dashboards ##################
[dashboards]
# A setting of 20 (default) means only the last 20 versions will be stored and older versions removed.
# To keep all dashboard versions you can set this value to 2147483647.
# Number dashboard versions to keep (per dashboard). Default: 20, Minimum: 1
versions_to_keep
=
20
#################################### Users ###############################
...
...
conf/sample.ini
View file @
98b4074c
...
...
@@ -177,8 +177,7 @@ log_queries =
#################################### Dashboards History ##################
[dashboards]
# A setting of 20 (default) means only the last 20 versions will be stored and older versions removed.
# To keep all dashboard versions you can set this value to 2147483647.
# Number dashboard versions to keep (per dashboard). Default: 20, Minimum: 1
;versions_to_keep = 20
#################################### Users ###############################
...
...
pkg/services/cleanup/cleanup.go
View file @
98b4074c
...
...
@@ -39,7 +39,7 @@ func (service *CleanUpService) Run(ctx context.Context) error {
func
(
service
*
CleanUpService
)
start
(
ctx
context
.
Context
)
error
{
service
.
cleanUpTmpFiles
()
ticker
:=
time
.
NewTicker
(
time
.
Hour
*
1
)
ticker
:=
time
.
NewTicker
(
time
.
Minute
*
10
)
for
{
select
{
case
<-
ticker
.
C
:
...
...
pkg/services/sqlstore/dashboard_version.go
View file @
98b4074c
package
sqlstore
import
(
"math"
"strings"
"github.com/grafana/grafana/pkg/bus"
...
...
@@ -66,37 +65,39 @@ func GetDashboardVersions(query *m.GetDashboardVersionsQuery) error {
func
DeleteExpiredVersions
(
cmd
*
m
.
DeleteExpiredVersionsCommand
)
error
{
return
inTransaction
(
func
(
sess
*
DBSession
)
error
{
var
expiredCount
int64
=
0
var
versions
[]
DashboardVersionExp
// Don't clean up if user set versions_to_keep to 2147483647 (MaxInt32)
if
versionsToKeep
:=
setting
.
DashboardVersionsToKeep
;
versionsToKeep
<
math
.
MaxInt32
{
err
:=
sess
.
Table
(
"dashboard_version"
)
.
Select
(
"dashboard_version.id, dashboard_version.version, dashboard_version.dashboard_id"
)
.
Where
(
`dashboard_id IN (
SELECT dashboard_id FROM dashboard_version
GROUP BY dashboard_id HAVING COUNT(dashboard_version.id) > ?
)`
,
versionsToKeep
)
.
Desc
(
"dashboard_version.dashboard_id"
,
"dashboard_version.version"
)
.
Find
(
&
versions
)
expiredCount
:=
int64
(
0
)
versions
:=
[]
DashboardVersionExp
{}
versionsToKeep
:=
setting
.
DashboardVersionsToKeep
if
versionsToKeep
<
1
{
versionsToKeep
=
1
}
err
:=
sess
.
Table
(
"dashboard_version"
)
.
Select
(
"dashboard_version.id, dashboard_version.version, dashboard_version.dashboard_id"
)
.
Where
(
`dashboard_id IN (
SELECT dashboard_id FROM dashboard_version
GROUP BY dashboard_id HAVING COUNT(dashboard_version.id) > ?
)`
,
versionsToKeep
)
.
Desc
(
"dashboard_version.dashboard_id"
,
"dashboard_version.version"
)
.
Find
(
&
versions
)
if
err
!=
nil
{
return
err
}
// Keep last versionsToKeep versions and delete other
versionIdsToDelete
:=
getVersionIDsToDelete
(
versions
,
versionsToKeep
)
if
len
(
versionIdsToDelete
)
>
0
{
deleteExpiredSql
:=
`DELETE FROM dashboard_version WHERE id IN (?`
+
strings
.
Repeat
(
",?"
,
len
(
versionIdsToDelete
)
-
1
)
+
`)`
expiredResponse
,
err
:=
sess
.
Exec
(
deleteExpiredSql
,
versionIdsToDelete
...
)
if
err
!=
nil
{
return
err
}
// Keep last versionsToKeep versions and delete other
versionIdsToDelete
:=
getVersionIDsToDelete
(
versions
,
versionsToKeep
)
if
len
(
versionIdsToDelete
)
>
0
{
deleteExpiredSql
:=
`DELETE FROM dashboard_version WHERE id IN (?`
+
strings
.
Repeat
(
",?"
,
len
(
versionIdsToDelete
)
-
1
)
+
`)`
expiredResponse
,
err
:=
sess
.
Exec
(
deleteExpiredSql
,
versionIdsToDelete
...
)
if
err
!=
nil
{
return
err
}
expiredCount
,
_
=
expiredResponse
.
RowsAffected
()
}
expiredCount
,
_
=
expiredResponse
.
RowsAffected
()
sqlog
.
Debug
(
"Deleted old/expired dashboard versions"
,
"expired"
,
expiredCount
)
}
sqlog
.
Debug
(
"Deleted old/expired dashboard versions"
,
"expired"
,
expiredCount
)
return
nil
})
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment