SQL Datasources: Use health check for config test (#59867)

* SQL Datasources: Use health check for config test

* Remove unnecessary test

* Fix test errors

* Revert mysql go driver update

* Use transform query error

* Use TransformQueryError from sql_engine
This commit is contained in:
Zoltán Bedi
2022-12-19 17:17:52 +01:00
committed by GitHub
parent 77786f236a
commit c25fe34ac0
7 changed files with 65 additions and 86 deletions

View File

@@ -1,5 +1,5 @@
import { lastValueFrom, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { lastValueFrom } from 'rxjs';
import { map } from 'rxjs/operators';
import {
DataFrame,
@@ -19,7 +19,7 @@ import {
getTemplateSrv,
TemplateSrv,
} from '@grafana/runtime';
import { toDataQueryResponse, toTestingStatus } from '@grafana/runtime/src/utils/queryResponse';
import { toDataQueryResponse } from '@grafana/runtime/src/utils/queryResponse';
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
import { VariableWithMultiSupport } from '../../../variables/types';
@@ -170,45 +170,6 @@ export abstract class SqlDatasource extends DataSourceWithBackend<SQLQuery, SQLO
);
}
testDatasource(): Promise<{ status: string; message: string }> {
const refId = 'A';
return lastValueFrom(
getBackendSrv()
.fetch<BackendDataSourceResponse>({
url: '/api/ds/query',
method: 'POST',
headers: this.getRequestHeaders(),
data: {
from: '5m',
to: 'now',
queries: [
{
refId: refId,
intervalMs: 1,
maxDataPoints: 1,
datasource: this.getRef(),
datasourceId: this.id,
rawSql: 'SELECT 1',
format: 'table',
},
],
},
})
.pipe(
map((r) => {
const error = r.data.results[refId].error;
if (error) {
return { status: 'error', message: error };
}
return { status: 'success', message: 'Database Connection OK' };
}),
catchError((err) => {
return of(toTestingStatus(err));
})
)
);
}
targetContainsTemplate(target: SQLQuery) {
let queryWithoutMacros = target.rawSql;
MACRO_NAMES.forEach((value) => {