|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
import './series_overrides_ctrl'; |
|
|
|
|
|
|
|
|
|
import template from './template'; |
|
|
|
|
import template from './template.html'; |
|
|
|
|
|
|
|
|
|
import { GraphRenderer } from './graph_renderer'; |
|
|
|
|
import { GraphLegend } from './graph_legend'; |
|
|
|
@ -31,6 +31,8 @@ class GraphCtrl extends MetricsPanelCtrl {
|
|
|
|
|
hiddenSeries: any = {}; |
|
|
|
|
seriesList: any = []; |
|
|
|
|
dataList: any = []; |
|
|
|
|
|
|
|
|
|
_backendUrl: string = undefined; |
|
|
|
|
// annotations: any = [];
|
|
|
|
|
|
|
|
|
|
private _datasourceRequest: DatasourceRequest; |
|
|
|
@ -140,7 +142,7 @@ class GraphCtrl extends MetricsPanelCtrl {
|
|
|
|
|
|
|
|
|
|
/** @ngInject */ |
|
|
|
|
constructor( |
|
|
|
|
$scope, $injector, $http, |
|
|
|
|
$scope, $injector, private $http, |
|
|
|
|
private annotationsSrv, |
|
|
|
|
private keybindingSrv, |
|
|
|
|
private backendSrv: BackendSrv, |
|
|
|
@ -154,52 +156,7 @@ class GraphCtrl extends MetricsPanelCtrl {
|
|
|
|
|
_.defaults(this.panel.legend, this.panelDefaults.legend); |
|
|
|
|
_.defaults(this.panel.xaxis, this.panelDefaults.xaxis); |
|
|
|
|
|
|
|
|
|
this.processor = new DataProcessor(this.panel); |
|
|
|
|
|
|
|
|
|
this.analyticService = new AnalyticService(this.backendURL, $http); |
|
|
|
|
|
|
|
|
|
this.runBackendConnectivityCheck(); |
|
|
|
|
|
|
|
|
|
this.analyticsController = new AnalyticController(this.panel, this.analyticService, this.events); |
|
|
|
|
|
|
|
|
|
this.bindDKey(); |
|
|
|
|
|
|
|
|
|
this.events.on('render', this.onRender.bind(this)); |
|
|
|
|
this.events.on('data-received', this.onDataReceived.bind(this)); |
|
|
|
|
this.events.on('data-error', this.onDataError.bind(this)); |
|
|
|
|
this.events.on('data-snapshot-load', this.onDataSnapshotLoad.bind(this)); |
|
|
|
|
this.events.on('init-edit-mode', this.onInitEditMode.bind(this)); |
|
|
|
|
this.events.on('init-panel-actions', this.onInitPanelActions.bind(this)); |
|
|
|
|
|
|
|
|
|
this.events.on('analytic-unit-status-change', async (analyticUnit: AnalyticUnit) => { |
|
|
|
|
if(analyticUnit === undefined) { |
|
|
|
|
throw new Error('analyticUnit is undefined'); |
|
|
|
|
} |
|
|
|
|
if(analyticUnit.status === '404') { |
|
|
|
|
await this.analyticsController.removeAnalyticUnit(analyticUnit.id, true); |
|
|
|
|
} |
|
|
|
|
if(analyticUnit.status === 'READY') { |
|
|
|
|
await this.analyticsController.fetchSegments(analyticUnit, +this.range.from, +this.range.to); |
|
|
|
|
} |
|
|
|
|
this.render(this.seriesList); |
|
|
|
|
this.$scope.$digest(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this._datasources = {}; |
|
|
|
|
|
|
|
|
|
appEvents.on('ds-request-response', data => { |
|
|
|
|
let requestConfig = data.config; |
|
|
|
|
|
|
|
|
|
this._datasourceRequest = { |
|
|
|
|
url: requestConfig.url, |
|
|
|
|
method: requestConfig.method, |
|
|
|
|
data: requestConfig.data, |
|
|
|
|
params: requestConfig.params, |
|
|
|
|
type: undefined |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.analyticsController.fetchAnalyticUnitsStatuses(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -212,11 +169,18 @@ class GraphCtrl extends MetricsPanelCtrl {
|
|
|
|
|
this.bindDKey(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
get backendURL(): string { |
|
|
|
|
if(this.templateSrv.index[BACKEND_VARIABLE_NAME] === undefined) { |
|
|
|
|
async getBackendURL(): Promise<string> { |
|
|
|
|
if(this._backendUrl !== undefined) { |
|
|
|
|
return this._backendUrl; |
|
|
|
|
} |
|
|
|
|
var data = await this.backendSrv.get('/api/plugins/hastic-app/settings'); |
|
|
|
|
if(data.jsonData === undefined) { |
|
|
|
|
return undefined; |
|
|
|
|
} |
|
|
|
|
let val = data.jsonData.hasticServerUrl; |
|
|
|
|
if(val === undefined) { |
|
|
|
|
return undefined; |
|
|
|
|
} |
|
|
|
|
let val = this.templateSrv.index[BACKEND_VARIABLE_NAME].current.value; |
|
|
|
|
val = val.replace(/\/+$/, ""); |
|
|
|
|
return val; |
|
|
|
|
} |
|
|
|
@ -235,12 +199,13 @@ class GraphCtrl extends MetricsPanelCtrl {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async runBackendConnectivityCheck() { |
|
|
|
|
if(this.backendURL === '' || this.backendURL === undefined) { |
|
|
|
|
let backendURL = await this.getBackendURL(); |
|
|
|
|
if(backendURL === '' || backendURL === undefined) { |
|
|
|
|
appEvents.emit( |
|
|
|
|
'alert-warning', |
|
|
|
|
[ |
|
|
|
|
`Dashboard variable $${BACKEND_VARIABLE_NAME} is missing`, |
|
|
|
|
`Please set $${BACKEND_VARIABLE_NAME}` |
|
|
|
|
`hasticServerUrl is missing`, |
|
|
|
|
`Please set it in config` |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
return; |
|
|
|
@ -253,13 +218,63 @@ class GraphCtrl extends MetricsPanelCtrl {
|
|
|
|
|
'alert-success', |
|
|
|
|
[ |
|
|
|
|
'Connected to Hastic server', |
|
|
|
|
`Hastic server: "${this.backendURL}"` |
|
|
|
|
`Hastic server: "${backendURL}"` |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
link(scope, elem, attrs, ctrl) { |
|
|
|
|
async link(scope, elem, attrs, ctrl) { |
|
|
|
|
|
|
|
|
|
this.processor = new DataProcessor(this.panel); |
|
|
|
|
|
|
|
|
|
let backendURL = await this.getBackendURL(); |
|
|
|
|
this.analyticService = new AnalyticService(backendURL, this.$http); |
|
|
|
|
|
|
|
|
|
this.runBackendConnectivityCheck(); |
|
|
|
|
|
|
|
|
|
this.analyticsController = new AnalyticController(this.panel, this.analyticService, this.events); |
|
|
|
|
|
|
|
|
|
this.bindDKey(); |
|
|
|
|
|
|
|
|
|
this.events.on('render', this.onRender.bind(this)); |
|
|
|
|
this.events.on('data-received', this.onDataReceived.bind(this)); |
|
|
|
|
this.events.on('data-error', this.onDataError.bind(this)); |
|
|
|
|
this.events.on('data-snapshot-load', this.onDataSnapshotLoad.bind(this)); |
|
|
|
|
this.events.on('init-edit-mode', this.onInitEditMode.bind(this)); |
|
|
|
|
this.events.on('init-panel-actions', this.onInitPanelActions.bind(this)); |
|
|
|
|
|
|
|
|
|
this.events.on('analytic-unit-status-change', async (analyticUnit: AnalyticUnit) => { |
|
|
|
|
if(analyticUnit === undefined) { |
|
|
|
|
throw new Error('analyticUnit is undefined'); |
|
|
|
|
} |
|
|
|
|
if(analyticUnit.status === '404') { |
|
|
|
|
await this.analyticsController.removeAnalyticUnit(analyticUnit.id, true); |
|
|
|
|
} |
|
|
|
|
if(analyticUnit.status === 'READY') { |
|
|
|
|
await this.analyticsController.fetchSegments(analyticUnit, +this.range.from, +this.range.to); |
|
|
|
|
} |
|
|
|
|
this.render(this.seriesList); |
|
|
|
|
this.$scope.$digest(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this._datasources = {}; |
|
|
|
|
|
|
|
|
|
appEvents.on('ds-request-response', data => { |
|
|
|
|
let requestConfig = data.config; |
|
|
|
|
|
|
|
|
|
this._datasourceRequest = { |
|
|
|
|
url: requestConfig.url, |
|
|
|
|
method: requestConfig.method, |
|
|
|
|
data: requestConfig.data, |
|
|
|
|
params: requestConfig.params, |
|
|
|
|
type: undefined |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.analyticsController.fetchAnalyticUnitsStatuses(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var $graphElem = $(elem[0]).find('#graphPanel'); |
|
|
|
|
var $legendElem = $(elem[0]).find('#graphLegend'); |
|
|
|
|
this._graphRenderer = new GraphRenderer( |
|
|
|
@ -607,12 +622,13 @@ class GraphCtrl extends MetricsPanelCtrl {
|
|
|
|
|
|
|
|
|
|
private async _updatePanelInfo() { |
|
|
|
|
const datasource = await this._getDatasourceByName(this.panel.datasource); |
|
|
|
|
const backendUrl = await this.getBackendURL(); |
|
|
|
|
|
|
|
|
|
this._panelInfo = { |
|
|
|
|
grafanaVersion: this.contextSrv.version, |
|
|
|
|
grafanaUrl: window.location.host, |
|
|
|
|
datasourceType: datasource.type, |
|
|
|
|
hasticServerUrl: this.backendURL |
|
|
|
|
hasticServerUrl: backendUrl |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|