Move health check to the backend (#2120)
This PR moves the health check to backend only leaving in the frontend the functionality to test the dbconnector datasource. Leaving the `dbconnector.testDataSource` should be fine since the datasource types we allow for db connection with Zabbix already are backend datasources, and so their health requests would go through the backend. Verified: Clicking test and seeing a `health` request go out. IMPORTANT: While testing this in the UI, I found a bug with the config editor - whenever a change is made in the UI and tested, the changes don't take effect (i.e. disabling trends, keeps `trends` set to `true`, enabling db connection keep `dbConnectionEnabled` set to `false` and so on.). Created a separate [issue](https://github.com/orgs/grafana/projects/457/views/40?pane=issue&itemId=3627315751&issue=grafana%7Coss-big-tent-squad%7C132) to fix this Fixes https://github.com/grafana/oss-big-tent-squad/issues/124 Fixes https://github.com/grafana/grafana-zabbix/issues/2004
This commit is contained in:
committed by
GitHub
parent
631d3bdc4f
commit
89ae290942
@@ -21,6 +21,7 @@ import {
|
||||
toDataQueryResponse,
|
||||
getDataSourceSrv,
|
||||
HealthCheckError,
|
||||
DataSourceWithBackend,
|
||||
} from '@grafana/runtime';
|
||||
import {
|
||||
DataFrame,
|
||||
@@ -55,6 +56,7 @@ export class ZabbixDatasource extends DataSourceApi<ZabbixMetricsQuery, ZabbixDS
|
||||
dbConnectionRetentionPolicy: string;
|
||||
enableDebugLog: boolean;
|
||||
datasourceId: number;
|
||||
instanceSettings: DataSourceInstanceSettings<ZabbixDSOptions>;
|
||||
zabbix: Zabbix;
|
||||
|
||||
replaceTemplateVars: (target: any, scopedVars?: any) => any;
|
||||
@@ -62,6 +64,7 @@ export class ZabbixDatasource extends DataSourceApi<ZabbixMetricsQuery, ZabbixDS
|
||||
constructor(instanceSettings: DataSourceInstanceSettings<ZabbixDSOptions>) {
|
||||
super(instanceSettings);
|
||||
|
||||
this.instanceSettings = instanceSettings;
|
||||
this.enableDebugLog = config.buildInfo.env === 'development';
|
||||
|
||||
this.annotations = {
|
||||
@@ -767,17 +770,20 @@ export class ZabbixDatasource extends DataSourceApi<ZabbixMetricsQuery, ZabbixDS
|
||||
* Test connection to Zabbix API and external history DB.
|
||||
*/
|
||||
async testDatasource() {
|
||||
const backendDS = new DataSourceWithBackend(this.instanceSettings);
|
||||
try {
|
||||
const { zabbixVersion, dbConnectorStatus } = await this.zabbix.testDataSource();
|
||||
let message = `Zabbix API version: ${zabbixVersion}`;
|
||||
if (dbConnectorStatus) {
|
||||
message += `, DB connector type: ${dbConnectorStatus.dsType}`;
|
||||
}
|
||||
return {
|
||||
status: 'success',
|
||||
title: 'Success',
|
||||
message: message,
|
||||
};
|
||||
const testResult = await backendDS.testDatasource();
|
||||
return this.zabbix.testDataSource().then((dbConnectorStatus) => {
|
||||
let message = testResult.message;
|
||||
if (dbConnectorStatus) {
|
||||
message += `, DB connector type: ${dbConnectorStatus.dsType}`;
|
||||
}
|
||||
return {
|
||||
status: testResult.status,
|
||||
message: message,
|
||||
title: testResult.status,
|
||||
};
|
||||
});
|
||||
} catch (error: any) {
|
||||
if (error instanceof ZabbixAPIError) {
|
||||
return Promise.reject({
|
||||
|
||||
@@ -208,32 +208,21 @@ export class Zabbix implements ZabbixConnector {
|
||||
* ```
|
||||
*/
|
||||
testDataSource() {
|
||||
let zabbixVersion;
|
||||
let dbConnectorStatus;
|
||||
return this.getVersion()
|
||||
.then((version) => {
|
||||
zabbixVersion = version;
|
||||
return this.getAllGroups();
|
||||
})
|
||||
.then(() => {
|
||||
if (this.enableDirectDBConnection) {
|
||||
return this.dbConnector.testDataSource();
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
return Promise.reject(error);
|
||||
})
|
||||
.then((testResult) => {
|
||||
|
||||
if (this.enableDirectDBConnection) {
|
||||
return this.dbConnector.testDataSource().then((testResult) => {
|
||||
if (testResult) {
|
||||
dbConnectorStatus = {
|
||||
dsType: this.dbConnector.datasourceTypeName || this.dbConnector.datasourceTypeId,
|
||||
dsName: this.dbConnector.datasourceName,
|
||||
};
|
||||
return dbConnectorStatus;
|
||||
}
|
||||
return { zabbixVersion, dbConnectorStatus };
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
async getVersion() {
|
||||
|
||||
Reference in New Issue
Block a user