Skip to content

Commit

Permalink
Visualizing composite spans. (elastic#106862)
Browse files Browse the repository at this point in the history
* Visualizing composite spans.

* fixed reviews comments

* replaced var usage with let

* Fixed display of compositeSpanDurationSummary

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
2 people authored and vadimkibana committed Aug 8, 2021
1 parent ff27960 commit 15d3f35
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import {
EuiBadge,
EuiButtonEmpty,
EuiCallOut,
EuiFlexGroup,
EuiFlexItem,
EuiFlyoutBody,
Expand All @@ -21,6 +22,7 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React, { Fragment } from 'react';
import { CompositeSpanDurationSummaryItem } from '../../../../../../shared/Summary/CompositeSpanDurationSummaryItem';
import { euiStyled } from '../../../../../../../../../../../src/plugins/kibana_react/common';
import { Span } from '../../../../../../../../typings/es_schemas/ui/span';
import { Transaction } from '../../../../../../../../typings/es_schemas/ui/transaction';
Expand Down Expand Up @@ -123,7 +125,6 @@ export function SpanFlyout({
</h2>
</EuiTitle>
</EuiFlexItem>

<EuiFlexItem grow={false}>
<DiscoverSpanLink span={span}>
<EuiButtonEmpty iconType="discoverApp">
Expand All @@ -137,18 +138,41 @@ export function SpanFlyout({
</DiscoverSpanLink>
</EuiFlexItem>
</EuiFlexGroup>
{span.span.composite && (
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiCallOut color="warning" iconType="gear" size="s">
{i18n.translate(
'xpack.apm.transactionDetails.spanFlyout.compositeExampleWarning',
{
defaultMessage:
'This is a sample document for a group of consecutive, similar spans',
}
)}
</EuiCallOut>
</EuiFlexItem>
</EuiFlexGroup>
)}
</EuiFlyoutHeader>
<EuiFlyoutBody>
<StickySpanProperties span={span} transaction={parentTransaction} />
<EuiSpacer size="m" />
<Summary
items={[
<TimestampTooltip time={span.timestamp.us / 1000} />,
<DurationSummaryItem
duration={span.span.duration.us}
totalDuration={totalDuration}
parentType="transaction"
/>,
<>
<DurationSummaryItem
duration={span.span.duration.us}
totalDuration={totalDuration}
parentType="transaction"
/>
{span.span.composite && (
<CompositeSpanDurationSummaryItem
count={span.span.composite.count}
durationSum={span.span.composite.sum.us}
/>
)}
</>,
<>
{spanHttpUrl && (
<HttpInfoContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,15 @@ function HttpStatusCode({ item }: { item: IWaterfallSpanOrTransaction }) {
function NameLabel({ item }: { item: IWaterfallSpanOrTransaction }) {
switch (item.docType) {
case 'span':
return <EuiText size="s">{item.doc.span.name}</EuiText>;
let name = item.doc.span.name;
if (item.doc.span.composite) {
const compositePrefix =
item.doc.span.composite.compression_strategy === 'exact_match'
? 'x'
: '';
name = `${item.doc.span.composite.count}${compositePrefix} ${name}`;
}
return <EuiText size="s">{name}</EuiText>;
case 'transaction':
return (
<EuiTitle size="xxs">
Expand Down Expand Up @@ -182,6 +190,9 @@ export function WaterfallItem({
}
);

const isCompositeSpan = item.docType === 'span' && item.doc.span.composite;
const itemBarStyle = getItemBarStyle(item, color, width, left);

return (
<Container
type={item.docType}
Expand All @@ -193,8 +204,8 @@ export function WaterfallItem({
}}
>
<ItemBar // using inline styles instead of props to avoid generating a css class for each item
style={{ left: `${left}%`, width: `${width}%` }}
color={color}
style={itemBarStyle}
color={isCompositeSpan ? 'transparent' : color}
type={item.docType}
/>
<ItemText // using inline styles instead of props to avoid generating a css class for each item
Expand Down Expand Up @@ -227,3 +238,32 @@ export function WaterfallItem({
</Container>
);
}

function getItemBarStyle(
item: IWaterfallSpanOrTransaction,
color: string,
width: number,
left: number
): React.CSSProperties {
let itemBarStyle = { left: `${left}%`, width: `${width}%` };

if (item.docType === 'span' && item.doc.span.composite) {
const percNumItems = 100.0 / item.doc.span.composite.count;
const spanSumRatio =
item.doc.span.composite.sum.us / item.doc.span.duration.us;
const percDuration = percNumItems * spanSumRatio;

itemBarStyle = {
...itemBarStyle,
...{
backgroundImage:
`repeating-linear-gradient(90deg, ${color},` +
` ${color} max(${percDuration}%,3px),` +
` transparent max(${percDuration}%,3px),` +
` transparent max(${percNumItems}%,max(${percDuration}%,3px) + 3px))`,
},
};
}

return itemBarStyle;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiToolTip, EuiText } from '@elastic/eui';
import { asDuration } from '../../../../common/utils/formatters';

interface Props {
count: number;
durationSum: number;
}

function CompositeSpanDurationSummaryItem({ count, durationSum }: Props) {
const avgDuration = durationSum / count;

return (
<EuiToolTip
content={i18n.translate('xpack.apm.compositeSpanDurationLabel', {
defaultMessage: 'Average duration',
})}
>
<EuiText>
{i18n.translate('xpack.apm.compositeSpanCallsLabel', {
defaultMessage: `, {count} calls, on avg. {duration}`,
values: {
count,
duration: asDuration(avgDuration),
},
})}
</EuiText>
</EuiToolTip>
);
}

export { CompositeSpanDurationSummaryItem };
5 changes: 5 additions & 0 deletions x-pack/plugins/apm/typings/es_schemas/raw/span_raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export interface SpanRaw extends APMBaseDoc {
body?: string;
headers?: Record<string, unknown>;
};
composite?: {
count: number;
sum: { us: number };
compression_strategy: string;
};
};
timestamp: TimestampUs;
transaction?: {
Expand Down

0 comments on commit 15d3f35

Please sign in to comment.