mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
b3838d372e
* Remove feature flag * Add data source setting for Jaeger * Refactor trace to logs settings * Fix tests * Get ds settings in two steps * Add info to settings * Update docs for trace to logs * Update yarn.lock * Apply suggestions from code review Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update TraceToLogsSettings after merge with master * Add config for tags * Add tags to check for keys * Apply suggestions from code review Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
134 lines
3.9 KiB
TypeScript
134 lines
3.9 KiB
TypeScript
import { DataSourceInstanceSettings, ScopedVars } from '@grafana/data';
|
|
import { setDataSourceSrv, setTemplateSrv } from '@grafana/runtime';
|
|
import { createSpanLinkFactory } from './createSpanLink';
|
|
|
|
describe('createSpanLinkFactory', () => {
|
|
it('returns undefined if there is no data source uid', () => {
|
|
const splitOpenFn = jest.fn();
|
|
const createLink = createSpanLinkFactory(splitOpenFn);
|
|
expect(createLink).not.toBeDefined();
|
|
});
|
|
|
|
describe('should return link', () => {
|
|
beforeAll(() => {
|
|
setDataSourceSrv({
|
|
getInstanceSettings(uid: string): DataSourceInstanceSettings | undefined {
|
|
return {
|
|
uid: 'loki1',
|
|
name: 'loki1',
|
|
} as any;
|
|
},
|
|
} as any);
|
|
|
|
setTemplateSrv({
|
|
replace(target?: string, scopedVars?: ScopedVars, format?: string | Function): string {
|
|
return target!;
|
|
},
|
|
} as any);
|
|
});
|
|
|
|
it('with default keys when tags not configured', () => {
|
|
const splitOpenFn = jest.fn();
|
|
const createLink = createSpanLinkFactory(splitOpenFn, { datasourceUid: 'lokiUid' });
|
|
expect(createLink).toBeDefined();
|
|
const linkDef = createLink!({
|
|
startTime: new Date('2020-10-14T01:00:00Z').valueOf() * 1000,
|
|
duration: 1000 * 1000,
|
|
tags: [
|
|
{
|
|
key: 'host',
|
|
value: 'host',
|
|
},
|
|
],
|
|
process: {
|
|
tags: [
|
|
{
|
|
key: 'cluster',
|
|
value: 'cluster1',
|
|
},
|
|
{
|
|
key: 'hostname',
|
|
value: 'hostname1',
|
|
},
|
|
{
|
|
key: 'label2',
|
|
value: 'val2',
|
|
},
|
|
],
|
|
} as any,
|
|
} as any);
|
|
|
|
expect(linkDef.href).toBe(
|
|
`/explore?left={"range":{"from":"20201014T000000","to":"20201014T010006"},"datasource":"loki1","queries":[{"expr":"{cluster=\\"cluster1\\", hostname=\\"hostname1\\"}","refId":""}]}`
|
|
);
|
|
});
|
|
|
|
it('with tags that passed in and without tags that are not in the span', () => {
|
|
const splitOpenFn = jest.fn();
|
|
const createLink = createSpanLinkFactory(splitOpenFn, { datasourceUid: 'lokiUid', tags: ['ip', 'newTag'] });
|
|
expect(createLink).toBeDefined();
|
|
const linkDef = createLink!({
|
|
startTime: new Date('2020-10-14T01:00:00Z').valueOf() * 1000,
|
|
duration: 1000 * 1000,
|
|
tags: [
|
|
{
|
|
key: 'host',
|
|
value: 'host',
|
|
},
|
|
],
|
|
process: {
|
|
tags: [
|
|
{
|
|
key: 'hostname',
|
|
value: 'hostname1',
|
|
},
|
|
{
|
|
key: 'ip',
|
|
value: '192.168.0.1',
|
|
},
|
|
],
|
|
} as any,
|
|
} as any);
|
|
|
|
expect(linkDef.href).toBe(
|
|
`/explore?left={"range":{"from":"20201014T000000","to":"20201014T010006"},"datasource":"loki1","queries":[{"expr":"{ip=\\"192.168.0.1\\"}","refId":""}]}`
|
|
);
|
|
});
|
|
|
|
it('from tags and process tags as well', () => {
|
|
const splitOpenFn = jest.fn();
|
|
const createLink = createSpanLinkFactory(splitOpenFn, {
|
|
datasourceUid: 'lokiUid',
|
|
tags: ['ip', 'host'],
|
|
});
|
|
expect(createLink).toBeDefined();
|
|
const linkDef = createLink!({
|
|
startTime: new Date('2020-10-14T01:00:00Z').valueOf() * 1000,
|
|
duration: 1000 * 1000,
|
|
tags: [
|
|
{
|
|
key: 'host',
|
|
value: 'host',
|
|
},
|
|
],
|
|
process: {
|
|
tags: [
|
|
{
|
|
key: 'hostname',
|
|
value: 'hostname1',
|
|
},
|
|
{
|
|
key: 'ip',
|
|
value: '192.168.0.1',
|
|
},
|
|
],
|
|
} as any,
|
|
} as any);
|
|
|
|
expect(linkDef.href).toBe(
|
|
`/explore?left={"range":{"from":"20201014T000000","to":"20201014T010006"},"datasource":"loki1","queries":[{"expr":"{ip=\\"192.168.0.1\\", host=\\"host\\"}","refId":""}]}`
|
|
);
|
|
});
|
|
});
|
|
});
|