|
|
@ -1,6 +1,6 @@ |
|
|
|
import './series_overrides_ctrl'; |
|
|
|
import './series_overrides_ctrl'; |
|
|
|
|
|
|
|
|
|
|
|
import template from './template'; |
|
|
|
import template from './template.html'; |
|
|
|
|
|
|
|
|
|
|
|
import { GraphRenderer } from './graph_renderer'; |
|
|
|
import { GraphRenderer } from './graph_renderer'; |
|
|
|
import { GraphLegend } from './graph_legend'; |
|
|
|
import { GraphLegend } from './graph_legend'; |
|
|
@ -31,6 +31,8 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
hiddenSeries: any = {}; |
|
|
|
hiddenSeries: any = {}; |
|
|
|
seriesList: any = []; |
|
|
|
seriesList: any = []; |
|
|
|
dataList: any = []; |
|
|
|
dataList: any = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_backendUrl: string = undefined; |
|
|
|
// annotations: any = [];
|
|
|
|
// annotations: any = [];
|
|
|
|
|
|
|
|
|
|
|
|
private _datasourceRequest: DatasourceRequest; |
|
|
|
private _datasourceRequest: DatasourceRequest; |
|
|
@ -140,7 +142,7 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
|
|
|
|
|
|
|
|
/** @ngInject */ |
|
|
|
/** @ngInject */ |
|
|
|
constructor( |
|
|
|
constructor( |
|
|
|
$scope, $injector, $http, |
|
|
|
$scope, $injector, private $http, |
|
|
|
private annotationsSrv, |
|
|
|
private annotationsSrv, |
|
|
|
private keybindingSrv, |
|
|
|
private keybindingSrv, |
|
|
|
private backendSrv: BackendSrv, |
|
|
|
private backendSrv: BackendSrv, |
|
|
@ -154,52 +156,7 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
_.defaults(this.panel.legend, this.panelDefaults.legend); |
|
|
|
_.defaults(this.panel.legend, this.panelDefaults.legend); |
|
|
|
_.defaults(this.panel.xaxis, this.panelDefaults.xaxis); |
|
|
|
_.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(); |
|
|
|
this.bindDKey(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
get backendURL(): string { |
|
|
|
async getBackendURL(): Promise<string> { |
|
|
|
if(this.templateSrv.index[BACKEND_VARIABLE_NAME] === undefined) { |
|
|
|
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; |
|
|
|
return undefined; |
|
|
|
} |
|
|
|
} |
|
|
|
let val = this.templateSrv.index[BACKEND_VARIABLE_NAME].current.value; |
|
|
|
|
|
|
|
val = val.replace(/\/+$/, ""); |
|
|
|
val = val.replace(/\/+$/, ""); |
|
|
|
return val; |
|
|
|
return val; |
|
|
|
} |
|
|
|
} |
|
|
@ -235,12 +199,13 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async runBackendConnectivityCheck() { |
|
|
|
async runBackendConnectivityCheck() { |
|
|
|
if(this.backendURL === '' || this.backendURL === undefined) { |
|
|
|
let backendURL = await this.getBackendURL(); |
|
|
|
|
|
|
|
if(backendURL === '' || backendURL === undefined) { |
|
|
|
appEvents.emit( |
|
|
|
appEvents.emit( |
|
|
|
'alert-warning', |
|
|
|
'alert-warning', |
|
|
|
[ |
|
|
|
[ |
|
|
|
`Dashboard variable $${BACKEND_VARIABLE_NAME} is missing`, |
|
|
|
`hasticServerUrl is missing`, |
|
|
|
`Please set $${BACKEND_VARIABLE_NAME}` |
|
|
|
`Please set it in config` |
|
|
|
] |
|
|
|
] |
|
|
|
); |
|
|
|
); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -253,13 +218,63 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
'alert-success', |
|
|
|
'alert-success', |
|
|
|
[ |
|
|
|
[ |
|
|
|
'Connected to Hastic server', |
|
|
|
'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 $graphElem = $(elem[0]).find('#graphPanel'); |
|
|
|
var $legendElem = $(elem[0]).find('#graphLegend'); |
|
|
|
var $legendElem = $(elem[0]).find('#graphLegend'); |
|
|
|
this._graphRenderer = new GraphRenderer( |
|
|
|
this._graphRenderer = new GraphRenderer( |
|
|
@ -607,12 +622,13 @@ class GraphCtrl extends MetricsPanelCtrl { |
|
|
|
|
|
|
|
|
|
|
|
private async _updatePanelInfo() { |
|
|
|
private async _updatePanelInfo() { |
|
|
|
const datasource = await this._getDatasourceByName(this.panel.datasource); |
|
|
|
const datasource = await this._getDatasourceByName(this.panel.datasource); |
|
|
|
|
|
|
|
const backendUrl = await this.getBackendURL(); |
|
|
|
|
|
|
|
|
|
|
|
this._panelInfo = { |
|
|
|
this._panelInfo = { |
|
|
|
grafanaVersion: this.contextSrv.version, |
|
|
|
grafanaVersion: this.contextSrv.version, |
|
|
|
grafanaUrl: window.location.host, |
|
|
|
grafanaUrl: window.location.host, |
|
|
|
datasourceType: datasource.type, |
|
|
|
datasourceType: datasource.type, |
|
|
|
hasticServerUrl: this.backendURL |
|
|
|
hasticServerUrl: backendUrl |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|