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
f5e00e13
Commit
f5e00e13
authored
Dec 28, 2017
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboards as cfg: moves dashcash into its own file
parent
237d469e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
32 deletions
+38
-32
pkg/services/provisioning/dashboards/dashboard_cache.go
+33
-0
pkg/services/provisioning/dashboards/file_reader.go
+3
-3
pkg/services/provisioning/dashboards/file_reader_test.go
+2
-2
pkg/services/provisioning/dashboards/types.go
+0
-27
No files found.
pkg/services/provisioning/dashboards/dashboard_cache.go
0 → 100644
View file @
f5e00e13
package
dashboards
import
(
"github.com/grafana/grafana/pkg/services/dashboards"
gocache
"github.com/patrickmn/go-cache"
"time"
)
type
dashboardCache
struct
{
internalCache
*
gocache
.
Cache
}
func
NewDashboardCache
()
*
dashboardCache
{
return
&
dashboardCache
{
internalCache
:
gocache
.
New
(
5
*
time
.
Minute
,
30
*
time
.
Minute
)}
}
func
(
fr
*
dashboardCache
)
addDashboardCache
(
key
string
,
json
*
dashboards
.
SaveDashboardItem
)
{
fr
.
internalCache
.
Add
(
key
,
json
,
time
.
Minute
*
10
)
}
func
(
fr
*
dashboardCache
)
getCache
(
key
string
)
(
*
dashboards
.
SaveDashboardItem
,
bool
)
{
obj
,
exist
:=
fr
.
internalCache
.
Get
(
key
)
if
!
exist
{
return
nil
,
exist
}
dash
,
ok
:=
obj
.
(
*
dashboards
.
SaveDashboardItem
)
if
!
ok
{
return
nil
,
ok
}
return
dash
,
ok
}
pkg/services/provisioning/dashboards/file_reader.go
View file @
f5e00e13
...
...
@@ -29,7 +29,7 @@ type fileReader struct {
Path
string
log
log
.
Logger
dashboardRepo
dashboards
.
Repository
cache
*
D
ashboardCache
cache
*
d
ashboardCache
createWalk
func
(
fr
*
fileReader
,
folderId
int64
)
filepath
.
WalkFunc
}
...
...
@@ -87,7 +87,7 @@ func (fr *fileReader) startWalkingDisk() error {
}
}
folderId
,
err
:=
getOrCreateFolder
(
fr
.
Cfg
,
fr
.
dashboardRepo
)
folderId
,
err
:=
getOrCreateFolder
Id
(
fr
.
Cfg
,
fr
.
dashboardRepo
)
if
err
!=
nil
&&
err
!=
ErrFolderNameMissing
{
return
err
}
...
...
@@ -95,7 +95,7 @@ func (fr *fileReader) startWalkingDisk() error {
return
filepath
.
Walk
(
fr
.
Path
,
fr
.
createWalk
(
fr
,
folderId
))
}
func
getOrCreateFolder
(
cfg
*
DashboardsAsConfig
,
repo
dashboards
.
Repository
)
(
int64
,
error
)
{
func
getOrCreateFolder
Id
(
cfg
*
DashboardsAsConfig
,
repo
dashboards
.
Repository
)
(
int64
,
error
)
{
if
cfg
.
Folder
==
""
{
return
0
,
ErrFolderNameMissing
}
...
...
pkg/services/provisioning/dashboards/file_reader_test.go
View file @
f5e00e13
...
...
@@ -133,7 +133,7 @@ func TestDashboardFileReader(t *testing.T) {
},
}
_
,
err
:=
getOrCreateFolder
(
cfg
,
fakeRepo
)
_
,
err
:=
getOrCreateFolder
Id
(
cfg
,
fakeRepo
)
So
(
err
,
ShouldEqual
,
ErrFolderNameMissing
)
})
...
...
@@ -148,7 +148,7 @@ func TestDashboardFileReader(t *testing.T) {
},
}
folderId
,
err
:=
getOrCreateFolder
(
cfg
,
fakeRepo
)
folderId
,
err
:=
getOrCreateFolder
Id
(
cfg
,
fakeRepo
)
So
(
err
,
ShouldBeNil
)
inserted
:=
false
for
_
,
d
:=
range
fakeRepo
.
inserted
{
...
...
pkg/services/provisioning/dashboards/types.go
View file @
f5e00e13
...
...
@@ -7,7 +7,6 @@ import (
"github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/models"
gocache
"github.com/patrickmn/go-cache"
)
type
DashboardsAsConfig
struct
{
...
...
@@ -19,32 +18,6 @@ type DashboardsAsConfig struct {
Options
map
[
string
]
interface
{}
`json:"options" yaml:"options"`
}
type
DashboardCache
struct
{
internalCache
*
gocache
.
Cache
}
func
NewDashboardCache
()
*
DashboardCache
{
return
&
DashboardCache
{
internalCache
:
gocache
.
New
(
5
*
time
.
Minute
,
30
*
time
.
Minute
)}
}
func
(
fr
*
DashboardCache
)
addDashboardCache
(
key
string
,
json
*
dashboards
.
SaveDashboardItem
)
{
fr
.
internalCache
.
Add
(
key
,
json
,
time
.
Minute
*
10
)
}
func
(
fr
*
DashboardCache
)
getCache
(
key
string
)
(
*
dashboards
.
SaveDashboardItem
,
bool
)
{
obj
,
exist
:=
fr
.
internalCache
.
Get
(
key
)
if
!
exist
{
return
nil
,
exist
}
dash
,
ok
:=
obj
.
(
*
dashboards
.
SaveDashboardItem
)
if
!
ok
{
return
nil
,
ok
}
return
dash
,
ok
}
func
createDashboardJson
(
data
*
simplejson
.
Json
,
lastModified
time
.
Time
,
cfg
*
DashboardsAsConfig
,
folderId
int64
)
(
*
dashboards
.
SaveDashboardItem
,
error
)
{
dash
:=
&
dashboards
.
SaveDashboardItem
{}
dash
.
Dashboard
=
models
.
NewDashboardFromJson
(
data
)
...
...
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