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
93e1d8a1
Commit
93e1d8a1
authored
Nov 28, 2017
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboards as cfg: make dashboard none editable by default
parent
7f3a7ea1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
42 deletions
+51
-42
pkg/services/provisioning/dashboard/dashboard_test.go
+2
-0
pkg/services/provisioning/dashboard/file_reader.go
+8
-37
pkg/services/provisioning/dashboard/test-configs/dashboards-from-disk/dev-dashboards.yaml
+1
-0
pkg/services/provisioning/dashboard/types.go
+40
-5
No files found.
pkg/services/provisioning/dashboard/dashboard_test.go
View file @
93e1d8a1
...
...
@@ -29,6 +29,7 @@ func TestDashboardsAsConfig(t *testing.T) {
So
(
ds
.
Type
,
ShouldEqual
,
"file"
)
So
(
ds
.
OrgId
,
ShouldEqual
,
2
)
So
(
ds
.
Folder
,
ShouldEqual
,
"developers"
)
So
(
ds
.
Editable
,
ShouldBeTrue
)
So
(
len
(
ds
.
Options
),
ShouldEqual
,
1
)
So
(
ds
.
Options
[
"folder"
],
ShouldEqual
,
"/var/lib/grafana/dashboards"
)
...
...
@@ -39,6 +40,7 @@ func TestDashboardsAsConfig(t *testing.T) {
So
(
ds2
.
Type
,
ShouldEqual
,
"file"
)
So
(
ds2
.
OrgId
,
ShouldEqual
,
1
)
So
(
ds2
.
Folder
,
ShouldEqual
,
""
)
So
(
ds2
.
Editable
,
ShouldBeFalse
)
So
(
len
(
ds2
.
Options
),
ShouldEqual
,
1
)
So
(
ds2
.
Options
[
"folder"
],
ShouldEqual
,
"/var/lib/grafana/dashboards"
)
...
...
pkg/services/provisioning/dashboard/file_reader.go
View file @
93e1d8a1
...
...
@@ -7,7 +7,6 @@ import (
"os"
"path/filepath"
"strings"
"sync"
"time"
"github.com/grafana/grafana/pkg/bus"
...
...
@@ -24,31 +23,6 @@ type fileReader struct {
dashboardCache
*
dashboardCache
}
type
dashboardCache
struct
{
mutex
*
sync
.
Mutex
dashboards
map
[
string
]
*
DashboardJson
}
func
newDashboardCache
()
*
dashboardCache
{
return
&
dashboardCache
{
dashboards
:
map
[
string
]
*
DashboardJson
{},
mutex
:
&
sync
.
Mutex
{},
}
}
func
(
dc
*
dashboardCache
)
addCache
(
json
*
DashboardJson
)
{
dc
.
mutex
.
Lock
()
defer
dc
.
mutex
.
Unlock
()
dc
.
dashboards
[
json
.
Path
]
=
json
}
func
(
dc
*
dashboardCache
)
getCache
(
path
string
)
(
*
DashboardJson
,
bool
)
{
dc
.
mutex
.
Lock
()
defer
dc
.
mutex
.
Unlock
()
v
,
exist
:=
dc
.
dashboards
[
path
]
return
v
,
exist
}
func
NewDashboardFilereader
(
cfg
*
DashboardsAsConfig
,
log
log
.
Logger
)
(
*
fileReader
,
error
)
{
path
,
ok
:=
cfg
.
Options
[
"folder"
]
.
(
string
)
if
!
ok
{
...
...
@@ -152,20 +126,17 @@ func (fr *fileReader) readDashboardFromFile(path string) (*DashboardJson, error)
return
nil
,
err
}
stat
,
_
:=
os
.
Stat
(
path
)
dash
:=
&
DashboardJson
{}
dash
.
Dashboard
=
models
.
NewDashboardFromJson
(
data
)
dash
.
TitleLower
=
strings
.
ToLower
(
dash
.
Dashboard
.
Title
)
dash
.
Path
=
path
dash
.
ModTime
=
stat
.
ModTime
()
dash
.
OrgId
=
fr
.
Cfg
.
OrgId
dash
.
Folder
=
fr
.
Cfg
.
Folder
stat
,
err
:=
os
.
Stat
(
path
)
if
err
!=
nil
{
return
nil
,
err
}
if
dash
.
Dashboard
.
Title
==
""
{
return
nil
,
models
.
ErrDashboardTitleEmpty
dash
,
err
:=
createDashboardJson
(
data
,
stat
.
ModTime
(),
fr
.
Cfg
)
if
err
!=
nil
{
return
nil
,
err
}
fr
.
dashboardCache
.
addCache
(
dash
)
fr
.
dashboardCache
.
addCache
(
path
,
dash
)
return
dash
,
nil
}
...
...
pkg/services/provisioning/dashboard/test-configs/dashboards-from-disk/dev-dashboards.yaml
View file @
93e1d8a1
-
name
:
'
general
dashboards'
org_id
:
2
folder
:
'
developers'
editable
:
true
type
:
file
options
:
folder
:
/var/lib/grafana/dashboards
...
...
pkg/services/provisioning/dashboard/types.go
View file @
93e1d8a1
package
dashboard
import
(
"github.com/grafana/grafana/pkg/components/simplejson"
"strings"
"sync"
"time"
...
...
@@ -12,23 +14,56 @@ type DashboardsAsConfig struct {
Type
string
`json:"type" yaml:"type"`
OrgId
int64
`json:"org_id" yaml:"org_id"`
Folder
string
`json:"folder" yaml:"folder"`
Editable
bool
`json:"editable" yaml:"editable"`
Options
map
[
string
]
interface
{}
`json:"options" yaml:"options"`
}
type
DashboardJson
struct
{
TitleLower
string
Path
string
OrgId
int64
Folder
string
ModTime
time
.
Time
Dashboard
*
models
.
Dashboard
}
type
DashboardIndex
struct
{
type
dashboardCache
struct
{
mutex
*
sync
.
Mutex
dashboards
map
[
string
]
*
DashboardJson
}
func
newDashboardCache
()
*
dashboardCache
{
return
&
dashboardCache
{
dashboards
:
map
[
string
]
*
DashboardJson
{},
mutex
:
&
sync
.
Mutex
{},
}
}
func
(
dc
*
dashboardCache
)
addCache
(
key
string
,
json
*
DashboardJson
)
{
dc
.
mutex
.
Lock
()
defer
dc
.
mutex
.
Unlock
()
dc
.
dashboards
[
key
]
=
json
}
PathToDashboard
map
[
string
]
*
DashboardJson
func
(
dc
*
dashboardCache
)
getCache
(
key
string
)
(
*
DashboardJson
,
bool
)
{
dc
.
mutex
.
Lock
()
defer
dc
.
mutex
.
Unlock
()
v
,
exist
:=
dc
.
dashboards
[
key
]
return
v
,
exist
}
type
InsertDashboard
func
(
cmd
*
models
.
Dashboard
)
error
type
UpdateDashboard
func
(
cmd
*
models
.
SaveDashboardCommand
)
error
func
createDashboardJson
(
data
*
simplejson
.
Json
,
lastModified
time
.
Time
,
cfg
*
DashboardsAsConfig
)
(
*
DashboardJson
,
error
)
{
dash
:=
&
DashboardJson
{}
dash
.
Dashboard
=
models
.
NewDashboardFromJson
(
data
)
dash
.
TitleLower
=
strings
.
ToLower
(
dash
.
Dashboard
.
Title
)
dash
.
ModTime
=
lastModified
dash
.
OrgId
=
cfg
.
OrgId
dash
.
Folder
=
cfg
.
Folder
dash
.
Dashboard
.
Data
.
Set
(
"editable"
,
cfg
.
Editable
)
if
dash
.
Dashboard
.
Title
==
""
{
return
nil
,
models
.
ErrDashboardTitleEmpty
}
return
dash
,
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