@grafana/data#DataSourcePluginMeta TypeScript Examples
The following examples show how to use
@grafana/data#DataSourcePluginMeta.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NewDataSourcePage.tsx From grafana-chinese with Apache License 2.0 | 6 votes |
renderPlugins(plugins: DataSourcePluginMeta[]) {
if (!plugins || !plugins.length) {
return null;
}
return (
<List
items={plugins}
getItemKey={item => item.id.toString()}
renderItem={item => (
<DataSourceTypeCard
plugin={item}
onClick={() => this.onDataSourceTypeClicked(item)}
onLearnMoreClick={this.onLearnMoreClick}
/>
)}
/>
);
}
Example #2
Source File: actions.ts From grafana-chinese with Apache License 2.0 | 6 votes |
initQueryVariableEditor = (identifier: VariableIdentifier): ThunkResult<void> => async (
dispatch,
getState
) => {
const dataSources: DataSourceSelectItem[] = getDatasourceSrv()
.getMetricSources()
.filter(ds => !ds.meta.mixed && ds.value !== null);
const defaultDatasource: DataSourceSelectItem = { name: '', value: '', meta: {} as DataSourcePluginMeta, sort: '' };
const allDataSources = [defaultDatasource].concat(dataSources);
dispatch(changeVariableEditorExtended({ propName: 'dataSources', propValue: allDataSources }));
const variable = getVariable<QueryVariableModel>(identifier.uuid!, getState());
if (!variable.datasource) {
return;
}
dispatch(changeQueryVariableDataSource(toVariableIdentifier(variable), variable.datasource));
}
Example #3
Source File: actions.ts From grafana-chinese with Apache License 2.0 | 6 votes |
export function loadDataSource(id: number): ThunkResult<void> {
return async dispatch => {
const dataSource = await getBackendSrv().get(`/api/datasources/${id}`);
const pluginInfo = (await getPluginSettings(dataSource.type)) as DataSourcePluginMeta;
const plugin = await importDataSourcePlugin(pluginInfo);
dispatch(dataSourceLoaded(dataSource));
dispatch(dataSourceMetaLoaded(pluginInfo));
dispatch(updateNavIndex(buildNavModel(dataSource, plugin)));
};
}
Example #4
Source File: actions.ts From grafana-chinese with Apache License 2.0 | 6 votes |
export function addDataSource(plugin: DataSourcePluginMeta): ThunkResult<void> {
return async (dispatch, getStore) => {
await dispatch(loadDataSources());
const dataSources = getStore().dataSources.dataSources;
const newInstance = {
name: plugin.name,
type: plugin.id,
access: 'proxy',
isDefault: dataSources.length === 0,
};
if (nameExits(dataSources, newInstance.name)) {
newInstance.name = findNewName(dataSources, newInstance.name);
}
const result = await getBackendSrv().post('/api/datasources', newInstance);
dispatch(updateLocation({ path: `/datasources/edit/${result.id}` }));
};
}
Example #5
Source File: buildCategories.test.ts From grafana-chinese with Apache License 2.0 | 6 votes |
plugins: DataSourcePluginMeta[] = [
{
...getMockPlugin({ id: 'graphite' }),
category: 'tsdb',
},
{
...getMockPlugin({ id: 'prometheus' }),
category: 'tsdb',
},
{
...getMockPlugin({ id: 'elasticsearch' }),
category: 'logging',
},
{
...getMockPlugin({ id: 'loki' }),
category: 'logging',
},
{
...getMockPlugin({ id: 'azure' }),
category: 'cloud',
},
]
Example #6
Source File: buildCategories.ts From grafana-chinese with Apache License 2.0 | 6 votes |
function sortPlugins(plugins: DataSourcePluginMeta[]) {
const sortingRules: { [id: string]: number } = {
prometheus: 100,
graphite: 95,
loki: 90,
mysql: 80,
postgres: 79,
gcloud: -1,
};
plugins.sort((a, b) => {
const aSort = sortingRules[a.id] || 0;
const bSort = sortingRules[b.id] || 0;
if (aSort > bSort) {
return -1;
}
if (aSort < bSort) {
return 1;
}
return a.name > b.name ? -1 : 1;
});
}
Example #7
Source File: plugin_loader.ts From grafana-chinese with Apache License 2.0 | 6 votes |
export function importDataSourcePlugin(meta: DataSourcePluginMeta): Promise<GenericDataSourcePlugin> {
return importPluginModule(meta.module).then(pluginExports => {
if (pluginExports.plugin) {
const dsPlugin = pluginExports.plugin as GenericDataSourcePlugin;
dsPlugin.meta = meta;
return dsPlugin;
}
if (pluginExports.Datasource) {
const dsPlugin = new DataSourcePlugin<
DataSourceApi<DataQuery, DataSourceJsonData>,
DataQuery,
DataSourceJsonData
>(pluginExports.Datasource);
dsPlugin.setComponentsFromLegacyExports(pluginExports);
dsPlugin.meta = meta;
return dsPlugin;
}
throw new Error('Plugin module is missing DataSourcePlugin or Datasource constructor export');
});
}
Example #8
Source File: buildCategories.ts From grafana-chinese with Apache License 2.0 | 6 votes |
function getGrafanaCloudPhantomPlugin(): DataSourcePluginMeta {
return {
id: 'gcloud',
name: 'Grafana Cloud',
type: PluginType.datasource,
module: 'phantom',
baseUrl: '',
info: {
description: 'Hosted Graphite, Prometheus and Loki',
logos: { small: 'public/img/grafana_icon.svg', large: 'asd' },
author: { name: 'Grafana Labs' },
links: [
{
url: 'https://grafana.com/products/cloud/',
name: 'Learn more',
},
],
screenshots: [],
updated: '2019-05-10',
version: '1.0.0',
},
};
}
Example #9
Source File: buildCategories.ts From grafana-chinese with Apache License 2.0 | 6 votes |
function getPhantomPlugin(options: GetPhantomPluginOptions): DataSourcePluginMeta {
return {
id: options.id,
name: options.name,
type: PluginType.datasource,
module: 'phantom',
baseUrl: '',
info: {
description: options.description,
logos: { small: options.imgUrl, large: options.imgUrl },
author: { name: 'Grafana Labs' },
links: [
{
url: 'https://grafana.com/grafana/plugins/' + options.id,
name: 'Install now',
},
],
screenshots: [],
updated: '2019-05-10',
version: '1.0.0',
},
};
}
Example #10
Source File: reducers.ts From grafana-chinese with Apache License 2.0 | 6 votes |
initialState: DataSourcesState = {
dataSources: [],
plugins: [],
categories: [],
dataSource: {} as DataSourceSettings,
layoutMode: LayoutModes.List,
searchQuery: '',
dataSourcesCount: 0,
dataSourceTypeSearchQuery: '',
hasFetched: false,
isLoadingDataSources: false,
dataSourceMeta: {} as DataSourcePluginMeta,
}
Example #11
Source File: ExpressionDatasource.ts From grafana-chinese with Apache License 2.0 | 6 votes |
expressionDatasource.meta = {
id: ExpressionDatasourceID,
info: {
logos: {
small: 'public/img/icn-datasource.svg',
large: 'public/img/icn-datasource.svg',
},
},
} as DataSourcePluginMeta;
Example #12
Source File: datasource_srv.ts From grafana-chinese with Apache License 2.0 | 5 votes |
constructor(name?: string, result?: DataQueryResponse, meta?: any) {
super({ name: name ? name : 'MockDataSourceApi' } as DataSourceInstanceSettings);
if (result) {
this.result = result;
}
this.meta = meta || ({} as DataSourcePluginMeta);
}
Example #13
Source File: variableQueryEditorLoader.tsx From grafana-chinese with Apache License 2.0 | 5 votes |
async function loadComponent(meta: DataSourcePluginMeta) {
const dsPlugin = await importDataSourcePlugin(meta);
if (dsPlugin.components.VariableQueryEditor) {
return dsPlugin.components.VariableQueryEditor;
} else {
return DefaultVariableQueryEditor;
}
}
Example #14
Source File: selectors.ts From grafana-chinese with Apache License 2.0 | 5 votes |
getDataSourceMeta = (state: DataSourcesState, type: string): DataSourcePluginMeta => {
if (state.dataSourceMeta.id === type) {
return state.dataSourceMeta;
}
return {} as DataSourcePluginMeta;
}
Example #15
Source File: selectors.ts From grafana-chinese with Apache License 2.0 | 5 votes |
getDataSourcePlugins = (state: DataSourcesState) => {
const regex = new RegExp(state.dataSourceTypeSearchQuery, 'i');
return state.plugins.filter((type: DataSourcePluginMeta) => {
return regex.test(type.name);
});
}
Example #16
Source File: reducers.ts From grafana-chinese with Apache License 2.0 | 5 votes |
dataSourceMetaLoaded = createAction<DataSourcePluginMeta>('dataSources/dataSourceMetaLoaded')
Example #17
Source File: buildCategories.ts From grafana-chinese with Apache License 2.0 | 5 votes |
function getEnterprisePhantomPlugins(): DataSourcePluginMeta[] {
return [
getPhantomPlugin({
id: 'grafana-splunk-datasource',
name: 'Splunk',
description: 'Visualize & explore Splunk logs',
imgUrl: 'public/img/plugins/splunk_logo_128.png',
}),
getPhantomPlugin({
id: 'grafana-oracle-datasource',
name: 'Oracle',
description: 'Visualize & explore Oracle SQL',
imgUrl: 'public/img/plugins/oracle.png',
}),
getPhantomPlugin({
id: 'grafana-dynatrace-datasource',
name: 'Dynatrace',
description: 'Visualize & explore Dynatrace data',
imgUrl: 'public/img/plugins/dynatrace.png',
}),
getPhantomPlugin({
id: 'grafana-servicenow-datasource',
description: 'ServiceNow integration & data source',
name: 'ServiceNow',
imgUrl: 'public/img/plugins/servicenow.svg',
}),
getPhantomPlugin({
id: 'grafana-datadog-datasource',
description: 'DataDog integration & data source',
name: 'DataDog',
imgUrl: 'public/img/plugins/datadog.png',
}),
getPhantomPlugin({
id: 'grafana-newrelic-datasource',
description: 'New Relic integration & data source',
name: 'New Relic',
imgUrl: 'public/img/plugins/newrelic.svg',
}),
];
}
Example #18
Source File: buildCategories.ts From grafana-chinese with Apache License 2.0 | 5 votes |
export function buildCategories(plugins: DataSourcePluginMeta[]): DataSourcePluginCategory[] {
const categories: DataSourcePluginCategory[] = [
{ id: 'tsdb', title: '时序数据库', plugins: [] },
{ id: 'logging', title: '日志 & 文档数据库', plugins: [] },
{ id: 'sql', title: 'SQL', plugins: [] },
{ id: 'cloud', title: '云插件', plugins: [] },
{ id: 'enterprise', title: '企业插件', plugins: [] },
{ id: 'other', title: '其他', plugins: [] },
];
const categoryIndex: Record<string, DataSourcePluginCategory> = {};
const pluginIndex: Record<string, DataSourcePluginMeta> = {};
const enterprisePlugins = getEnterprisePhantomPlugins();
// build indices
for (const category of categories) {
categoryIndex[category.id] = category;
}
for (const plugin of plugins) {
// Force category for enterprise plugins
if (enterprisePlugins.find(item => item.id === plugin.id)) {
plugin.category = 'enterprise';
}
// Fix link name
if (plugin.info.links) {
for (const link of plugin.info.links) {
link.name = 'Learn more';
}
}
const category = categories.find(item => item.id === plugin.category) || categoryIndex['other'];
category.plugins.push(plugin);
// add to plugin index
pluginIndex[plugin.id] = plugin;
}
for (const category of categories) {
// add phantom plugin
if (category.id === 'cloud') {
category.plugins.push(getGrafanaCloudPhantomPlugin());
}
// add phantom plugins
if (category.id === 'enterprise') {
for (const plugin of enterprisePlugins) {
if (!pluginIndex[plugin.id]) {
category.plugins.push(plugin);
}
}
}
sortPlugins(category.plugins);
}
return categories;
}
Example #19
Source File: PluginSettings.tsx From grafana-chinese with Apache License 2.0 | 5 votes |
scopeProps: {
ctrl: { datasourceMeta: DataSourcePluginMeta; current: DataSourceSettings };
onModelChanged: (dataSource: DataSourceSettings) => void;
};
Example #20
Source File: NewDataSourcePage.tsx From grafana-chinese with Apache License 2.0 | 5 votes |
onDataSourceTypeClicked = (plugin: DataSourcePluginMeta) => {
this.props.addDataSource(plugin);
};
Example #21
Source File: datasource_srv.test.ts From grafana-chinese with Apache License 2.0 | 4 votes |
describe('datasource_srv', () => {
const _datasourceSrv = new DatasourceSrv({} as any, {} as any, templateSrv);
describe('when loading external datasources', () => {
beforeEach(() => {
config.datasources = {
buildInDs: {
id: 1,
type: 'b',
name: 'buildIn',
meta: { builtIn: true } as DataSourcePluginMeta,
jsonData: {},
},
nonBuildIn: {
id: 2,
type: 'e',
name: 'external1',
meta: { builtIn: false } as DataSourcePluginMeta,
jsonData: {},
},
nonExplore: {
id: 3,
type: 'e2',
name: 'external2',
meta: {} as PluginMeta,
jsonData: {},
},
};
});
it('should return list of explore sources', () => {
const externalSources = _datasourceSrv.getExternal();
expect(externalSources.length).toBe(2);
expect(externalSources[0].name).toBe('external1');
expect(externalSources[1].name).toBe('external2');
});
});
describe('when loading metric sources', () => {
let metricSources: any;
const unsortedDatasources = {
mmm: {
type: 'test-db',
meta: { metrics: { m: 1 } },
},
'--Grafana--': {
type: 'grafana',
meta: { builtIn: true, metrics: { m: 1 }, id: 'grafana' },
},
'--Mixed--': {
type: 'test-db',
meta: { builtIn: true, metrics: { m: 1 }, id: 'mixed' },
},
ZZZ: {
type: 'test-db',
meta: { metrics: { m: 1 } },
},
aaa: {
type: 'test-db',
meta: { metrics: { m: 1 } },
},
BBB: {
type: 'test-db',
meta: { metrics: { m: 1 } },
},
};
beforeEach(() => {
config.datasources = unsortedDatasources as any;
metricSources = _datasourceSrv.getMetricSources({});
config.defaultDatasource = 'BBB';
});
it('should return a list of sources sorted case insensitively with builtin sources last', () => {
expect(metricSources[1].name).toBe('aaa');
expect(metricSources[2].name).toBe('BBB');
expect(metricSources[3].name).toBe('mmm');
expect(metricSources[4].name).toBe('ZZZ');
expect(metricSources[5].name).toBe('--Grafana--');
expect(metricSources[6].name).toBe('--Mixed--');
});
it('should set default data source', () => {
expect(metricSources[3].name).toBe('default');
expect(metricSources[3].sort).toBe('BBB');
});
it('should set default inject the variable datasources', () => {
expect(metricSources[0].name).toBe('$datasource');
expect(metricSources[0].sort).toBe('$datasource');
});
});
});