mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #10547 from grafana/provisioning
Dashboard provisioning. Replace folder property with path
This commit is contained in:
commit
81bb3e1e27
@ -33,7 +33,7 @@ func TestDashboardsAsConfig(t *testing.T) {
|
|||||||
So(ds.Editable, ShouldBeTrue)
|
So(ds.Editable, ShouldBeTrue)
|
||||||
|
|
||||||
So(len(ds.Options), ShouldEqual, 1)
|
So(len(ds.Options), ShouldEqual, 1)
|
||||||
So(ds.Options["folder"], ShouldEqual, "/var/lib/grafana/dashboards")
|
So(ds.Options["path"], ShouldEqual, "/var/lib/grafana/dashboards")
|
||||||
|
|
||||||
ds2 := cfg[1]
|
ds2 := cfg[1]
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ func TestDashboardsAsConfig(t *testing.T) {
|
|||||||
So(ds2.Editable, ShouldBeFalse)
|
So(ds2.Editable, ShouldBeFalse)
|
||||||
|
|
||||||
So(len(ds2.Options), ShouldEqual, 1)
|
So(len(ds2.Options), ShouldEqual, 1)
|
||||||
So(ds2.Options["folder"], ShouldEqual, "/var/lib/grafana/dashboards")
|
So(ds2.Options["path"], ShouldEqual, "/var/lib/grafana/dashboards")
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Should skip broken config files", func() {
|
Convey("Should skip broken config files", func() {
|
||||||
|
@ -34,9 +34,15 @@ type fileReader struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewDashboardFileReader(cfg *DashboardsAsConfig, log log.Logger) (*fileReader, error) {
|
func NewDashboardFileReader(cfg *DashboardsAsConfig, log log.Logger) (*fileReader, error) {
|
||||||
path, ok := cfg.Options["folder"].(string)
|
var path string
|
||||||
|
path, ok := cfg.Options["path"].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("Failed to load dashboards. folder param is not a string")
|
path, ok = cfg.Options["folder"].(string)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("Failed to load dashboards. path param is not a string")
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Warn("[Deprecated] The folder property is deprecated. Please use path instead.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
|
@ -42,7 +42,7 @@ func TestDashboardFileReader(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Convey("Can read default dashboard", func() {
|
Convey("Can read default dashboard", func() {
|
||||||
cfg.Options["folder"] = defaultDashboards
|
cfg.Options["path"] = defaultDashboards
|
||||||
cfg.Folder = "Team A"
|
cfg.Folder = "Team A"
|
||||||
|
|
||||||
reader, err := NewDashboardFileReader(cfg, logger)
|
reader, err := NewDashboardFileReader(cfg, logger)
|
||||||
@ -67,7 +67,7 @@ func TestDashboardFileReader(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Should not update dashboards when db is newer", func() {
|
Convey("Should not update dashboards when db is newer", func() {
|
||||||
cfg.Options["folder"] = oneDashboard
|
cfg.Options["path"] = oneDashboard
|
||||||
|
|
||||||
fakeRepo.getDashboard = append(fakeRepo.getDashboard, &models.Dashboard{
|
fakeRepo.getDashboard = append(fakeRepo.getDashboard, &models.Dashboard{
|
||||||
Updated: time.Now().Add(time.Hour),
|
Updated: time.Now().Add(time.Hour),
|
||||||
@ -84,7 +84,7 @@ func TestDashboardFileReader(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Can read default dashboard and replace old version in database", func() {
|
Convey("Can read default dashboard and replace old version in database", func() {
|
||||||
cfg.Options["folder"] = oneDashboard
|
cfg.Options["path"] = oneDashboard
|
||||||
|
|
||||||
stat, _ := os.Stat(oneDashboard + "/dashboard1.json")
|
stat, _ := os.Stat(oneDashboard + "/dashboard1.json")
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ func TestDashboardFileReader(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Broken dashboards should not cause error", func() {
|
Convey("Broken dashboards should not cause error", func() {
|
||||||
cfg.Options["folder"] = brokenDashboards
|
cfg.Options["path"] = brokenDashboards
|
||||||
|
|
||||||
_, err := NewDashboardFileReader(cfg, logger)
|
_, err := NewDashboardFileReader(cfg, logger)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
@ -167,7 +167,7 @@ func TestDashboardFileReader(t *testing.T) {
|
|||||||
OrgId: 1,
|
OrgId: 1,
|
||||||
Folder: "",
|
Folder: "",
|
||||||
Options: map[string]interface{}{
|
Options: map[string]interface{}{
|
||||||
"folder": defaultDashboards,
|
"path": defaultDashboards,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,6 +184,30 @@ func TestDashboardFileReader(t *testing.T) {
|
|||||||
So(shouldSkip, ShouldBeNil)
|
So(shouldSkip, ShouldBeNil)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("Can use bpth path and folder as dashboard path", func() {
|
||||||
|
cfg := &DashboardsAsConfig{
|
||||||
|
Name: "Default",
|
||||||
|
Type: "file",
|
||||||
|
OrgId: 1,
|
||||||
|
Folder: "",
|
||||||
|
Options: map[string]interface{}{},
|
||||||
|
}
|
||||||
|
|
||||||
|
Convey("using path parameter", func() {
|
||||||
|
cfg.Options["path"] = defaultDashboards
|
||||||
|
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(reader.Path, ShouldEqual, defaultDashboards)
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("using folder as options", func() {
|
||||||
|
cfg.Options["folder"] = defaultDashboards
|
||||||
|
reader, err := NewDashboardFileReader(cfg, log.New("test-logger"))
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(reader.Path, ShouldEqual, defaultDashboards)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
editable: true
|
editable: true
|
||||||
type: file
|
type: file
|
||||||
options:
|
options:
|
||||||
folder: /var/lib/grafana/dashboards
|
path: /var/lib/grafana/dashboards
|
||||||
|
|
||||||
- name: 'default'
|
- name: 'default'
|
||||||
type: file
|
type: file
|
||||||
options:
|
options:
|
||||||
folder: /var/lib/grafana/dashboards
|
path: /var/lib/grafana/dashboards
|
||||||
|
Loading…
Reference in New Issue
Block a user