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
09917846
Commit
09917846
authored
Dec 01, 2017
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboards as cfg: wire up dashboard repo
parent
288cc355
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
10 deletions
+15
-10
pkg/services/dashboards/dashboards.go
+2
-2
pkg/services/provisioning/dashboards/file_reader.go
+10
-8
pkg/services/provisioning/dashboards/types.go
+1
-0
pkg/services/sqlstore/sqlstore.go
+2
-0
No files found.
pkg/services/dashboards/dashboards.go
View file @
09917846
...
...
@@ -33,9 +33,9 @@ type SaveDashboardItem struct {
Dashboard
*
models
.
Dashboard
}
type
d
ashboardRepository
struct
{}
type
D
ashboardRepository
struct
{}
func
(
dr
*
d
ashboardRepository
)
SaveDashboard
(
json
*
SaveDashboardItem
)
(
*
models
.
Dashboard
,
error
)
{
func
(
dr
*
D
ashboardRepository
)
SaveDashboard
(
json
*
SaveDashboardItem
)
(
*
models
.
Dashboard
,
error
)
{
dashboard
:=
json
.
Dashboard
if
dashboard
.
Title
==
""
{
...
...
pkg/services/provisioning/dashboards/file_reader.go
View file @
09917846
...
...
@@ -41,7 +41,7 @@ func NewDashboardFilereader(cfg *DashboardsAsConfig, log log.Logger) (*fileReade
Path
:
path
,
log
:
log
,
dashboardRepo
:
dashboards
.
GetRepository
(),
cache
:
gocache
.
New
(
5
*
time
.
Minute
,
1
0
*
time
.
Minute
),
cache
:
gocache
.
New
(
5
*
time
.
Minute
,
3
0
*
time
.
Minute
),
},
nil
}
...
...
@@ -87,23 +87,23 @@ func (fr *fileReader) walkFolder() error {
}
}
return
filepath
.
Walk
(
fr
.
Path
,
func
(
path
string
,
f
os
.
FileInfo
,
err
error
)
error
{
return
filepath
.
Walk
(
fr
.
Path
,
func
(
path
string
,
f
ileInfo
os
.
FileInfo
,
err
error
)
error
{
if
err
!=
nil
{
return
err
}
if
f
.
IsDir
()
{
if
strings
.
HasPrefix
(
f
.
Name
(),
"."
)
{
if
f
ileInfo
.
IsDir
()
{
if
strings
.
HasPrefix
(
f
ileInfo
.
Name
(),
"."
)
{
return
filepath
.
SkipDir
}
return
nil
}
if
!
strings
.
HasSuffix
(
f
.
Name
(),
".json"
)
{
if
!
strings
.
HasSuffix
(
f
ileInfo
.
Name
(),
".json"
)
{
return
nil
}
cachedDashboard
,
exist
:=
fr
.
getCache
(
path
)
if
exist
&&
cachedDashboard
.
UpdatedAt
==
f
.
ModTime
()
{
if
exist
&&
cachedDashboard
.
UpdatedAt
==
f
ileInfo
.
ModTime
()
{
return
nil
}
...
...
@@ -116,6 +116,7 @@ func (fr *fileReader) walkFolder() error {
cmd
:=
&
models
.
GetDashboardQuery
{
Slug
:
dash
.
Dashboard
.
Slug
}
err
=
bus
.
Dispatch
(
cmd
)
// if we dont have the dashboard in the db, save it!
if
err
==
models
.
ErrDashboardNotFound
{
fr
.
log
.
Debug
(
"saving new dashboard"
,
"file"
,
path
)
_
,
err
=
fr
.
dashboardRepo
.
SaveDashboard
(
dash
)
...
...
@@ -127,11 +128,12 @@ func (fr *fileReader) walkFolder() error {
return
nil
}
if
cmd
.
Result
.
Updated
.
Unix
()
>=
f
.
ModTime
()
.
Unix
()
{
// break if db version is newer then fil version
if
cmd
.
Result
.
Updated
.
Unix
()
>=
fileInfo
.
ModTime
()
.
Unix
()
{
return
nil
}
fr
.
log
.
Debug
(
"
no dashboard in cache.
loading dashboard from disk into database."
,
"file"
,
path
)
fr
.
log
.
Debug
(
"loading dashboard from disk into database."
,
"file"
,
path
)
_
,
err
=
fr
.
dashboardRepo
.
SaveDashboard
(
dash
)
return
err
})
...
...
pkg/services/provisioning/dashboards/types.go
View file @
09917846
...
...
@@ -25,6 +25,7 @@ func createDashboardJson(data *simplejson.Json, lastModified time.Time, cfg *Das
dash
.
Dashboard
=
models
.
NewDashboardFromJson
(
data
)
dash
.
TitleLower
=
strings
.
ToLower
(
dash
.
Dashboard
.
Title
)
dash
.
UpdatedAt
=
lastModified
dash
.
Overwrite
=
true
dash
.
OrgId
=
cfg
.
OrgId
dash
.
Folder
=
cfg
.
Folder
dash
.
Dashboard
.
Data
.
Set
(
"editable"
,
cfg
.
Editable
)
...
...
pkg/services/sqlstore/sqlstore.go
View file @
09917846
...
...
@@ -12,6 +12,7 @@ import (
"github.com/grafana/grafana/pkg/log"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/annotations"
"github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/sqlstore/migrations"
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
"github.com/grafana/grafana/pkg/setting"
...
...
@@ -100,6 +101,7 @@ func SetEngine(engine *xorm.Engine) (err error) {
// Init repo instances
annotations
.
SetRepository
(
&
SqlAnnotationRepo
{})
dashboards
.
SetRepository
(
&
dashboards
.
DashboardRepository
{})
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