Skip to content

Commit

Permalink
Refactor model/trace-dag to prep for latency diffs
Browse files Browse the repository at this point in the history
- Refactor TraceDag class to make it simpler and more flexible

- Change DagNode to be a simple type instead of a class

- Change the data on DagNode to extend DagNode instead of live off
  the "data" field

- Base the data model for trace diffs on collections of DenseSpans
  instead of just the count of spans in a vs b for a given node in the
  comparison DAG

- Lay some small (id-factories.tsx) ground-work for being more flexible
  in how the DAG is built from the trace, which is to say how spans are
  grouped

Signed-off-by: Joe Farro <joe@jf.io>
  • Loading branch information
tiffon committed Feb 18, 2020
1 parent b27a9a5 commit be6c215
Show file tree
Hide file tree
Showing 15 changed files with 212 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ describe('drawNode', () => {
});

describe('renderNode()', () => {
const dataKey = 'data-key';
const dataValue = 'data-value';
const lenA = 3;
const lenB = 7;
const key = 'vertex key';
const vertex = {
data: {
data: {
[dataKey]: dataValue,
a: {
members: new Array(lenA),
},
b: {
members: new Array(lenB),
},
operation,
service,
Expand All @@ -83,7 +86,8 @@ describe('drawNode', () => {

it('extracts values from vertex.data', () => {
const node = renderNode(vertex);
expect(node.props[dataKey]).toBe(dataValue);
expect(node.props.a).toBe(lenA);
expect(node.props.b).toBe(lenB);
expect(node.props.operation).toBe(operation);
expect(node.props.service).toBe(service);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (c) 2020 The Jaeger Authors.
// Copyright (c) 2018 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -20,7 +21,7 @@ import { TLayoutVertex } from '@jaegertracing/plexus/lib/types';
import EmphasizedNode from '../../common/EmphasizedNode';
import CopyIcon from '../../common/CopyIcon';
import { DiffCounts } from '../../../model/trace-dag/types';
import TDagVertex from '../../../model/trace-dag/types/TDagVertex';
import DagPlexusVertex from '../../../model/trace-dag/types/DagPlexusVertex';

import './renderNode.css';

Expand Down Expand Up @@ -86,9 +87,11 @@ export class DiffNode extends React.PureComponent<Props> {
}
}

export default function renderNode(vertex: TDagVertex<DiffCounts>) {
const { data, operation, service } = vertex.data;
return <DiffNode {...data} operation={operation} service={service} />;
export default function renderNode(vertex: DagPlexusVertex<DiffCounts>) {
const { a, b, operation, service } = vertex.data;
const lenA = a ? a.members.length : 0;
const lenB = b ? b.members.length : 0;
return <DiffNode a={lenA} b={lenB} operation={operation} service={service} />;
}

export function getNodeEmphasisRenderer(keys: Set<string>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (c) 2020 The Jaeger Authors.
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,12 +20,15 @@ import memoizeOne from 'memoize-one';

import convPlexus from '../../../model/trace-dag/convPlexus';
import TraceDag from '../../../model/trace-dag/TraceDag';
import { DiffCounts } from '../../../model/trace-dag/types';
import TDagVertex from '../../../model/trace-dag/types/TDagVertex';
import { DenseSpanMembers, DiffCounts } from '../../../model/trace-dag/types';
import DagPlexusVertex from '../../../model/trace-dag/types/DagPlexusVertex';
import { Trace } from '../../../types/trace';
import filterSpans from '../../../utils/filter-spans';

function getUiFindVertexKeysFn(uiFind: string, vertices: TDagVertex<any>[]): Set<TVertexKey> {
function getUiFindVertexKeysFn(
uiFind: string,
vertices: DagPlexusVertex<DenseSpanMembers>[]
): Set<TVertexKey> {
if (!uiFind) return new Set<TVertexKey>();
const newVertexKeys: Set<TVertexKey> = new Set();
vertices.forEach(({ key, data: { members } }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { TLayoutVertex } from '@jaegertracing/plexus/lib/types';

import { TSumSpan } from './types';
import CopyIcon from '../../common/CopyIcon';
import TDagVertex from '../../../model/trace-dag/types/TDagVertex';
import { DenseSpanMembers } from '../../../model/trace-dag/types';
import DagPlexusVertex from '../../../model/trace-dag/types/DagPlexusVertex';
import colorGenerator from '../../../utils/color-generator';

import './OpNode.css';
Expand Down Expand Up @@ -126,22 +127,21 @@ export default class OpNode extends React.PureComponent<Props> {
}

export function getNodeRenderer(mode: string) {
return function drawNode(vertex: TDagVertex<TSumSpan>) {
const { data, operation, service } = vertex.data;
return <OpNode {...data} mode={mode} operation={operation} service={service} />;
return function drawNode(vertex: DagPlexusVertex<TSumSpan & DenseSpanMembers>) {
return <OpNode {...vertex.data} mode={mode} />;
};
}

export function getNodeFindEmphasisRenderer(uiFindVertexKeys: Set<string> | null | undefined) {
return function renderFindEmphasis(lv: TLayoutVertex<TDagVertex<TSumSpan>>) {
return function renderFindEmphasis(lv: TLayoutVertex<DagPlexusVertex<TSumSpan & DenseSpanMembers>>) {
if (!uiFindVertexKeys || !uiFindVertexKeys.has(lv.vertex.key)) {
return null;
}
return <EmphasizedNode height={lv.height} width={lv.width} />;
};
}

export function renderNodeVectorBorder(lv: TLayoutVertex<TDagVertex<TSumSpan>>) {
export function renderNodeVectorBorder(lv: TLayoutVertex<DagPlexusVertex<TSumSpan>>) {
return (
<rect
className="OpNode--vectorBorder"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import {
HELP_TABLE,
} from './OpNode';
import { TEv, TSumSpan } from './types';
import TDagVertex from '../../../model/trace-dag/types/TDagVertex';
import { DenseSpanMembers } from '../../../model/trace-dag/types';
import DagPlexusVertex from '../../../model/trace-dag/types/DagPlexusVertex';
import { TNil } from '../../../types';

import './TraceGraph.css';
Expand Down Expand Up @@ -154,7 +155,7 @@ export default class TraceGraph extends React.PureComponent<Props, State> {

return (
<div className={wrapperClassName} style={{ paddingTop: headerHeight + 47 }}>
<Digraph<TDagVertex<TSumSpan>>
<Digraph<DagPlexusVertex<TSumSpan & DenseSpanMembers>>
minimap
zoom
className="TraceGraph--dag"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const testTrace = require('./testTrace.json');
const transformedTrace = transformTraceData(testTrace);

function assertData(nodes, service, operation, count, errors, time, percent, selfTime) {
const d = nodes.find(({ data: n }) => n.service === service && n.operation === operation).data.data;
const d = nodes.find(({ data: n }) => n.service === service && n.operation === operation).data;
expect(d).toBeDefined();
expect(d.count).toBe(count);
expect(d.errors).toBe(errors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import DRange from 'drange';
import { TEdge } from '@jaegertracing/plexus/lib/types';
import convPlexus from '../../../model/trace-dag/convPlexus';
import TraceDag from '../../../model/trace-dag/TraceDag';
import DagNode from '../../../model/trace-dag/DagNode';
import { DenseSpanMembers } from '../../../model/trace-dag/types';
import DagNode from '../../../model/trace-dag/types/DagNode';
import { Trace, Span, KeyValuePair } from '../../../types/trace';
import { TSumSpan, TEv } from './types';

Expand All @@ -33,12 +34,15 @@ export function isError(tags: Array<KeyValuePair>) {
return false;
}

function extendFollowsFrom(edges: TEdge[], nodes: DagNode<TSumSpan>[]) {
function mapFollowsFrom(
edges: TEdge[],
nodes: DagNode<TSumSpan & DenseSpanMembers>[]
): TEdge<{ followsFrom: boolean }>[] {
return edges.map(e => {
let hasChildOf = true;
if (typeof e.to === 'number') {
const n = nodes[e.to];
hasChildOf = n.members.some(
const node = nodes[e.to];
hasChildOf = node.members.some(
m => m.span.references && m.span.references.some(r => r.refType === 'CHILD_OF')
);
}
Expand Down Expand Up @@ -72,46 +76,38 @@ function getChildOfDrange(parentID: string, trace: Trace) {
return childrenDrange;
}

export function calculateTraceDag(trace: Trace): TraceDag<TSumSpan> {
const traceDag: TraceDag<TSumSpan> = new TraceDag();
traceDag._initFromTrace(trace, {
count: 0,
errors: 0,
time: 0,
percent: 0,
selfTime: 0,
percentSelfTime: 0,
});
export function calculateTraceDag(trace: Trace): TraceDag<TSumSpan & DenseSpanMembers> {
const baseDag = TraceDag.newFromTrace(trace);
const dag = new TraceDag<TSumSpan & DenseSpanMembers>();

traceDag.nodesMap.forEach(n => {
const ntime = n.members.reduce((p, m) => p + m.span.duration, 0);
const numErrors = n.members.reduce((p, m) => (p + isError(m.span.tags) ? 1 : 0), 0);
const childDurationsDRange = n.members.reduce((p, m) => {
baseDag.nodesMap.forEach(node => {
const ntime = node.members.reduce((p, m) => p + m.span.duration, 0);
const numErrors = node.members.reduce((p, m) => (p + isError(m.span.tags) ? 1 : 0), 0);
const childDurationsDRange = node.members.reduce((p, m) => {
// Using DRange to handle overlapping spans (fork-join)
const cdr = new DRange(m.span.startTime, m.span.startTime + m.span.duration).intersect(
getChildOfDrange(m.span.spanID, trace)
);
return p + cdr.length;
}, 0);
const stime = ntime - childDurationsDRange;
const nd = {
count: n.members.length,
dag.addNode(node.id, node.parentID, {
...node,
count: node.members.length,
errors: numErrors,
time: ntime,
percent: (100 / trace.duration) * ntime,
selfTime: stime,
percentSelfTime: (100 / ntime) * stime,
};
// eslint-disable-next-line no-param-reassign
n.data = nd;
});
});
return traceDag;
return dag;
}

export default function calculateTraceDagEV(trace: Trace): TEv {
const traceDag = calculateTraceDag(trace);
const nodes = [...traceDag.nodesMap.values()];
const ev = convPlexus(traceDag.nodesMap);
ev.edges = extendFollowsFrom(ev.edges, nodes);
return ev;
const edges = mapFollowsFrom(ev.edges, nodes);
return { ...ev, edges };
}
12 changes: 7 additions & 5 deletions packages/jaeger-ui/src/components/TracePage/TraceGraph/types.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (c) 2020 The Jaeger Authors.
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,18 +15,19 @@

import { TEdge } from '@jaegertracing/plexus/lib/types';

import TDagVertex from '../../../model/trace-dag/types/TDagVertex';
import { DenseSpanMembers } from '../../../model/trace-dag/types';
import DagPlexusVertex from '../../../model/trace-dag/types/DagPlexusVertex';

export type TSumSpan = {
count: number;
errors: number;
time: number;
percent: number;
selfTime: number;
percentSelfTime: number;
selfTime: number;
time: number;
};

export type TEv = {
edges: TEdge[];
vertices: TDagVertex<TSumSpan>[];
edges: TEdge<{ followsFrom: boolean }>[];
vertices: DagPlexusVertex<TSumSpan & DenseSpanMembers>[];
};
47 changes: 0 additions & 47 deletions packages/jaeger-ui/src/model/trace-dag/DagNode.tsx

This file was deleted.

Loading

0 comments on commit be6c215

Please sign in to comment.