[v9.2.x] SQL: Fix issue where testing the datasource would always be successful if the datasourceQueryMultiStatus feature was enabled (#58685)
SQL: Fix issue where testing the datasource would always be successful if the `datasourceQueryMultiStatus` feature was enabled (#58671)
SQL Datasources: fix issue where testing the datasource connection would show success even when there was an error.
Co-authored-by: Victor Marin <victor.marin@grafana.com>
(cherry picked from commit 75e435fb00)
Co-authored-by: Oscar Kilhed <oscar.kilhed@grafana.com>
This commit is contained in:
co-authored by
Oscar Kilhed
parent
1cf016c9b2
commit
0c9e3abc52
@@ -160,9 +160,10 @@ export abstract class SqlDatasource extends DataSourceWithBackend<SQLQuery, SQLO
|
||||
}
|
||||
|
||||
testDatasource(): Promise<{ status: string; message: string }> {
|
||||
const refId = 'A';
|
||||
return lastValueFrom(
|
||||
getBackendSrv()
|
||||
.fetch({
|
||||
.fetch<BackendDataSourceResponse>({
|
||||
url: '/api/ds/query',
|
||||
method: 'POST',
|
||||
data: {
|
||||
@@ -170,7 +171,7 @@ export abstract class SqlDatasource extends DataSourceWithBackend<SQLQuery, SQLO
|
||||
to: 'now',
|
||||
queries: [
|
||||
{
|
||||
refId: 'A',
|
||||
refId: refId,
|
||||
intervalMs: 1,
|
||||
maxDataPoints: 1,
|
||||
datasource: this.getRef(),
|
||||
@@ -182,7 +183,13 @@ export abstract class SqlDatasource extends DataSourceWithBackend<SQLQuery, SQLO
|
||||
},
|
||||
})
|
||||
.pipe(
|
||||
map(() => ({ status: 'success', message: 'Database Connection OK' })),
|
||||
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));
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user