-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[APM] Fix gap in timeline and fallback when traceroot is missing #25346
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
Changes from all commits
e54dab8
d39042a
8b21924
4f88257
6c9dda0
5aa08cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ export interface IWaterfallGroup { | |
|
|
||
| export interface IWaterfall { | ||
| traceRoot?: Transaction; | ||
| traceRootDuration: number; | ||
| traceRootDuration?: number; | ||
|
|
||
| /** | ||
| * Duration in us | ||
|
|
@@ -145,18 +145,19 @@ function getSpanItem(span: Span): IWaterfallItemSpan { | |
|
|
||
| export function getClockSkew( | ||
| item: IWaterfallItem, | ||
| parentItem: IWaterfallItem | undefined, | ||
| parentTransactionSkew: number | ||
| parentItem?: IWaterfallItem | ||
|
||
| ) { | ||
| if (!parentItem) { | ||
| return 0; | ||
| } | ||
|
|
||
| switch (item.docType) { | ||
| // don't calculate skew for spans. Just use parent's skew | ||
| case 'span': | ||
| return parentTransactionSkew; | ||
| case 'transaction': { | ||
| // For some reason the parent span and related transactions might be missing. | ||
| if (!parentItem) { | ||
| return 0; | ||
| } | ||
| return parentItem.skew; | ||
|
|
||
| // transaction is the inital entry in a service. Calculate skew for this, and it will be propogated to all child spans | ||
| case 'transaction': { | ||
| const parentStart = parentItem.timestamp + parentItem.skew; | ||
| const parentEnd = parentStart + parentItem.duration; | ||
|
|
||
|
|
@@ -182,28 +183,25 @@ export function getClockSkew( | |
|
|
||
| export function getWaterfallItems( | ||
| childrenByParentId: IWaterfallGroup, | ||
| itemsById: IWaterfallIndex, | ||
| entryTransactionItem: IWaterfallItem | ||
| ) { | ||
| function getSortedChildren( | ||
| item: IWaterfallItem, | ||
| parentTransactionSkew: number | ||
| parentItem?: IWaterfallItem | ||
| ): IWaterfallItem[] { | ||
| const parentItem = item.parentId ? itemsById[item.parentId] : undefined; | ||
| const skew = getClockSkew(item, parentItem, parentTransactionSkew); | ||
| const children = sortBy(childrenByParentId[item.id] || [], 'timestamp'); | ||
|
|
||
| item.childIds = children.map(child => child.id); | ||
| item.offset = item.timestamp - entryTransactionItem.timestamp; | ||
| item.skew = skew; | ||
| item.skew = getClockSkew(item, parentItem); | ||
|
|
||
| const deepChildren = flatten( | ||
| children.map(child => getSortedChildren(child, skew)) | ||
| children.map(child => getSortedChildren(child, item)) | ||
| ); | ||
| return [item, ...deepChildren]; | ||
| } | ||
|
|
||
| return getSortedChildren(entryTransactionItem, 0); | ||
| return getSortedChildren(entryTransactionItem); | ||
| } | ||
|
|
||
| function getTraceRoot(childrenByParentId: IWaterfallGroup) { | ||
|
|
@@ -265,7 +263,6 @@ export function getWaterfall( | |
| return { | ||
| services: [], | ||
| duration: 0, | ||
| traceRootDuration: 0, | ||
| items: [], | ||
| itemsById: {}, | ||
| getTransactionById: () => undefined, | ||
|
|
@@ -296,16 +293,10 @@ export function getWaterfall( | |
| ); | ||
| const entryTransactionItem = getTransactionItem(entryTransaction); | ||
| const itemsById: IWaterfallIndex = indexBy(filteredHits, 'id'); | ||
| const items = getWaterfallItems( | ||
| childrenByParentId, | ||
| itemsById, | ||
| entryTransactionItem | ||
| ); | ||
| const items = getWaterfallItems(childrenByParentId, entryTransactionItem); | ||
| const traceRoot = getTraceRoot(childrenByParentId); | ||
| const duration = getDuration(items); | ||
| const traceRootDuration = traceRoot | ||
| ? traceRoot.transaction.duration.us | ||
| : duration; | ||
| const traceRootDuration = traceRoot && traceRoot.transaction.duration.us; | ||
| const services = getServices(items); | ||
| const getTransactionById = createGetTransactionById(itemsById); | ||
| const serviceColors = getServiceColors(services); | ||
|
|
||
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.
Code review is a place where destructuring is nice IMO, e.g.
mostly for the fallback value to have some context ... but let's not change that right now at the release deadline :)
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.
I can see how it makes it more readable here.