Browse Source

info.ts refactorings + getHasticDatasourceURL -> getHasticDatasource + names of DSs (#214)

master
Alexey Velikiy 6 years ago committed by GitHub
parent
commit
3a377cfbc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/datasource/hastic_api.ts
  2. 6
      src/panel/graph_panel/controllers/analytic_controller.ts
  3. 26
      src/panel/graph_panel/graph_ctrl.ts
  4. 8
      src/panel/graph_panel/models/hastic_panel_info.ts
  5. 11
      src/panel/graph_panel/models/hastic_server_info.ts
  6. 6
      src/panel/graph_panel/services/analytic_service.ts

1
src/datasource/hastic_api.ts

@ -1,5 +1,6 @@
import { BackendSrv } from 'grafana/app/core/services/backend_srv';
export default class HasticAPI {
private url: string;

6
src/panel/graph_panel/controllers/analytic_controller.ts

@ -12,7 +12,7 @@ import { DatasourceRequest } from '../models/datasource';
import { Segment, SegmentId } from '../models/segment';
import { SegmentsSet } from '../models/segment_set';
import { SegmentArray } from '../models/segment_array';
import { ServerInfo, ServerInfoUnknown } from '../models/info';
import { HasticServerInfo, HasticServerInfoUnknown } from '../models/hastic_server_info';
import { Threshold, Condition } from '../models/threshold';
import text from '../partials/help_section.html';
@ -43,7 +43,7 @@ export class AnalyticController {
private _tempIdCounted: number = -1;
private _graphLocked: boolean = false;
private _statusRunners: Set<AnalyticUnitId> = new Set<AnalyticUnitId>();
private _serverInfo: ServerInfo;
private _serverInfo: HasticServerInfo;
private _currentMetric: MetricExpanded;
private _currentDatasource: DatasourceRequest;
private _thresholds: Threshold[];
@ -477,7 +477,7 @@ export class AnalyticController {
public async updateServerInfo() {
if(!this._analyticService) {
this._serverInfo = ServerInfoUnknown;
this._serverInfo = HasticServerInfoUnknown;
return;
}
this._serverInfo = await this._analyticService.getServerInfo();

26
src/panel/graph_panel/graph_ctrl.ts

@ -10,7 +10,7 @@ import { DatasourceRequest } from './models/datasource';
import { AnalyticUnitId, AnalyticUnit, LabelingMode } from './models/analytic_unit';
import { AnalyticService } from './services/analytic_service';
import { AnalyticController } from './controllers/analytic_controller';
import { PanelInfo } from './models/info';
import { HasticPanelInfo } from './models/hastic_panel_info';
import { axesEditorComponent } from './axes_editor';
@ -47,7 +47,7 @@ class GraphCtrl extends MetricsPanelCtrl {
_graphRenderer: GraphRenderer;
_graphLegend: GraphLegend;
_panelInfo: PanelInfo;
_panelInfo: HasticPanelInfo;
private _analyticUnitTypes: any;
private _hasticDatasources: any[];
@ -183,14 +183,18 @@ class GraphCtrl extends MetricsPanelCtrl {
this.rebindKeys();
}
getHasticDatasourceURL(): string | undefined {
getHasticDatasource(): { url: string, name: string } | undefined {
const hasticDatasourceId = this.panel.hasticDatasource;
if(hasticDatasourceId !== undefined && hasticDatasourceId !== null) {
const hasticDatasource = _.find(this._hasticDatasources, { id: hasticDatasourceId });
let url = hasticDatasource.url;
if(hasticDatasource.access === 'proxy') {
return `/api/datasources/proxy/${hasticDatasource.id}`;
url = `/api/datasources/proxy/${hasticDatasource.id}`
}
return {
url,
name: hasticDatasource.name
}
return hasticDatasource.url;
}
return undefined;
}
@ -296,11 +300,11 @@ class GraphCtrl extends MetricsPanelCtrl {
this.processor = new DataProcessor(this.panel);
await this._fetchHasticDatasources();
const hasticDatasourceURL = this.getHasticDatasourceURL();
if(hasticDatasourceURL === undefined) {
let hasticDatasource = this.getHasticDatasource();
if(hasticDatasource === undefined) {
delete this.analyticService;
} else {
this.analyticService = new AnalyticService(hasticDatasourceURL, this.$http);
this.analyticService = new AnalyticService(hasticDatasource.url, this.$http);
this.runDatasourceConnectivityCheck();
}
@ -651,7 +655,7 @@ class GraphCtrl extends MetricsPanelCtrl {
datasource = await this._getDatasourceByName(this.panel.datasource);
}
const backendUrl = this.getHasticDatasourceURL();
const hasticDatasource = this.getHasticDatasource();
let grafanaVersion = 'unknown';
if(_.has(window, 'grafanaBootData.settings.buildInfo.version')) {
@ -660,8 +664,10 @@ class GraphCtrl extends MetricsPanelCtrl {
this._panelInfo = {
grafanaVersion,
grafanaUrl: window.location.host,
datasourceName: datasource === undefined ? 'unknown' : datasource.name,
datasourceType: datasource === undefined ? 'unknown' : datasource.type,
hasticServerUrl: backendUrl
hasticDatasourceName: datasource === undefined ? 'unknown' : hasticDatasource.name,
hasticDatasourceUrl: hasticDatasource === undefined ? 'unknown' : hasticDatasource.url
};
}

8
src/panel/graph_panel/models/hastic_panel_info.ts

@ -0,0 +1,8 @@
export type HasticPanelInfo = {
grafanaVersion: string,
grafanaUrl: string,
datasourceName: string,
datasourceType: string,
hasticDatasourceName: string,
hasticDatasourceUrl: string
}

11
src/panel/graph_panel/models/info.ts → src/panel/graph_panel/models/hastic_server_info.ts

@ -1,4 +1,4 @@
export type ServerInfo = {
export type HasticServerInfo = {
nodeVersion: string,
packageVersion: string,
npmUserAgent: string,
@ -9,7 +9,7 @@ export type ServerInfo = {
gitCommitHash: string
}
export const ServerInfoUnknown: ServerInfo = {
export const HasticServerInfoUnknown: HasticServerInfo = {
nodeVersion: 'unknown',
packageVersion: 'unknown',
npmUserAgent: 'unknown',
@ -19,10 +19,3 @@ export const ServerInfoUnknown: ServerInfo = {
gitBranch: 'unknown',
gitCommitHash: 'unknown'
};
export type PanelInfo = {
grafanaVersion: string,
grafanaUrl: string,
datasourceType: string,
hasticServerUrl: string
}

6
src/panel/graph_panel/services/analytic_service.ts

@ -3,7 +3,7 @@ import { MetricExpanded } from '../models/metric';
import { DatasourceRequest } from '../models/datasource';
import { SegmentsSet } from '../models/segment_set';
import { AnalyticUnitId, AnalyticUnit, AnalyticSegment } from '../models/analytic_unit';
import { ServerInfo, ServerInfoUnknown } from '../models/info';
import { HasticServerInfo, HasticServerInfoUnknown } from '../models/hastic_server_info';
import { Threshold } from '../models/threshold';
import { appEvents } from 'grafana/app/core/core';
@ -150,10 +150,10 @@ export class AnalyticService {
}
}
async getServerInfo(): Promise<ServerInfo> {
async getServerInfo(): Promise<HasticServerInfo> {
const data = await this.get('/');
if(data === undefined) {
return ServerInfoUnknown;
return HasticServerInfoUnknown;
}
return {
nodeVersion: data.nodeVersion,

Loading…
Cancel
Save