mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user