Commit dc0fb8be by bergquist

dashboards as cfg: code cleanup

parent d69b63cb
......@@ -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)
}
}
......
......@@ -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)
......
package datasources
package datasource
import "github.com/grafana/grafana/pkg/models"
import "github.com/grafana/grafana/pkg/components/simplejson"
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment