mirror of https://github.com/grafana/grafana.git
DataSourceSrv: Filter out non queryable data sources by default (#31144)
This commit is contained in:
parent
0c3c17592e
commit
50faeb3078
|
|
@ -28,12 +28,31 @@ export interface DataSourceSrv {
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
export interface GetDataSourceListFilters {
|
export interface GetDataSourceListFilters {
|
||||||
|
/** Include mixed deta source by setting this to true */
|
||||||
mixed?: boolean;
|
mixed?: boolean;
|
||||||
|
|
||||||
|
/** Only return data sources that support metrics response */
|
||||||
metrics?: boolean;
|
metrics?: boolean;
|
||||||
|
|
||||||
|
/** Only return data sources that support tracing response */
|
||||||
tracing?: boolean;
|
tracing?: boolean;
|
||||||
|
|
||||||
|
/** Only return data sources that support annotations */
|
||||||
annotations?: boolean;
|
annotations?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default only data sources that can be queried will be returned. Meaning they have tracing,
|
||||||
|
* metrics, logs or annotations flag set in plugin.json file
|
||||||
|
* */
|
||||||
|
all?: boolean;
|
||||||
|
|
||||||
|
/** Set to true to return dashboard data source */
|
||||||
dashboard?: boolean;
|
dashboard?: boolean;
|
||||||
|
|
||||||
|
/** Set to true to return data source variables */
|
||||||
variables?: boolean;
|
variables?: boolean;
|
||||||
|
|
||||||
|
/** filter list by plugin */
|
||||||
pluginId?: string;
|
pluginId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -157,6 +157,15 @@ export class DatasourceSrv implements DataSourceService {
|
||||||
if (filters.pluginId && x.meta.id !== filters.pluginId) {
|
if (filters.pluginId && x.meta.id !== filters.pluginId) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
!filters.all &&
|
||||||
|
x.meta.metrics !== true &&
|
||||||
|
x.meta.annotations !== true &&
|
||||||
|
x.meta.tracing !== true &&
|
||||||
|
x.meta.logs !== true
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,12 @@ describe('datasource_srv', () => {
|
||||||
uid: 'uid-code-Jaeger',
|
uid: 'uid-code-Jaeger',
|
||||||
meta: { tracing: true, id: 'jaeger' },
|
meta: { tracing: true, id: 'jaeger' },
|
||||||
},
|
},
|
||||||
|
CannotBeQueried: {
|
||||||
|
type: 'no-query',
|
||||||
|
name: 'no-query',
|
||||||
|
uid: 'no-query',
|
||||||
|
meta: { id: 'no-query' },
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('Given a list of data sources', () => {
|
describe('Given a list of data sources', () => {
|
||||||
|
|
@ -120,6 +126,13 @@ describe('datasource_srv', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should by default filter out data sources that cannot be queried', () => {
|
||||||
|
const list = dataSourceSrv.getList({});
|
||||||
|
expect(list.find((x) => x.name === 'no-query')).toBeUndefined();
|
||||||
|
const all = dataSourceSrv.getList({ all: true });
|
||||||
|
expect(all.find((x) => x.name === 'no-query')).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
it('Can get list of data sources with variables: true', () => {
|
it('Can get list of data sources with variables: true', () => {
|
||||||
const list = dataSourceSrv.getList({ metrics: true, variables: true });
|
const list = dataSourceSrv.getList({ metrics: true, variables: true });
|
||||||
expect(list[0].name).toBe('${datasource}');
|
expect(list[0].name).toBe('${datasource}');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue