Commit 66b3e08a by Andrej Ocenas Committed by GitHub

Links: Filter data sources in derived link to tracing only (#23948)

parent a8ba503b
......@@ -189,14 +189,15 @@ datasources:
jsonData:
maxLines: 1000
derivedFields:
# Field with internal link pointing to datasource in Grafana
# Field with internal link pointing to data source in Grafana.
# Right now, Grafana supports only Jaeger and Zipkin data sources as link targets.
- datasourceUid: my_jaeger_uid
matcherRegex: "traceID=(\\w+)"
name: TraceID
# url will be interpreted as query for the datasource
url: "$${__value.raw}"
# Field with external link
# Field with external link.
- matcherRegex: "traceID=(\\w+)"
name: TraceID
url: "http://localhost:16686/trace/$${__value.raw}"
......
......@@ -2,12 +2,31 @@ import React from 'react';
import { shallow } from 'enzyme';
import { DerivedField } from './DerivedField';
import DataSourcePicker from '../../../../core/components/Select/DataSourcePicker';
import { DataSourceInstanceSettings } from '@grafana/data';
jest.mock('app/features/plugins/datasource_srv', () => ({
getDatasourceSrv() {
return {
getExternal(): any[] {
return [];
getExternal(): DataSourceInstanceSettings[] {
return [
{
id: 1,
uid: 'metrics',
name: 'metrics_ds',
meta: {
tracing: false,
} as any,
} as any,
{
id: 2,
uid: 'tracing',
name: 'tracing_ds',
meta: {
tracing: true,
} as any,
} as any,
];
},
};
},
......@@ -39,4 +58,21 @@ describe('DerivedField', () => {
const wrapper = shallow(<DerivedField value={value} onChange={() => {}} onDelete={() => {}} suggestions={[]} />);
expect(wrapper.find('DataSourceSection').length).toBe(0);
});
it('shows only tracing datasources for internal link', () => {
const value = {
matcherRegex: '',
name: '',
datasourceUid: 'test',
};
const wrapper = shallow(<DerivedField value={value} onChange={() => {}} onDelete={() => {}} suggestions={[]} />);
const dsSection = wrapper.find('DataSourceSection').dive();
expect(dsSection.find(DataSourcePicker).props().datasources).toEqual([
{
meta: { tracing: true },
name: 'tracing_ds',
value: 'tracing',
},
]);
});
});
......@@ -152,6 +152,8 @@ const DataSourceSection = (props: DataSourceSectionProps) => {
const { datasourceUid, onChange } = props;
const datasources: DataSourceSelectItem[] = getDatasourceSrv()
.getExternal()
// At this moment only Jaeger and Zipkin datasource is supported as the link target.
.filter(ds => ds.meta.tracing)
.map(
ds =>
({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment