Просмотр исходного кода

Handle errors when loading dashboard with template variables that query data sources that cannot be found

Torkel Ödegaard 11 лет назад
Родитель
Сommit
646298f5c5

+ 1 - 0
pkg/middleware/util.go

@@ -11,6 +11,7 @@ func Gziper() macaron.Handler {
 
 	return func(ctx *macaron.Context) {
 		requestPath := ctx.Req.URL.RequestURI()
+		// ignore datasource proxy requests
 		if strings.HasPrefix(requestPath, "/api/datasources/proxy") {
 			return
 		}

+ 4 - 1
public/app/features/dashboard/dashboardCtrl.js

@@ -45,7 +45,7 @@ function (angular, $, config) {
 
       // template values service needs to initialize completely before
       // the rest of the dashboard can load
-      templateValuesSrv.init(dashboard).then(function() {
+      templateValuesSrv.init(dashboard).finally(function() {
         $scope.dashboard = dashboard;
         $scope.dashboardMeta = dashboard.meta;
         $scope.dashboardViewState = dashboardViewStateSrv.create($scope);
@@ -57,6 +57,9 @@ function (angular, $, config) {
         $scope.setWindowTitleAndTheme();
 
         $scope.appEvent("dashboard-loaded", $scope.dashboard);
+      }).catch(function(err) {
+        console.log('Failed to initialize dashboard template variables, error: ', err);
+        $scope.appEvent("alert-error", ['Dashboard init failed', 'Template variables could not be initialized: ' + err.message]);
       });
     };
 

+ 4 - 0
public/app/plugins/datasource/grafana/datasource.js

@@ -31,6 +31,10 @@ function (angular, _, kbn) {
       return backendSrv.get('/api/metrics/test', { from: from, to: to, maxDataPoints: options.maxDataPoints });
     };
 
+    GrafanaDatasource.prototype.metricFindQuery = function() {
+      return $q.when([]);
+    };
+
     GrafanaDatasource.prototype.starDashboard = function(dashId) {
       return backendSrv.post('/api/user/stars/dashboard/' + dashId);
     };