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
516839d7
Commit
516839d7
authored
Jun 14, 2018
by
Anton Sergeyev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#11607 Cleanup time of temporary files is now configurable
parent
0cc8ccda
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
1 deletions
+70
-1
conf/defaults.ini
+3
-0
conf/sample.ini
+3
-0
docs/sources/installation/configuration.md
+5
-0
pkg/services/cleanup/cleanup.go
+11
-1
pkg/services/cleanup/cleanup_test.go
+42
-0
pkg/setting/setting.go
+6
-0
No files found.
conf/defaults.ini
View file @
516839d7
...
...
@@ -14,6 +14,9 @@ instance_name = ${HOSTNAME}
# Path to where grafana can store temp files, sessions, and the sqlite3 db (if that is used)
data
=
data
# Temporary files in `data` directory older than given duration will be removed
temp_data_lifetime
=
24h
# Directory where grafana can store logs
logs
=
data/log
...
...
conf/sample.ini
View file @
516839d7
...
...
@@ -14,6 +14,9 @@
# Path to where grafana can store temp files, sessions, and the sqlite3 db (if that is used)
;data = /var/lib/grafana
# Temporary files in `data` directory older than given duration will be removed
temp_data_lifetime
=
24h
# Directory where grafana can store logs
;logs = /var/log/grafana
...
...
docs/sources/installation/configuration.md
View file @
516839d7
...
...
@@ -80,6 +80,11 @@ Path to where Grafana stores the sqlite3 database (if used), file based
sessions (if used), and other data. This path is usually specified via
command line in the init.d script or the systemd service file.
### temp_data_lifetime
How long temporary images in
`data`
directory should be kept. Defaults to:
`24h`
. Supported modifiers:
`h`
(hours),
`m`
(minutes), for example:
`168h`
,
`30m`
,
`10h30m`
. Use
`0`
to never clean up temporary files.
### logs
Path to where Grafana will store logs. This path is usually specified via
...
...
pkg/services/cleanup/cleanup.go
View file @
516839d7
...
...
@@ -57,8 +57,10 @@ func (srv *CleanUpService) cleanUpTmpFiles() {
}
var
toDelete
[]
os
.
FileInfo
var
now
=
time
.
Now
()
for
_
,
file
:=
range
files
{
if
file
.
ModTime
()
.
AddDate
(
0
,
0
,
1
)
.
Before
(
time
.
Now
()
)
{
if
srv
.
shouldCleanupTempFile
(
file
.
ModTime
(),
now
)
{
toDelete
=
append
(
toDelete
,
file
)
}
}
...
...
@@ -74,6 +76,14 @@ func (srv *CleanUpService) cleanUpTmpFiles() {
srv
.
log
.
Debug
(
"Found old rendered image to delete"
,
"deleted"
,
len
(
toDelete
),
"keept"
,
len
(
files
))
}
func
(
srv
*
CleanUpService
)
shouldCleanupTempFile
(
filemtime
time
.
Time
,
now
time
.
Time
)
bool
{
if
srv
.
Cfg
.
TempDataLifetime
==
0
{
return
false
}
return
filemtime
.
Add
(
srv
.
Cfg
.
TempDataLifetime
)
.
Before
(
now
)
}
func
(
srv
*
CleanUpService
)
deleteExpiredSnapshots
()
{
cmd
:=
m
.
DeleteExpiredSnapshotsCommand
{}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
...
...
pkg/services/cleanup/cleanup_test.go
0 → 100644
View file @
516839d7
package
cleanup
import
(
"testing"
"github.com/grafana/grafana/pkg/setting"
.
"github.com/smartystreets/goconvey/convey"
"time"
)
func
TestCleanUpTmpFiles
(
t
*
testing
.
T
)
{
Convey
(
"Cleanup service tests"
,
t
,
func
()
{
cfg
:=
setting
.
Cfg
{}
cfg
.
TempDataLifetime
,
_
=
time
.
ParseDuration
(
"24h"
)
service
:=
CleanUpService
{
Cfg
:
&
cfg
,
}
now
:=
time
.
Now
()
secondAgo
:=
now
.
Add
(
-
time
.
Second
)
dayAgo
:=
now
.
Add
(
-
time
.
Second
*
3600
*
24
*
7
)
weekAgo
:=
now
.
Add
(
-
time
.
Second
*
3600
*
24
*
7
)
Convey
(
"Should not cleanup recent files"
,
func
()
{
So
(
service
.
shouldCleanupTempFile
(
secondAgo
,
now
),
ShouldBeFalse
);
})
Convey
(
"Should cleanup older files"
,
func
()
{
So
(
service
.
shouldCleanupTempFile
(
dayAgo
,
now
),
ShouldBeTrue
);
})
Convey
(
"After increasing temporary files lifetime, older files should be kept"
,
func
()
{
cfg
.
TempDataLifetime
,
_
=
time
.
ParseDuration
(
"1000h"
)
So
(
service
.
shouldCleanupTempFile
(
weekAgo
,
now
),
ShouldBeFalse
);
})
Convey
(
"If lifetime is 0, files should never be cleaned up"
,
func
()
{
cfg
.
TempDataLifetime
=
0
So
(
service
.
shouldCleanupTempFile
(
weekAgo
,
now
),
ShouldBeFalse
);
})
})
}
pkg/setting/setting.go
View file @
516839d7
...
...
@@ -20,6 +20,7 @@ import (
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/util"
"time"
)
type
Scheme
string
...
...
@@ -195,6 +196,8 @@ type Cfg struct {
PhantomDir
string
RendererUrl
string
DisableBruteForceLoginProtection
bool
TempDataLifetime
time
.
Duration
}
type
CommandLineArgs
struct
{
...
...
@@ -637,6 +640,9 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
cfg
.
RendererUrl
=
renderSec
.
Key
(
"server_url"
)
.
String
()
cfg
.
ImagesDir
=
filepath
.
Join
(
DataPath
,
"png"
)
cfg
.
PhantomDir
=
filepath
.
Join
(
HomePath
,
"tools/phantomjs"
)
cfg
.
TempDataLifetime
=
iniFile
.
Section
(
"paths"
)
.
Key
(
"temp_data_lifetime"
)
.
MustDuration
(
time
.
Duration
(
time
.
Second
*
3600
*
24
),
)
analytics
:=
iniFile
.
Section
(
"analytics"
)
ReportingEnabled
=
analytics
.
Key
(
"reporting_enabled"
)
.
MustBool
(
true
)
...
...
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