From 09cb0f378b92c04ad9011738cfa8243f697b4ac5 Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 30 Nov 2017 17:17:49 +0100 Subject: [PATCH] dashboards as cfg: minor tweaks --- .../provisioning/dashboard/dashboard.go | 5 +- .../provisioning/dashboard/file_reader.go | 23 ++- .../broken-dashboards/invalid.json | 170 +----------------- 3 files changed, 15 insertions(+), 183 deletions(-) diff --git a/pkg/services/provisioning/dashboard/dashboard.go b/pkg/services/provisioning/dashboard/dashboard.go index c67c645f242..820eaf3c0f5 100644 --- a/pkg/services/provisioning/dashboard/dashboard.go +++ b/pkg/services/provisioning/dashboard/dashboard.go @@ -20,10 +20,11 @@ func Provision(ctx context.Context, configDirectory string) (*DashboardProvision ctx: ctx, } - return d, d.Init(ctx) + err := d.Provision(ctx) + return d, err } -func (provider *DashboardProvisioner) Init(ctx context.Context) error { +func (provider *DashboardProvisioner) Provision(ctx context.Context) error { cfgs, err := provider.cfgReader.readConfig() if err != nil { return err diff --git a/pkg/services/provisioning/dashboard/file_reader.go b/pkg/services/provisioning/dashboard/file_reader.go index d27575523ee..d417a73f0da 100644 --- a/pkg/services/provisioning/dashboard/file_reader.go +++ b/pkg/services/provisioning/dashboard/file_reader.go @@ -42,7 +42,7 @@ func NewDashboardFilereader(cfg *DashboardsAsConfig, log log.Logger) (*fileReade } func (fr *fileReader) ReadAndListen(ctx context.Context) error { - ticker := time.NewTicker(time.Second * 10) + ticker := time.NewTicker(time.Second * 5) if err := fr.walkFolder(); err != nil { fr.log.Error("failed to search for dashboards", "error", err) @@ -105,11 +105,10 @@ func (fr *fileReader) walkFolder() error { } if cmd.Result.Updated.Unix() >= f.ModTime().Unix() { - fr.log.Debug("already using latest version", "dashboard", dash.Dashboard.Slug) return nil } - fr.log.Debug("no dashboard in cache. Loading dashboard from disk into database.", "file", path) + fr.log.Debug("no dashboard in cache. loading dashboard from disk into database.", "file", path) return fr.saveDashboard(dash) }) } @@ -141,16 +140,16 @@ func (fr *fileReader) readDashboardFromFile(path string) (*DashboardJson, error) return dash, nil } -func (fr *fileReader) saveDashboard(dashboardJson *DashboardJson) error { - dash := dashboardJson.Dashboard +func (fr *fileReader) saveDashboard(json *DashboardJson) error { + dashboard := json.Dashboard - if dash.Title == "" { + if dashboard.Title == "" { return models.ErrDashboardTitleEmpty } validateAlertsCmd := alerting.ValidateDashboardAlertsCommand{ - OrgId: dashboardJson.OrgId, - Dashboard: dash, + OrgId: json.OrgId, + Dashboard: dashboard, } if err := bus.Dispatch(&validateAlertsCmd); err != nil { @@ -158,11 +157,11 @@ func (fr *fileReader) saveDashboard(dashboardJson *DashboardJson) error { } cmd := models.SaveDashboardCommand{ - Dashboard: dash.Data, + Dashboard: dashboard.Data, Message: "Dashboard created from file.", - OrgId: dashboardJson.OrgId, + OrgId: json.OrgId, Overwrite: true, - UpdatedAt: dashboardJson.ModTime, + UpdatedAt: json.ModTime, } err := bus.Dispatch(&cmd) @@ -171,7 +170,7 @@ func (fr *fileReader) saveDashboard(dashboardJson *DashboardJson) error { } alertCmd := alerting.UpdateDashboardAlertsCommand{ - OrgId: dashboardJson.OrgId, + OrgId: json.OrgId, Dashboard: cmd.Result, } diff --git a/pkg/services/provisioning/dashboard/test-dashboards/broken-dashboards/invalid.json b/pkg/services/provisioning/dashboard/test-dashboards/broken-dashboards/invalid.json index 1aa388a6e78..0c5e34c2da7 100644 --- a/pkg/services/provisioning/dashboard/test-dashboards/broken-dashboards/invalid.json +++ b/pkg/services/provisioning/dashboard/test-dashboards/broken-dashboards/invalid.json @@ -1,174 +1,6 @@ [] { "title": "Grafana", - "tags": [], - "style": "dark", - "timezone": "browser", - "editable": true, - "rows": [ - { - "title": "New row", - "height": "150px", - "collapse": false, - "editable": true, - "panels": [ - { - "id": 1, - "span": 12, - "editable": true, - "type": "text", - "mode": "html", - "content": "
\n \n
", - "style": {}, - "title": "Welcome to" - } - ] - }, - { - "title": "Welcome to Grafana", - "height": "210px", - "collapse": false, - "editable": true, - "panels": [ - { - "id": 2, - "span": 6, - "type": "text", - "mode": "html", - "content": "
\n\n
\n
\n \n
\n
\n \n
\n
", - "style": {}, - "title": "Documentation Links" - }, - { - "id": 3, - "span": 6, - "type": "text", - "mode": "html", - "content": "
\n\n
\n
\n
    \n
  • Ctrl+S saves the current dashboard
  • \n
  • Ctrl+F Opens the dashboard finder
  • \n
  • Ctrl+H Hide/show row controls
  • \n
  • Click and drag graph title to move panel
  • \n
  • Hit Escape to exit graph when in fullscreen or edit mode
  • \n
  • Click the colored icon in the legend to change series color
  • \n
  • Ctrl or Shift + Click legend name to hide other series
  • \n
\n
\n
\n", - "style": {}, - "title": "Tips & Shortcuts" - } - ] - }, - { - "title": "test", - "height": "250px", - "editable": true, - "collapse": false, - "panels": [ - { - "id": 4, - "span": 12, - "type": "graph", - "x-axis": true, - "y-axis": true, - "scale": 1, - "y_formats": [ - "short", - "short" - ], - "grid": { - "max": null, - "min": null, - "leftMax": null, - "rightMax": null, - "leftMin": null, - "rightMin": null, - "threshold1": null, - "threshold2": null, - "threshold1Color": "rgba(216, 200, 27, 0.27)", - "threshold2Color": "rgba(234, 112, 112, 0.22)" - }, - "resolution": 100, - "lines": true, - "fill": 1, - "linewidth": 2, - "dashes": false, - "dashLength": 10, - "spaceLength": 10, - "points": false, - "pointradius": 5, - "bars": false, - "stack": true, - "spyable": true, - "options": false, - "legend": { - "show": true, - "values": false, - "min": false, - "max": false, - "current": false, - "total": false, - "avg": false - }, - "interactive": true, - "legend_counts": true, - "timezone": "browser", - "percentage": false, - "nullPointMode": "connected", - "steppedLine": false, - "tooltip": { - "value_type": "cumulative", - "query_as_alias": true - }, - "targets": [ - { - "target": "randomWalk('random walk')", - "function": "mean", - "column": "value" - } - ], - "aliasColors": {}, - "aliasYAxis": {}, - "title": "First Graph (click title to edit)", - "datasource": "graphite", - "renderer": "flot", - "annotate": { - "enable": false - } - } - ] - } - ], - "nav": [ - { - "type": "timepicker", - "collapse": false, - "enable": true, - "status": "Stable", - "time_options": [ - "5m", - "15m", - "1h", - "6h", - "12h", - "24h", - "2d", - "7d", - "30d" - ], - "refresh_intervals": [ - "5s", - "10s", - "30s", - "1m", - "5m", - "15m", - "30m", - "1h", - "2h", - "1d" - ], - "now": true - } - ], - "time": { - "from": "now-6h", - "to": "now" - }, - "templating": { - "list": [] - }, - "version": 5 + } \ No newline at end of file