renames intervalSeconds to updateIntervalSeconds

This commit is contained in:
bergquist 2018-06-04 08:13:20 +02:00
parent 333af6fd9b
commit 75ee1e9208
7 changed files with 53 additions and 50 deletions

View File

@ -197,6 +197,7 @@ providers:
folder: '' folder: ''
type: file type: file
disableDeletion: false disableDeletion: false
updateIntervalSeconds: 3 #how often Grafana will scan for changed dashboards
options: options:
path: /var/lib/grafana/dashboards path: /var/lib/grafana/dashboards
``` ```

View File

@ -82,8 +82,8 @@ func (cr *configReader) readConfig() ([]*DashboardsAsConfig, error) {
dashboards[i].OrgId = 1 dashboards[i].OrgId = 1
} }
if dashboards[i].IntervalSeconds == 0 { if dashboards[i].UpdateIntervalSeconds == 0 {
dashboards[i].IntervalSeconds = 3 dashboards[i].UpdateIntervalSeconds = 3
} }
} }

View File

@ -22,7 +22,7 @@ func TestDashboardsAsConfig(t *testing.T) {
cfg, err := cfgProvider.readConfig() cfg, err := cfgProvider.readConfig()
So(err, ShouldBeNil) So(err, ShouldBeNil)
validateDashboardAsConfig(cfg) validateDashboardAsConfig(t, cfg)
}) })
Convey("Can read config file in version 0 format", func() { Convey("Can read config file in version 0 format", func() {
@ -30,7 +30,7 @@ func TestDashboardsAsConfig(t *testing.T) {
cfg, err := cfgProvider.readConfig() cfg, err := cfgProvider.readConfig()
So(err, ShouldBeNil) So(err, ShouldBeNil)
validateDashboardAsConfig(cfg) validateDashboardAsConfig(t, cfg)
}) })
Convey("Should skip invalid path", func() { Convey("Should skip invalid path", func() {
@ -56,7 +56,9 @@ func TestDashboardsAsConfig(t *testing.T) {
}) })
}) })
} }
func validateDashboardAsConfig(cfg []*DashboardsAsConfig) { func validateDashboardAsConfig(t *testing.T, cfg []*DashboardsAsConfig) {
t.Helper()
So(len(cfg), ShouldEqual, 2) So(len(cfg), ShouldEqual, 2)
ds := cfg[0] ds := cfg[0]
@ -68,7 +70,7 @@ func validateDashboardAsConfig(cfg []*DashboardsAsConfig) {
So(len(ds.Options), ShouldEqual, 1) So(len(ds.Options), ShouldEqual, 1)
So(ds.Options["path"], ShouldEqual, "/var/lib/grafana/dashboards") So(ds.Options["path"], ShouldEqual, "/var/lib/grafana/dashboards")
So(ds.DisableDeletion, ShouldBeTrue) So(ds.DisableDeletion, ShouldBeTrue)
So(ds.IntervalSeconds, ShouldEqual, 10) So(ds.UpdateIntervalSeconds, ShouldEqual, 10)
ds2 := cfg[1] ds2 := cfg[1]
So(ds2.Name, ShouldEqual, "default") So(ds2.Name, ShouldEqual, "default")
@ -79,5 +81,5 @@ func validateDashboardAsConfig(cfg []*DashboardsAsConfig) {
So(len(ds2.Options), ShouldEqual, 1) So(len(ds2.Options), ShouldEqual, 1)
So(ds2.Options["path"], ShouldEqual, "/var/lib/grafana/dashboards") So(ds2.Options["path"], ShouldEqual, "/var/lib/grafana/dashboards")
So(ds2.DisableDeletion, ShouldBeFalse) So(ds2.DisableDeletion, ShouldBeFalse)
So(ds2.IntervalSeconds, ShouldEqual, 3) So(ds2.UpdateIntervalSeconds, ShouldEqual, 3)
} }

View File

@ -66,7 +66,7 @@ func (fr *fileReader) ReadAndListen(ctx context.Context) error {
fr.log.Error("failed to search for dashboards", "error", err) fr.log.Error("failed to search for dashboards", "error", err)
} }
ticker := time.NewTicker(time.Duration(int64(time.Second) * fr.Cfg.IntervalSeconds)) ticker := time.NewTicker(time.Duration(int64(time.Second) * fr.Cfg.UpdateIntervalSeconds))
running := false running := false

View File

@ -6,7 +6,7 @@ providers:
folder: 'developers' folder: 'developers'
editable: true editable: true
disableDeletion: true disableDeletion: true
intervalSeconds: 10 updateIntervalSeconds: 10
type: file type: file
options: options:
path: /var/lib/grafana/dashboards path: /var/lib/grafana/dashboards

View File

@ -3,7 +3,7 @@
folder: 'developers' folder: 'developers'
editable: true editable: true
disableDeletion: true disableDeletion: true
intervalSeconds: 10 updateIntervalSeconds: 10
type: file type: file
options: options:
path: /var/lib/grafana/dashboards path: /var/lib/grafana/dashboards

View File

@ -17,7 +17,7 @@ type DashboardsAsConfig struct {
Editable bool Editable bool
Options map[string]interface{} Options map[string]interface{}
DisableDeletion bool DisableDeletion bool
IntervalSeconds int64 UpdateIntervalSeconds int64
} }
type DashboardsAsConfigV0 struct { type DashboardsAsConfigV0 struct {
@ -28,7 +28,7 @@ type DashboardsAsConfigV0 struct {
Editable bool `json:"editable" yaml:"editable"` Editable bool `json:"editable" yaml:"editable"`
Options map[string]interface{} `json:"options" yaml:"options"` Options map[string]interface{} `json:"options" yaml:"options"`
DisableDeletion bool `json:"disableDeletion" yaml:"disableDeletion"` DisableDeletion bool `json:"disableDeletion" yaml:"disableDeletion"`
IntervalSeconds int64 `json:"intervalSeconds" yaml:"intervalSeconds"` UpdateIntervalSeconds int64 `json:"updateIntervalSeconds" yaml:"updateIntervalSeconds"`
} }
type ConfigVersion struct { type ConfigVersion struct {
@ -47,7 +47,7 @@ type DashboardProviderConfigs struct {
Editable bool `json:"editable" yaml:"editable"` Editable bool `json:"editable" yaml:"editable"`
Options map[string]interface{} `json:"options" yaml:"options"` Options map[string]interface{} `json:"options" yaml:"options"`
DisableDeletion bool `json:"disableDeletion" yaml:"disableDeletion"` DisableDeletion bool `json:"disableDeletion" yaml:"disableDeletion"`
IntervalSeconds int64 `json:"intervalSeconds" yaml:"intervalSeconds"` UpdateIntervalSeconds int64 `json:"updateIntervalSeconds" yaml:"updateIntervalSeconds"`
} }
func createDashboardJson(data *simplejson.Json, lastModified time.Time, cfg *DashboardsAsConfig, folderId int64) (*dashboards.SaveDashboardDTO, error) { func createDashboardJson(data *simplejson.Json, lastModified time.Time, cfg *DashboardsAsConfig, folderId int64) (*dashboards.SaveDashboardDTO, error) {
@ -78,7 +78,7 @@ func mapV0ToDashboardAsConfig(v0 []*DashboardsAsConfigV0) []*DashboardsAsConfig
Editable: v.Editable, Editable: v.Editable,
Options: v.Options, Options: v.Options,
DisableDeletion: v.DisableDeletion, DisableDeletion: v.DisableDeletion,
IntervalSeconds: v.IntervalSeconds, UpdateIntervalSeconds: v.UpdateIntervalSeconds,
}) })
} }
@ -97,7 +97,7 @@ func (dc *DashboardAsConfigV1) mapToDashboardAsConfig() []*DashboardsAsConfig {
Editable: v.Editable, Editable: v.Editable,
Options: v.Options, Options: v.Options,
DisableDeletion: v.DisableDeletion, DisableDeletion: v.DisableDeletion,
IntervalSeconds: v.IntervalSeconds, UpdateIntervalSeconds: v.UpdateIntervalSeconds,
}) })
} }