diff --git a/.gitignore b/.gitignore index 21083741e14..7172e6af575 100644 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,4 @@ debug.test /devenv/bulk_alerting_dashboards/*.json /scripts/build/release_publisher/release_publisher +*.patch diff --git a/public/app/features/datasources/state/actions.ts b/public/app/features/datasources/state/actions.ts index ff8af8b4c9d..1bef610ff29 100644 --- a/public/app/features/datasources/state/actions.ts +++ b/public/app/features/datasources/state/actions.ts @@ -1,11 +1,14 @@ import { ThunkAction } from 'redux-thunk'; import { DataSource, Plugin, StoreState } from 'app/types'; import { getBackendSrv } from '../../../core/services/backend_srv'; +import { getDatasourceSrv } from '../../plugins/datasource_srv'; import { LayoutMode } from '../../../core/components/LayoutSelector/LayoutSelector'; import { updateLocation, updateNavIndex, UpdateNavIndexAction } from '../../../core/actions'; import { UpdateLocationAction } from '../../../core/actions/location'; import { buildNavModel } from './navModel'; +import config from '../../../core/config'; + export enum ActionTypes { LoadDataSources = 'LOAD_DATA_SOURCES', LoadDataSourceTypes = 'LOAD_DATA_SOURCE_TYPES', @@ -159,7 +162,14 @@ export function loadDataSourceTypes(): ThunkResult { export function updateDataSource(dataSource: DataSource): ThunkResult { return async dispatch => { - await getBackendSrv().put(`/api/datasources/${dataSource.id}`, dataSource); + await getBackendSrv() + .put(`/api/datasources/${dataSource.id}`, dataSource) + .then(response => { + updateFrontendSettings().then(() => { + testDataSource(response.name); + }); + }); + dispatch(loadDataSource(dataSource.id)); }; } @@ -201,6 +211,49 @@ export function findNewName(dataSources, name) { return name; } +function updateFrontendSettings() { + return getBackendSrv() + .get('/api/frontend/settings') + .then(settings => { + config.datasources = settings.datasources; + config.defaultDatasource = settings.defaultDatasource; + getDatasourceSrv().init(); + }); +} + +function testDataSource(name) { + getDatasourceSrv() + .get(name) + .then(dataSource => { + if (!dataSource.testDatasource) { + return; + } + + const testing = { done: false, status: 'error', message: '' }; + + // make test call in no backend cache context + getBackendSrv() + .withNoBackendCache(() => { + return dataSource + .testDatasource() + .then(result => { + testing.message = result.message; + testing.status = result.status; + }) + .catch(err => { + if (err.statusText) { + testing.message = 'HTTP Error ' + err.statusText; + } else { + testing.message = err.message; + } + }); + }) + .finally(() => { + testing.done = true; + }); + }); +} + function nameHasSuffix(name) { return name.endsWith('-', name.length - 1); } diff --git a/public/app/types/series.ts b/public/app/types/series.ts index 5396880611b..997090bf541 100644 --- a/public/app/types/series.ts +++ b/public/app/types/series.ts @@ -88,4 +88,5 @@ export interface DataQueryOptions { export interface DataSourceApi { query(options: DataQueryOptions): Promise; + testDatasource(): Promise; }