Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make traceID, startTime, endTime, duration and traceName available for Link Patterns #1178

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix review comments
Signed-off-by: Kanahathi Mohideen <kpmfazal@gmail.com>
  • Loading branch information
MUI-Pop committed Feb 7, 2023
commit d3980bcfbfd799b051e75113459f42322e9b37bc
Original file line number Diff line number Diff line change
Expand Up @@ -433,20 +433,38 @@ describe('<VirtualizedTraceViewImpl>', () => {
});

describe('linksGetter()', () => {
let getLinksSpy;
const span = trace.spans[1];
const key = span.tags[0].key;
const val = encodeURIComponent(span.tags[0].value);
const origLinkPatterns = [...getLinks.processedLinks];

beforeAll(() => {
getLinksSpy = jest.spyOn(getLinks, 'default');
beforeEach(() => {
getLinks.processedLinks.splice(0, getLinks.processedLinks.length);
});

afterAll(() => {
getLinksSpy.mockRestore();
getLinks.processedLinks.splice(0, getLinks.processedLinks.length);
getLinks.processedLinks.push(...origLinkPatterns);
});

it('calls getLinks with expected params', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stale title

const span = trace.spans[1];
instance.linksGetter(span, span.tags, 0);
expect(getLinksSpy).toHaveBeenCalledWith(span, span.tags, 0, trace);
const linkPatterns = [
{
key,
type: 'tags',
url: `http://example.com/?key1=#{${key}}&traceID=#{trace.traceID}&startTime=#{trace.startTime}`,
text: `For first link traceId is - #{trace.traceID}`,
},
].map(getLinks.processLinkPattern);

getLinks.processedLinks.push(...linkPatterns);

expect(instance.linksGetter(span, span.tags, 0)).toEqual([
{
url: `http://example.com/?key1=${val}&traceID=${trace.traceID}&startTime=${trace.startTime}`,
text: `For first link traceId is - ${trace.traceID}`,
},
]);
});
});
});
2 changes: 1 addition & 1 deletion packages/jaeger-ui/src/model/link-patterns.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ describe('getParameterInTrace()', () => {
};

it('returns an entry that is present', () => {
expect(getParameterInTrace('startTime', trace)).toEqual(trace.startTime);
expect(getParameterInTrace('startTime', trace)).toEqual({ key: 'startTime', value: trace.startTime });
});

it('returns undefined when the entry cannot be found', () => {
Expand Down
16 changes: 8 additions & 8 deletions packages/jaeger-ui/src/model/link-patterns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function getParameterInTrace(name: string, trace: Trace | undefined) {

const key = name as keyof Trace;
if (validTraceKeys.includes(key)) {
return trace[key];
return { key, value: trace[key] };
}
}

Expand All @@ -146,11 +146,11 @@ export function computeTraceLink(linkPatterns: ProcessedLinkPattern[], trace: Tr
.forEach(pattern => {
const parameterValues: Record<string, any> = {};
const allParameters = pattern.parameters.every(parameter => {
const val = getParameterInTrace(parameter, trace);
if (val) {
const traceKV = getParameterInTrace(parameter, trace);
if (traceKV) {
// At this point is safe to access to trace object using parameter variable because
// we validated parameter against validKeys, this implies that parameter a keyof Trace.
parameterValues[parameter] = val;
parameterValues[parameter] = traceKV.value;
return true;
}
return false;
Expand Down Expand Up @@ -191,9 +191,9 @@ export function computeLinks(
let entry;

if (parameter.startsWith('trace.')) {
const traceVal = getParameterInTrace(parameter.split('trace.')[1], trace);
if (traceVal) {
entry = { key: parameter, value: traceVal };
const traceKV = getParameterInTrace(parameter.split('trace.')[1], trace);
if (traceKV) {
entry = traceKV;
}
} else {
entry = getParameterInArray(parameter, items);
Expand Down Expand Up @@ -243,7 +243,7 @@ export function createGetLinks(linkPatterns: ProcessedLinkPattern[], cache: Weak
};
}

const processedLinks: ProcessedLinkPattern[] = (getConfigValue('linkPatterns') || [])
export const processedLinks: ProcessedLinkPattern[] = (getConfigValue('linkPatterns') || [])
.map(processLinkPattern)
.filter(Boolean);

Expand Down