Migrate backendSrv to getBackendSrv, fix direct DB connection

This commit is contained in:
Alexander Zobnin
2020-03-20 17:03:49 +03:00
parent 58949be25e
commit dad0fd965d
14 changed files with 975 additions and 240 deletions

View File

@@ -29,8 +29,9 @@
"@babel/preset-env": "^7.7.7", "@babel/preset-env": "^7.7.7",
"@babel/preset-react": "^7.6.3", "@babel/preset-react": "^7.6.3",
"@emotion/core": "^10.0.27", "@emotion/core": "^10.0.27",
"@grafana/data": "^6.4.2", "@grafana/data": "^6.7.0",
"@grafana/ui": "^6.4.2", "@grafana/ui": "^6.7.0",
"@grafana/runtime": "^6.7.0",
"@types/classnames": "^2.2.6", "@types/classnames": "^2.2.6",
"@types/grafana": "github:CorpGlory/types-grafana", "@types/grafana": "github:CorpGlory/types-grafana",
"@types/jest": "^23.1.1", "@types/jest": "^23.1.1",
@@ -70,7 +71,7 @@
"react": "^16.7.0", "react": "^16.7.0",
"react-dom": "^16.7.0", "react-dom": "^16.7.0",
"react-popper": "^1.3.2", "react-popper": "^1.3.2",
"react-table": "^6.8.6", "react-table-6": "^6.8.6",
"react-test-renderer": "^16.7.0", "react-test-renderer": "^16.7.0",
"react-transition-group": "^2.5.2", "react-transition-group": "^2.5.2",
"rst2html": "github:thoward/rst2html#990cb89", "rst2html": "github:thoward/rst2html#990cb89",

View File

@@ -1,7 +1,8 @@
import React, { FC } from 'react'; import React, { FC } from 'react';
import { css, cx } from 'emotion'; import { css, cx } from 'emotion';
import { Themeable, withTheme, Input, GrafanaTheme, EventsWithValidation, ValidationEvents } from '@grafana/ui'; import { Themeable, withTheme, Input, EventsWithValidation, ValidationEvents } from '@grafana/ui';
import { isRegex, variableRegex } from '../utils'; import { isRegex, variableRegex } from '../utils';
import { GrafanaTheme } from '@grafana/data';
const variablePattern = RegExp(`^${variableRegex.source}`); const variablePattern = RegExp(`^${variableRegex.source}`);

View File

@@ -16,7 +16,7 @@ const DEFAULT_ZABBIX_VERSION = 3;
export class ZabbixDatasource { export class ZabbixDatasource {
/** @ngInject */ /** @ngInject */
constructor(instanceSettings, templateSrv, backendSrv, datasourceSrv, zabbixAlertingSrv) { constructor(instanceSettings, templateSrv, datasourceSrv, zabbixAlertingSrv) {
this.templateSrv = templateSrv; this.templateSrv = templateSrv;
this.zabbixAlertingSrv = zabbixAlertingSrv; this.zabbixAlertingSrv = zabbixAlertingSrv;
@@ -75,7 +75,7 @@ export class ZabbixDatasource {
dbConnectionRetentionPolicy: this.dbConnectionRetentionPolicy, dbConnectionRetentionPolicy: this.dbConnectionRetentionPolicy,
}; };
this.zabbix = new Zabbix(zabbixOptions, datasourceSrv, backendSrv); this.zabbix = new Zabbix(zabbixOptions, datasourceSrv);
} }
//////////////////////// ////////////////////////

View File

@@ -21,11 +21,11 @@ describe('ZabbixDatasource', () => {
}; };
ctx.templateSrv = mocks.templateSrvMock; ctx.templateSrv = mocks.templateSrvMock;
ctx.backendSrv = mocks.backendSrvMock; // ctx.backendSrv = mocks.backendSrvMock;
ctx.datasourceSrv = mocks.datasourceSrvMock; ctx.datasourceSrv = mocks.datasourceSrvMock;
ctx.zabbixAlertingSrv = mocks.zabbixAlertingSrvMock; ctx.zabbixAlertingSrv = mocks.zabbixAlertingSrvMock;
ctx.ds = new Datasource(ctx.instanceSettings, ctx.templateSrv, ctx.backendSrv, ctx.datasourceSrv, ctx.zabbixAlertingSrv); ctx.ds = new Datasource(ctx.instanceSettings, ctx.templateSrv, ctx.datasourceSrv, ctx.zabbixAlertingSrv);
}); });
describe('When querying data', () => { describe('When querying data', () => {

View File

@@ -1,4 +1,5 @@
import _ from 'lodash'; import _ from 'lodash';
import { getBackendSrv } from '@grafana/runtime';
import { compactQuery } from '../../../utils'; import { compactQuery } from '../../../utils';
import mysql from './mysql'; import mysql from './mysql';
import postgres from './postgres'; import postgres from './postgres';
@@ -17,8 +18,7 @@ export class SQLConnector extends DBConnector {
this.sqlDialect = null; this.sqlDialect = null;
super.loadDBDataSource() super.loadDBDataSource()
.then(ds => { .then(() => {
this.backendSrv = ds.backendSrv;
this.loadSQLDialect(); this.loadSQLDialect();
}); });
} }
@@ -96,7 +96,7 @@ export class SQLConnector extends DBConnector {
maxDataPoints: this.limit maxDataPoints: this.limit
}; };
return this.backendSrv.datasourceRequest({ return getBackendSrv().datasourceRequest({
url: '/api/tsdb/query', url: '/api/tsdb/query',
method: 'POST', method: 'POST',
data: { data: {

View File

@@ -10,7 +10,7 @@ import { ZBX_ACK_ACTION_NONE, ZBX_ACK_ACTION_ACK, ZBX_ACK_ACTION_ADD_MESSAGE, MI
* Wraps API calls and provides high-level methods. * Wraps API calls and provides high-level methods.
*/ */
export class ZabbixAPIConnector { export class ZabbixAPIConnector {
constructor(api_url, username, password, version, basicAuth, withCredentials, backendSrv) { constructor(api_url, username, password, version, basicAuth, withCredentials) {
this.url = api_url; this.url = api_url;
this.username = username; this.username = username;
this.password = password; this.password = password;
@@ -26,7 +26,7 @@ export class ZabbixAPIConnector {
this.loginErrorCount = 0; this.loginErrorCount = 0;
this.maxLoginAttempts = 3; this.maxLoginAttempts = 3;
this.zabbixAPICore = new ZabbixAPICore(backendSrv); this.zabbixAPICore = new ZabbixAPICore();
this.getTrend = this.getTrend_ZBXNEXT1193; this.getTrend = this.getTrend_ZBXNEXT1193;
//getTrend = getTrend_30; //getTrend = getTrend_30;

View File

@@ -1,12 +1,12 @@
/** /**
* General Zabbix API methods * General Zabbix API methods
*/ */
import { getBackendSrv } from '@grafana/runtime';
export class ZabbixAPICore { export class ZabbixAPICore {
/** @ngInject */ /** @ngInject */
constructor(backendSrv) { constructor() {
this.backendSrv = backendSrv;
} }
/** /**
@@ -50,7 +50,7 @@ export class ZabbixAPICore {
} }
datasourceRequest(requestOptions) { datasourceRequest(requestOptions) {
return this.backendSrv.datasourceRequest(requestOptions) return getBackendSrv().datasourceRequest(requestOptions)
.then((response) => { .then((response) => {
if (!response.data) { if (!response.data) {
return Promise.reject(new ZabbixAPIError({data: "General Error, no data"})); return Promise.reject(new ZabbixAPIError({data: "General Error, no data"}));

View File

@@ -25,7 +25,7 @@ const REQUESTS_TO_BIND = [
]; ];
export class Zabbix { export class Zabbix {
constructor(options, datasourceSrv, backendSrv) { constructor(options, datasourceSrv) {
let { let {
url, url,
username, username,
@@ -49,7 +49,7 @@ export class Zabbix {
}; };
this.cachingProxy = new CachingProxy(cacheOptions); this.cachingProxy = new CachingProxy(cacheOptions);
this.zabbixAPI = new ZabbixAPIConnector(url, username, password, zabbixVersion, basicAuth, withCredentials, backendSrv); this.zabbixAPI = new ZabbixAPIConnector(url, username, password, zabbixVersion, basicAuth, withCredentials);
this.proxyfyRequests(); this.proxyfyRequests();
this.cacheRequests(); this.cacheRequests();

View File

@@ -13,9 +13,9 @@ describe('Zabbix', () => {
beforeEach(() => { beforeEach(() => {
ctx.options = options; ctx.options = options;
ctx.backendSrv = mocks.backendSrvMock; // ctx.backendSrv = mocks.backendSrvMock;
ctx.datasourceSrv = mocks.datasourceSrvMock; ctx.datasourceSrv = mocks.datasourceSrvMock;
zabbix = new Zabbix(ctx.options, ctx.backendSrvMock, ctx.datasourceSrvMock); zabbix = new Zabbix(ctx.options, ctx.datasourceSrvMock);
}); });
describe('When querying proxies', () => { describe('When querying proxies', () => {

View File

@@ -1,5 +1,5 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import ReactTable from 'react-table'; import ReactTable from 'react-table-6';
import classNames from 'classnames'; import classNames from 'classnames';
import _ from 'lodash'; import _ from 'lodash';
import moment from 'moment'; import moment from 'moment';
@@ -18,8 +18,8 @@ export interface ProblemListProps {
timeRange?: GFTimeRange; timeRange?: GFTimeRange;
pageSize?: number; pageSize?: number;
fontSize?: number; fontSize?: number;
getProblemEvents: (problem: ZBXTrigger) => ZBXEvent[]; getProblemEvents: (problem: ZBXTrigger) => Promise<ZBXEvent[]>;
getProblemAlerts: (problem: ZBXTrigger) => ZBXAlert[]; getProblemAlerts: (problem: ZBXTrigger) => Promise<ZBXAlert[]>;
onProblemAck?: (problem: ZBXTrigger, data: AckProblemData) => void; onProblemAck?: (problem: ZBXTrigger, data: AckProblemData) => void;
onTagClick?: (tag: ZBXTag, datasource: string, ctrlKey?: boolean, shiftKey?: boolean) => void; onTagClick?: (tag: ZBXTag, datasource: string, ctrlKey?: boolean, shiftKey?: boolean) => void;
onPageSizeChange?: (pageSize: number, pageIndex: number) => void; onPageSizeChange?: (pageSize: number, pageIndex: number) => void;
@@ -163,6 +163,7 @@ export default class ProblemList extends PureComponent<ProblemListProps, Problem
getProblemAlerts={this.props.getProblemAlerts} getProblemAlerts={this.props.getProblemAlerts}
onProblemAck={this.handleProblemAck} onProblemAck={this.handleProblemAck}
onTagClick={this.handleTagClick} onTagClick={this.handleTagClick}
subRows={false}
/> />
} }
expanded={this.getExpandedPage(this.state.page)} expanded={this.getExpandedPage(this.state.page)}

View File

@@ -1,6 +1,6 @@
import _ from 'lodash'; import _ from 'lodash';
import moment from 'moment'; import moment from 'moment';
import { DataQuery } from '@grafana/ui/'; import { DataQuery } from '@grafana/data';
import * as utils from '../datasource-zabbix/utils'; import * as utils from '../datasource-zabbix/utils';
import { ZBXTrigger } from './types'; import { ZBXTrigger } from './types';

View File

@@ -1,5 +1,5 @@
// DEPENDENCIES // DEPENDENCIES
@import '../../node_modules/react-table/react-table.css'; @import '../../node_modules/react-table-6/react-table.css';
@import 'variables'; @import 'variables';
@import 'panel-triggers'; @import 'panel-triggers';

View File

@@ -28,7 +28,7 @@ module.exports = {
externals: [ externals: [
// remove the line below if you don't want to use builtin versions // remove the line below if you don't want to use builtin versions
'jquery', 'lodash', 'moment', 'angular', 'emotion', 'jquery', 'lodash', 'moment', 'angular', 'emotion',
'react', 'react-dom', '@grafana/ui', '@grafana/data', 'react', 'react-dom', '@grafana/ui', '@grafana/data', '@grafana/runtime',
function (context, request, callback) { function (context, request, callback) {
var prefix = 'grafana/'; var prefix = 'grafana/';
if (request.indexOf(prefix) === 0) { if (request.indexOf(prefix) === 0) {

1158
yarn.lock

File diff suppressed because it is too large Load Diff