mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 23:35:15 +08:00
Provisioning: Allows specifying uid for datasource and use that in derived fields (#23585)
* Add uid to datasource * Fix uid passing when provisioning * Better error handling and Uid column type change * Fix test and strict null error counts * Add backend tests * Add tests * Fix strict null checks * Update test * Improve tests * Update pkg/services/sqlstore/datasource.go Co-Authored-By: Arve Knudsen <arve.knudsen@gmail.com> * Variable rename Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@ -6,7 +6,7 @@ import config from 'app/core/config';
|
||||
import { importDataSourcePlugin } from './plugin_loader';
|
||||
import { DataSourceSrv as DataSourceService, getDataSourceSrv as getDataSourceService } from '@grafana/runtime';
|
||||
// Types
|
||||
import { AppEvents, DataSourceApi, DataSourceSelectItem, ScopedVars } from '@grafana/data';
|
||||
import { AppEvents, DataSourceApi, DataSourceInstanceSettings, DataSourceSelectItem, ScopedVars } from '@grafana/data';
|
||||
import { auto } from 'angular';
|
||||
import { TemplateSrv } from '../templating/template_srv';
|
||||
import { GrafanaRootScope } from 'app/routes/GrafanaCtrl';
|
||||
@ -30,6 +30,10 @@ export class DatasourceSrv implements DataSourceService {
|
||||
this.datasources = {};
|
||||
}
|
||||
|
||||
getDataSourceSettingsByUid(uid: string): DataSourceInstanceSettings | undefined {
|
||||
return Object.values(config.datasources).find(ds => ds.uid === uid);
|
||||
}
|
||||
|
||||
get(name?: string, scopedVars?: ScopedVars): Promise<DataSourceApi> {
|
||||
if (!name) {
|
||||
return this.get(config.defaultDatasource);
|
||||
@ -93,12 +97,12 @@ export class DatasourceSrv implements DataSourceService {
|
||||
}
|
||||
}
|
||||
|
||||
getAll() {
|
||||
getAll(): DataSourceInstanceSettings[] {
|
||||
const { datasources } = config;
|
||||
return Object.keys(datasources).map(name => datasources[name]);
|
||||
}
|
||||
|
||||
getExternal() {
|
||||
getExternal(): DataSourceInstanceSettings[] {
|
||||
const datasources = this.getAll().filter(ds => !ds.meta.builtIn);
|
||||
return sortBy(datasources, ['name']);
|
||||
}
|
||||
|
Reference in New Issue
Block a user