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

Implemented Compressed Spans #97438

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@

import React, { ReactNode } from 'react';

import { EuiIcon, EuiText, EuiTitle, EuiToolTip } from '@elastic/eui';
import { EuiIcon, EuiText, EuiTitle, EuiToolTip, EuiBadge } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { euiStyled } from '../../../../../../../../../../src/plugins/kibana_react/common';
import { asDuration } from '../../../../../../../common/utils/formatters';
import { isRumAgentName } from '../../../../../../../common/agent_name';
import { px, unit, units } from '../../../../../../style/variables';
import { ErrorCount } from '../../ErrorCount';
import { IWaterfallSpanOrTransaction } from './waterfall_helpers/waterfall_helpers';
import { IWaterfallItem, IWaterfallSpanOrTransaction } from './waterfall_helpers/waterfall_helpers';
import { ErrorOverviewLink } from '../../../../../shared/Links/apm/ErrorOverviewLink';
import { TRACE_ID } from '../../../../../../../common/elasticsearch_fieldnames';
import { SyncBadge } from './SyncBadge';
import { Margins } from '../../../../../shared/charts/Timeline';
import { useTheme } from '../../../../../../hooks/use_theme';

type ItemType = 'transaction' | 'span' | 'error';

Expand Down Expand Up @@ -159,6 +160,26 @@ function NameLabel({ item }: { item: IWaterfallSpanOrTransaction }) {
}
}

function compressedSpanStyle(item: IWaterfallSpanOrTransaction, width: number, left: number): React.CSSProperties {
var itemBarStyle = { left: `${left}%`, width: `${width}%` };
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved

if (item.count !== undefined && item.durationSum !== undefined) {
const percNumItems = 100.0 / item.count;
const percDuration = percNumItems * (item.durationSum / item.duration);

itemBarStyle = {
...itemBarStyle,
...{
backgroundImage: `repeating-linear-gradient(90deg, transparent, transparent max(${percDuration}%,1.5px),` +
` rgba(255,255,255,1) max(${percDuration}%,1.5px),` +
` rgba(255,255,255,1) max(${percNumItems}%,3px))`
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
}
};
}

return itemBarStyle
}

export function WaterfallItem({
timelineMargins,
totalDuration,
Expand All @@ -168,6 +189,7 @@ export function WaterfallItem({
errorCount,
onClick,
}: IWaterfallItemProps) {
const theme = useTheme();
if (!totalDuration) {
return null;
}
Expand All @@ -184,6 +206,8 @@ export function WaterfallItem({
}
);

var itemBarStyle = compressedSpanStyle(item, width, left);

return (
<Container
type={item.docType}
Expand All @@ -194,17 +218,26 @@ export function WaterfallItem({
onClick();
}}
>
<ItemBar // using inline styles instead of props to avoid generating a css class for each item
style={{ left: `${left}%`, width: `${width}%` }}
color={color}
type={item.docType}
/>
<div>
<ItemBar // using inline styles instead of props to avoid generating a css class for each item
style={itemBarStyle}
color={color}
type={item.docType}
/>
</div>
<ItemText // using inline styles instead of props to avoid generating a css class for each item
style={{ minWidth: `${Math.max(100 - left, 0)}%` }}
>
<SpanActionToolTip item={item}>
<PrefixIcon item={item} />
</SpanActionToolTip>
{item.nPlusOne &&
<EuiToolTip content={`${item.nPlusOne}`}>
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
<EuiBadge color={theme.eui.euiColorWarning}>
N+1 pattern!
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
</EuiBadge>
</EuiToolTip>
}
<HttpStatusCode item={item} />
<NameLabel item={item} />
{errorCount > 0 && item.docType === 'transaction' ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface IWaterfall {
errorsCount: number;
legends: IWaterfallLegend[];
errorItems: IWaterfallError[];
antipatternDetected?: boolean;
}

interface IWaterfallSpanItemBase<TDocument, TDoctype>
Expand All @@ -46,6 +47,9 @@ interface IWaterfallSpanItemBase<TDocument, TDoctype>
* Latency in us
*/
duration: number;
durationSum?: number;
count?: number;
nPlusOne?: boolean;
legendValues: Record<WaterfallLegendType, string>;
}

Expand All @@ -56,6 +60,7 @@ interface IWaterfallItemBase<TDocument, TDoctype> {
parent?: IWaterfallSpanOrTransaction;
parentId?: string;
color: string;

/**
* offset from first item in us
*/
Expand Down Expand Up @@ -274,7 +279,7 @@ const getWaterfallItems = (items: TraceAPIResponse['trace']['items']) =>
}
});

function reparentSpans(waterfallItems: IWaterfallSpanOrTransaction[]) {
export function reparentSpans(waterfallItems: IWaterfallSpanOrTransaction[]) {
// find children that needs to be re-parented and map them to their correct parent id
const childIdToParentIdMapping = Object.fromEntries(
flatten(
Expand Down Expand Up @@ -302,9 +307,7 @@ function reparentSpans(waterfallItems: IWaterfallSpanOrTransaction[]) {
});
}

const getChildrenGroupedByParentId = (
waterfallItems: IWaterfallSpanOrTransaction[]
) =>
export const getChildrenGroupedByParentId = (waterfallItems: IWaterfallSpanOrTransaction[]) =>
groupBy(waterfallItems, (item) => (item.parentId ? item.parentId : ROOT_ID));

const getEntryWaterfallTransaction = (
Expand Down
Loading