dashboards as cfg: code cleanup

This commit is contained in:
bergquist 2017-11-28 14:01:10 +01:00
parent d69b63cbc0
commit dc0fb8be06
16 changed files with 13 additions and 32 deletions

View File

@ -30,19 +30,15 @@ func (provider *DashboardProvisioner) Init(ctx context.Context) error {
} }
for _, cfg := range cfgs { for _, cfg := range cfgs {
if cfg.Type == "file" { switch cfg.Type {
case "file":
fileReader, err := NewDashboardFilereader(cfg, provider.log.New("type", cfg.Type, "name", cfg.Name)) fileReader, err := NewDashboardFilereader(cfg, provider.log.New("type", cfg.Type, "name", cfg.Name))
if err != nil { if err != nil {
return err return err
} }
// err = fileReader.Init() go fileReader.ReadAndListen(ctx)
// if err != nil { default:
// provider.log.Error("Failed to load dashboards", "error", err)
// }
go fileReader.Listen(ctx)
} else {
return fmt.Errorf("type %s is not supported", cfg.Type) return fmt.Errorf("type %s is not supported", cfg.Type)
} }
} }

View File

@ -67,8 +67,8 @@ func NewDashboardFilereader(cfg *DashboardsAsConfig, log log.Logger) (*fileReade
}, nil }, nil
} }
func (fr *fileReader) Listen(ctx context.Context) error { func (fr *fileReader) ReadAndListen(ctx context.Context) error {
ticker := time.NewTicker(time.Second * 1) ticker := time.NewTicker(time.Second * 10)
if err := fr.walkFolder(); err != nil { if err := fr.walkFolder(); err != nil {
fr.log.Error("failed to search for dashboards", "error", err) fr.log.Error("failed to search for dashboards", "error", err)

View File

@ -1,4 +1,4 @@
package datasources package datasource
import ( import (
"errors" "errors"

View File

@ -1,4 +1,4 @@
package datasources package datasource
import ( import (
"testing" "testing"

View File

@ -1,4 +1,4 @@
package datasources package datasource
import "github.com/grafana/grafana/pkg/models" import "github.com/grafana/grafana/pkg/models"
import "github.com/grafana/grafana/pkg/components/simplejson" import "github.com/grafana/grafana/pkg/components/simplejson"

View File

@ -4,30 +4,19 @@ import (
"context" "context"
"path/filepath" "path/filepath"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/services/provisioning/dashboard" "github.com/grafana/grafana/pkg/services/provisioning/dashboard"
"github.com/grafana/grafana/pkg/services/provisioning/datasources" "github.com/grafana/grafana/pkg/services/provisioning/datasource"
ini "gopkg.in/ini.v1" ini "gopkg.in/ini.v1"
) )
var ( func Init(ctx context.Context, homePath string, cfg *ini.File) error {
logger log.Logger = log.New("services.provisioning")
)
type Provisioner struct {
datasourcePath string
dashboardPath string
bgContext context.Context
}
func Init(backgroundContext context.Context, homePath string, cfg *ini.File) error {
datasourcePath := makeAbsolute(cfg.Section("paths").Key("datasources").String(), homePath) datasourcePath := makeAbsolute(cfg.Section("paths").Key("datasources").String(), homePath)
if err := datasources.Provision(datasourcePath); err != nil { if err := datasource.Provision(datasourcePath); err != nil {
return err return err
} }
dashboardPath := makeAbsolute(cfg.Section("paths").Key("dashboards").String(), homePath) dashboardPath := makeAbsolute(cfg.Section("paths").Key("dashboards").String(), homePath)
_, err := dashboard.Provision(backgroundContext, dashboardPath) _, err := dashboard.Provision(ctx, dashboardPath)
if err != nil { if err != nil {
return err return err
} }
@ -35,10 +24,6 @@ func Init(backgroundContext context.Context, homePath string, cfg *ini.File) err
return nil return nil
} }
func (p *Provisioner) Listen() error {
return nil
}
func makeAbsolute(path string, root string) string { func makeAbsolute(path string, root string) string {
if filepath.IsAbs(path) { if filepath.IsAbs(path) {
return path return path