diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts
index 16edc364340..85cc63d057f 100644
--- a/public/app/core/services/backend_srv.ts
+++ b/public/app/core/services/backend_srv.ts
@@ -4,6 +4,7 @@ import angular from 'angular';
import _ from 'lodash';
import config from 'app/core/config';
import coreModule from 'app/core/core_module';
+import appEvents from 'app/core/app_events';
export class BackendSrv {
inFlightRequests = {};
@@ -150,7 +151,10 @@ export class BackendSrv {
}
}
- return this.$http(options).catch(err => {
+ return this.$http(options).then(response => {
+ appEvents.emit('ds-request-response', response);
+ return response;
+ }).catch(err => {
if (err.status === this.HTTP_REQUEST_CANCELLED) {
throw {err, cancelled: true};
}
@@ -179,7 +183,9 @@ export class BackendSrv {
err.data.message = err.data.error;
}
+ appEvents.emit('ds-request-error', err);
throw err;
+
}).finally(() => {
// clean up
if (options.requestId) {
diff --git a/public/app/features/panel/metrics_ds_selector.ts b/public/app/features/panel/metrics_ds_selector.ts
index 7c4bc0ef495..67619837e30 100644
--- a/public/app/features/panel/metrics_ds_selector.ts
+++ b/public/app/features/panel/metrics_ds_selector.ts
@@ -2,10 +2,24 @@
import angular from 'angular';
import _ from 'lodash';
+import appEvents from 'app/core/app_events';
var module = angular.module('grafana.directives');
var template = `
+
+
+
+
+
`;
@@ -45,9 +67,12 @@ export class MetricsDsSelectorCtrl {
panelCtrl: any;
datasources: any[];
current: any;
+ lastResponse: any;
+ lastError: any;
+ showResponse: boolean;
/** @ngInject */
- constructor(private uiSegmentSrv, datasourceSrv) {
+ constructor($scope, private uiSegmentSrv, datasourceSrv) {
this.datasources = datasourceSrv.getMetricSources();
var dsValue = this.panelCtrl.panel.datasource || null;
@@ -63,7 +88,25 @@ export class MetricsDsSelectorCtrl {
}
this.dsSegment = uiSegmentSrv.newSegment({value: this.current.name, selectMode: true});
- this.mixedDsSegment = uiSegmentSrv.newSegment({value: 'Add query', selectMode: true});
+ this.mixedDsSegment = uiSegmentSrv.newSegment({value: 'Add Query', selectMode: true});
+
+ appEvents.on('ds-request-response', this.onRequestResponse.bind(this), $scope);
+ appEvents.on('ds-request-error', this.onRequestError.bind(this), $scope);
+ }
+
+ onRequestResponse(data) {
+ console.log(data);
+ this.lastResponse = JSON.stringify(data, null, 2);
+ this.lastError = null;
+ }
+
+ toggleShowResponse() {
+ this.showResponse = !this.showResponse;
+ }
+
+ onRequestError(err) {
+ console.log(err);
+ this.lastError = JSON.stringify(err, null, 2);
}
getOptions(includeBuiltin) {
@@ -79,6 +122,8 @@ export class MetricsDsSelectorCtrl {
if (ds) {
this.current = ds;
this.panelCtrl.setDatasource(ds);
+ this.lastError = null;
+ this.lastResponse = null;
}
}
diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts
index af9d06d8742..000705d74d5 100644
--- a/public/app/features/panel/metrics_panel_ctrl.ts
+++ b/public/app/features/panel/metrics_panel_ctrl.ts
@@ -256,7 +256,7 @@ class MetricsPanelCtrl extends PanelCtrl {
result = {data: []};
}
- return this.events.emit('data-received', result.data);
+ this.events.emit('data-received', result.data);
}
handleDataStream(stream) {