-
Notifications
You must be signed in to change notification settings - Fork 472
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
yurishkuro
merged 7 commits into
jaegertracing:main
from
MUI-Pop:inject-trace-details-to-linkpatterns
Feb 8, 2023
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0318def
Make traceID, startTime, endTime, duration and traceName available fo…
MUI-Pop adf1e94
Fix review comments
MUI-Pop 4b74c6d
Fix lint errors
MUI-Pop c4e42e1
Add tests for VirtualizedTraceView
MUI-Pop d3980bc
Fix review comments
MUI-Pop 4d507da
Address review comments
MUI-Pop 4991ce3
Merge branch 'main' into inject-trace-details-to-linkpatterns
yurishkuro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import { DEFAULT_HEIGHTS, VirtualizedTraceViewImpl } from './VirtualizedTraceVie | |
import traceGenerator from '../../../demo/trace-generators'; | ||
import transformTraceData from '../../../model/transform-trace-data'; | ||
import updateUiFindSpy from '../../../utils/update-ui-find'; | ||
import * as getLinks from '../../../model/link-patterns'; | ||
|
||
jest.mock('./SpanTreeOffset'); | ||
jest.mock('../../../utils/update-ui-find'); | ||
|
@@ -430,4 +431,40 @@ describe('<VirtualizedTraceViewImpl>', () => { | |
expect(focusUiFindMatchesMock).toHaveBeenLastCalledWith(trace, spanName, false); | ||
}); | ||
}); | ||
|
||
describe('linksGetter()', () => { | ||
const span = trace.spans[1]; | ||
const key = span.tags[0].key; | ||
const val = encodeURIComponent(span.tags[0].value); | ||
const origLinkPatterns = [...getLinks.processedLinks]; | ||
|
||
beforeEach(() => { | ||
getLinks.processedLinks.splice(0, getLinks.processedLinks.length); | ||
}); | ||
|
||
afterAll(() => { | ||
getLinks.processedLinks.splice(0, getLinks.processedLinks.length); | ||
getLinks.processedLinks.push(...origLinkPatterns); | ||
}); | ||
|
||
it('calls getLinks with expected params', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. stale title |
||
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}`, | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -110,6 +110,27 @@ export function getParameterInAncestor(name: string, span: Span) { | |||||||||||
} | ||||||||||||
currentSpan = getParent(currentSpan); | ||||||||||||
} | ||||||||||||
|
||||||||||||
return undefined; | ||||||||||||
} | ||||||||||||
|
||||||||||||
const getValidTraceKeys = memoize(10)((trace: Trace) => { | ||||||||||||
const validKeys = (Object.keys(trace) as (keyof Trace)[]).filter( | ||||||||||||
key => typeof trace[key] === 'string' || typeof trace[key] === 'number' | ||||||||||||
); | ||||||||||||
return validKeys; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
export function getParameterInTrace(name: string, trace: Trace | undefined) { | ||||||||||||
yurishkuro marked this conversation as resolved.
Show resolved
Hide resolved
yurishkuro marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
if (trace) { | ||||||||||||
const validTraceKeys = getValidTraceKeys(trace); | ||||||||||||
|
||||||||||||
const key = name as keyof Trace; | ||||||||||||
if (validTraceKeys.includes(key)) { | ||||||||||||
return { key, value: trace[key] }; | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
return undefined; | ||||||||||||
} | ||||||||||||
|
||||||||||||
|
@@ -119,20 +140,17 @@ function callTemplate(template: ProcessedTemplate, data: any) { | |||||||||||
|
||||||||||||
export function computeTraceLink(linkPatterns: ProcessedLinkPattern[], trace: Trace) { | ||||||||||||
const result: TLinksRV = []; | ||||||||||||
const validKeys = (Object.keys(trace) as (keyof Trace)[]).filter( | ||||||||||||
key => typeof trace[key] === 'string' || typeof trace[key] === 'number' | ||||||||||||
); | ||||||||||||
|
||||||||||||
linkPatterns | ||||||||||||
.filter(pattern => pattern.type('traces')) | ||||||||||||
.forEach(pattern => { | ||||||||||||
const parameterValues: Record<string, any> = {}; | ||||||||||||
const allParameters = pattern.parameters.every(parameter => { | ||||||||||||
const key = parameter as keyof Trace; | ||||||||||||
if (validKeys.includes(key)) { | ||||||||||||
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] = trace[key]; | ||||||||||||
parameterValues[parameter] = traceKV.value; | ||||||||||||
return true; | ||||||||||||
} | ||||||||||||
return false; | ||||||||||||
|
@@ -152,7 +170,8 @@ export function computeLinks( | |||||||||||
linkPatterns: ProcessedLinkPattern[], | ||||||||||||
span: Span, | ||||||||||||
items: KeyValuePair[], | ||||||||||||
itemIndex: number | ||||||||||||
itemIndex: number, | ||||||||||||
trace: Trace | undefined | ||||||||||||
) { | ||||||||||||
const item = items[itemIndex]; | ||||||||||||
let type = 'logs'; | ||||||||||||
|
@@ -169,16 +188,28 @@ export function computeLinks( | |||||||||||
if (pattern.type(type) && pattern.key(item.key) && pattern.value(item.value)) { | ||||||||||||
const parameterValues: Record<string, any> = {}; | ||||||||||||
const allParameters = pattern.parameters.every(parameter => { | ||||||||||||
let entry = getParameterInArray(parameter, items); | ||||||||||||
if (!entry && !processTags) { | ||||||||||||
// do not look in ancestors for process tags because the same object may appear in different places in the hierarchy | ||||||||||||
// and the cache in getLinks uses that object as a key | ||||||||||||
entry = getParameterInAncestor(parameter, span); | ||||||||||||
let entry; | ||||||||||||
|
||||||||||||
if (parameter.startsWith('trace.')) { | ||||||||||||
const traceKV = getParameterInTrace(parameter.split('trace.')[1], trace); | ||||||||||||
if (traceKV) { | ||||||||||||
entry = traceKV; | ||||||||||||
} | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
} else { | ||||||||||||
entry = getParameterInArray(parameter, items); | ||||||||||||
|
||||||||||||
if (!entry && !processTags) { | ||||||||||||
// do not look in ancestors for process tags because the same object may appear in different places in the hierarchy | ||||||||||||
// and the cache in getLinks uses that object as a key | ||||||||||||
entry = getParameterInAncestor(parameter, span); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
if (entry) { | ||||||||||||
parameterValues[parameter] = entry.value; | ||||||||||||
return true; | ||||||||||||
} | ||||||||||||
|
||||||||||||
// eslint-disable-next-line no-console | ||||||||||||
console.warn( | ||||||||||||
`Skipping link pattern, missing parameter ${parameter} for key ${item.key} in ${type}.`, | ||||||||||||
|
@@ -198,21 +229,21 @@ export function computeLinks( | |||||||||||
} | ||||||||||||
|
||||||||||||
export function createGetLinks(linkPatterns: ProcessedLinkPattern[], cache: WeakMap<KeyValuePair, Link[]>) { | ||||||||||||
return (span: Span, items: KeyValuePair[], itemIndex: number) => { | ||||||||||||
return (span: Span, items: KeyValuePair[], itemIndex: number, trace: Trace | undefined) => { | ||||||||||||
if (linkPatterns.length === 0) { | ||||||||||||
return []; | ||||||||||||
} | ||||||||||||
const item = items[itemIndex]; | ||||||||||||
let result = cache.get(item); | ||||||||||||
if (!result) { | ||||||||||||
result = computeLinks(linkPatterns, span, items, itemIndex); | ||||||||||||
result = computeLinks(linkPatterns, span, items, itemIndex, trace); | ||||||||||||
cache.set(item, result); | ||||||||||||
} | ||||||||||||
return result; | ||||||||||||
}; | ||||||||||||
} | ||||||||||||
|
||||||||||||
const processedLinks: ProcessedLinkPattern[] = (getConfigValue('linkPatterns') || []) | ||||||||||||
export const processedLinks: ProcessedLinkPattern[] = (getConfigValue('linkPatterns') || []) | ||||||||||||
.map(processLinkPattern) | ||||||||||||
.filter(Boolean); | ||||||||||||
|
||||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit