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 {
if cfg.Type == "file" {
switch cfg.Type {
case "file":
fileReader, err := NewDashboardFilereader(cfg, provider.log.New("type", cfg.Type, "name", cfg.Name))
if err != nil {
return err
}
// err = fileReader.Init()
// if err != nil {
// provider.log.Error("Failed to load dashboards", "error", err)
// }
go fileReader.Listen(ctx)
} else {
go fileReader.ReadAndListen(ctx)
default:
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
}
func (fr *fileReader) Listen(ctx context.Context) error {
ticker := time.NewTicker(time.Second * 1)
func (fr *fileReader) ReadAndListen(ctx context.Context) error {
ticker := time.NewTicker(time.Second * 10)
if err := fr.walkFolder(); err != nil {
fr.log.Error("failed to search for dashboards", "error", err)

View File

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

View File

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

View File

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

View File

@ -4,30 +4,19 @@ import (
"context"
"path/filepath"
"github.com/grafana/grafana/pkg/log"
"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"
)
var (
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 {
func Init(ctx context.Context, homePath string, cfg *ini.File) error {
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
}
dashboardPath := makeAbsolute(cfg.Section("paths").Key("dashboards").String(), homePath)
_, err := dashboard.Provision(backgroundContext, dashboardPath)
_, err := dashboard.Provision(ctx, dashboardPath)
if err != nil {
return err
}
@ -35,10 +24,6 @@ func Init(backgroundContext context.Context, homePath string, cfg *ini.File) err
return nil
}
func (p *Provisioner) Listen() error {
return nil
}
func makeAbsolute(path string, root string) string {
if filepath.IsAbs(path) {
return path