Skip to content

Commit 6059fed

Browse files
committed
PR feedback - JSDoc, move trace transform
- JSDoc tweaks - documentation.js can infer types automatically - Move trace transform - Move trace tranform out of src/components/TracePage/TraceTimelineViewer/transforms and into src/model/transform-trace-data.js - Apply trace transform to data from HTTP response so the trace data stored in the state is always the enriched form
1 parent 3c8057e commit 6059fed

24 files changed

+244
-294
lines changed

src/components/TracePage/TraceSpanGraph.js

+10-18
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@ import PropTypes from 'prop-types';
2525
import SpanGraph from './SpanGraph';
2626
import SpanGraphTickHeader from './SpanGraph/SpanGraphTickHeader';
2727
import TimelineScrubber from './TimelineScrubber';
28-
import { getTraceId, getTraceTimestamp, getTraceEndTimestamp, getTraceDuration } from '../../selectors/trace';
2928
import { getPercentageOfInterval } from '../../utils/date';
3029

3130
const TIMELINE_TICK_INTERVAL = 4;
3231

3332
export default class TraceSpanGraph extends Component {
3433
static get propTypes() {
3534
return {
36-
xformedTrace: PropTypes.object,
3735
trace: PropTypes.object,
3836
height: PropTypes.number.isRequired,
3937
};
@@ -71,7 +69,7 @@ export default class TraceSpanGraph extends Component {
7169
const newRightBound = newTimeRangeFilter[1];
7270

7371
return (
74-
getTraceId(trace) !== getTraceId(newTrace) ||
72+
trace.traceID !== newTrace.traceID ||
7573
leftBound !== newLeftBound ||
7674
rightBound !== newRightBound ||
7775
currentlyDragging !== newCurrentlyDragging
@@ -109,19 +107,16 @@ export default class TraceSpanGraph extends Component {
109107
let rightBound = timeRangeFilter[1];
110108

111109
const deltaX = (clientX - prevX) / this.svg.clientWidth;
112-
const timestamp = getTraceTimestamp(trace);
113-
const endTimestamp = getTraceEndTimestamp(trace);
114-
const duration = getTraceDuration(this.props.trace);
115110
const prevValue = { leftBound, rightBound }[currentlyDragging];
116-
const newValue = prevValue + duration * deltaX;
111+
const newValue = prevValue + trace.duration * deltaX;
117112

118113
// enforce the edges of the graph
119114
switch (currentlyDragging) {
120115
case 'leftBound':
121-
leftBound = Math.max(timestamp, newValue);
116+
leftBound = Math.max(trace.startTime, newValue);
122117
break;
123118
case 'rightBound':
124-
rightBound = Math.min(endTimestamp, newValue);
119+
rightBound = Math.min(trace.endTime, newValue);
125120
break;
126121
/* istanbul ignore next */ default:
127122
break;
@@ -134,7 +129,7 @@ export default class TraceSpanGraph extends Component {
134129
}
135130

136131
render() {
137-
const { trace, xformedTrace, height } = this.props;
132+
const { trace, height } = this.props;
138133
const { currentlyDragging } = this.state;
139134
const { timeRangeFilter } = this.context;
140135
const leftBound = timeRangeFilter[0];
@@ -144,23 +139,20 @@ export default class TraceSpanGraph extends Component {
144139
return <div />;
145140
}
146141

147-
const initialTimestamp = getTraceTimestamp(trace);
148-
const traceDuration = getTraceDuration(trace);
149-
150142
let leftInactive;
151143
if (leftBound) {
152-
leftInactive = getPercentageOfInterval(leftBound, initialTimestamp, traceDuration);
144+
leftInactive = getPercentageOfInterval(leftBound, trace.startTime, trace.duration);
153145
}
154146

155147
let rightInactive;
156148
if (rightBound) {
157-
rightInactive = 100 - getPercentageOfInterval(rightBound, initialTimestamp, traceDuration);
149+
rightInactive = 100 - getPercentageOfInterval(rightBound, trace.startTime, trace.duration);
158150
}
159151

160152
return (
161153
<div>
162154
<div className="trace-page-timeline--tick-container">
163-
<SpanGraphTickHeader numTicks={TIMELINE_TICK_INTERVAL} duration={traceDuration} />
155+
<SpanGraphTickHeader numTicks={TIMELINE_TICK_INTERVAL} duration={trace.duration} />
164156
</div>
165157
<div>
166158
<svg
@@ -187,9 +179,9 @@ export default class TraceSpanGraph extends Component {
187179
className="trace-page-timeline__graph--inactive"
188180
/>}
189181
<SpanGraph
190-
valueWidth={xformedTrace.duration}
182+
valueWidth={trace.duration}
191183
numTicks={TIMELINE_TICK_INTERVAL}
192-
items={xformedTrace.spans.map(span => ({
184+
items={trace.spans.map(span => ({
193185
valueOffset: span.relativeStartTime,
194186
valueWidth: span.duration,
195187
serviceName: span.process.serviceName,

src/components/TracePage/TraceSpanGraph.test.js

+11-19
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,14 @@ import TraceSpanGraph from './TraceSpanGraph';
2727
import SpanGraphTickHeader from './SpanGraph/SpanGraphTickHeader';
2828
import TimelineScrubber from './TimelineScrubber';
2929
import traceGenerator from '../../../src/demo/trace-generators';
30-
import { transformTrace } from './TraceTimelineViewer/transforms';
31-
import { hydrateSpansWithProcesses } from '../../selectors/trace';
30+
import transformTraceData from '../../model/transform-trace-data';
3231

3332
describe('<TraceSpanGraph>', () => {
34-
const trace = hydrateSpansWithProcesses(traceGenerator.trace({}));
35-
const xformedTrace = transformTrace(trace);
36-
37-
const props = {
38-
trace,
39-
xformedTrace,
40-
};
41-
33+
const trace = transformTraceData(traceGenerator.trace({}));
34+
const props = { trace };
4235
const options = {
4336
context: {
44-
timeRangeFilter: [trace.timestamp, trace.timestamp + trace.duration],
37+
timeRangeFilter: [trace.startTime, trace.startTime + trace.duration],
4538
updateTimeRangeFilter: () => {},
4639
},
4740
};
@@ -68,7 +61,7 @@ describe('<TraceSpanGraph>', () => {
6861
it('renders a filtering box if leftBound exists', () => {
6962
const context = {
7063
...options.context,
71-
timeRangeFilter: [trace.timestamp + 0.2 * trace.duration, trace.timestamp + trace.duration],
64+
timeRangeFilter: [trace.startTime + 0.2 * trace.duration, trace.startTime + trace.duration],
7265
};
7366
wrapper = shallow(<TraceSpanGraph {...props} />, { ...options, context });
7467
const leftBox = wrapper.find('.trace-page-timeline__graph--inactive');
@@ -82,7 +75,7 @@ describe('<TraceSpanGraph>', () => {
8275
it('renders a filtering box if rightBound exists', () => {
8376
const context = {
8477
...options.context,
85-
timeRangeFilter: [trace.timestamp, trace.timestamp + 0.8 * trace.duration],
78+
timeRangeFilter: [trace.startTime, trace.startTime + 0.8 * trace.duration],
8679
};
8780
wrapper = shallow(<TraceSpanGraph {...props} />, { ...options, context });
8881
const rightBox = wrapper.find('.trace-page-timeline__graph--inactive');
@@ -132,7 +125,7 @@ describe('<TraceSpanGraph>', () => {
132125

133126
it('passes items to SpanGraph', () => {
134127
const spanGraph = wrapper.find(SpanGraph).first();
135-
const items = xformedTrace.spans.map(span => ({
128+
const items = trace.spans.map(span => ({
136129
valueOffset: span.relativeStartTime,
137130
valueWidth: span.duration,
138131
serviceName: span.process.serviceName,
@@ -151,9 +144,8 @@ describe('<TraceSpanGraph>', () => {
151144
it('returns true for new trace', () => {
152145
const state = wrapper.state();
153146
const instance = wrapper.instance();
154-
const trace2 = hydrateSpansWithProcesses(traceGenerator.trace({}));
155-
const xformedTrace2 = transformTrace(trace2);
156-
const altProps = { trace: trace2, xformedTrace: xformedTrace2 };
147+
const trace2 = transformTraceData(traceGenerator.trace({}));
148+
const altProps = { trace: trace2 };
157149
expect(instance.shouldComponentUpdate(altProps, state, options.context)).toBe(true);
158150
});
159151

@@ -190,7 +182,7 @@ describe('<TraceSpanGraph>', () => {
190182
});
191183

192184
it('updates the timeRangeFilter for the left handle', () => {
193-
const timestamp = trace.timestamp;
185+
const timestamp = trace.startTime;
194186
const duration = trace.duration;
195187
const updateTimeRangeFilter = sinon.spy();
196188
const context = { ...options.context, updateTimeRangeFilter };
@@ -204,7 +196,7 @@ describe('<TraceSpanGraph>', () => {
204196
});
205197

206198
it('updates the timeRangeFilter for the right handle', () => {
207-
const timestamp = trace.timestamp;
199+
const timestamp = trace.startTime;
208200
const duration = trace.duration;
209201
const updateTimeRangeFilter = sinon.spy();
210202
const context = { ...options.context, updateTimeRangeFilter };

src/components/TracePage/TraceTimelineViewer/ListView/Positions.js

+1-22
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ export default class Positions {
3333
/**
3434
* Indicates how far past the explicitly required height or y-values should
3535
* checked.
36-
* @type {number}
37-
* @memberof Positions
3836
*/
3937
bufferLen: number;
4038
dataLen: number;
@@ -43,8 +41,6 @@ export default class Positions {
4341
* `lastI` keeps track of which values have already been visited. In many
4442
* scenarios, values do not need to be revisited. But, revisiting is required
4543
* when heights have changed, so `lastI` can be forced.
46-
* @type {number}
47-
* @memberof Positions
4844
*/
4945
lastI: number;
5046
ys: number[];
@@ -60,8 +56,6 @@ export default class Positions {
6056
/**
6157
* Used to make sure the length of y-values and heights is consistent with
6258
* the context; in particular `lastI` needs to remain valid.
63-
*
64-
* @param {any[]} data
6559
*/
6660
profileData(dataLength: number) {
6761
if (dataLength !== this.dataLen) {
@@ -78,10 +72,7 @@ export default class Positions {
7872
* Calculate and save the heights and y-values, based on `heightGetter`, from
7973
* `lastI` until the`max` index; the starting point (`lastI`) can be forced
8074
* via the `forcedLastI` parameter.
81-
*
82-
* @param {number} max
83-
* @param {number} heightGetter
84-
* @param {number} [forcedLastI]
75+
* @param {number=} forcedLastI
8576
*/
8677
calcHeights(max: number, heightGetter: number => number, forcedLastI?: number) {
8778
if (forcedLastI != null) {
@@ -110,9 +101,6 @@ export default class Positions {
110101

111102
/**
112103
* Verify the height and y-values from `lastI` up to `yValue`.
113-
*
114-
* @param {number} yValue
115-
* @param {number => number} heightGetter
116104
*/
117105
calcYs(yValue: number, heightGetter: number => number) {
118106
while ((this.ys[this.lastI] == null || yValue > this.ys[this.lastI]) && this.lastI < this.dataLen - 1) {
@@ -124,10 +112,6 @@ export default class Positions {
124112
* Given a target y-value (`yValue`), find the closest index (in the `.ys`
125113
* array) that is prior to the y-value; e.g. map from y-value to index in
126114
* `.ys`.
127-
*
128-
* @param {number} yValue
129-
* @param {number => number} heightGetter
130-
* @returns {number}
131115
*/
132116
findFloorIndex(yValue: number, heightGetter: number => number): number {
133117
this.calcYs(yValue, heightGetter);
@@ -164,8 +148,6 @@ export default class Positions {
164148
/**
165149
* Get the estimated height of the whole shebang by extrapolating based on
166150
* the average known height.
167-
*
168-
* @returns {number}
169151
*/
170152
getEstimatedHeight(): number {
171153
const known = this.ys[this.lastI] + this.heights[this.lastI];
@@ -183,9 +165,6 @@ export default class Positions {
183165
* known territory (_i <= lastI) and the height is different than what is
184166
* known, recalculate subsequent y values, but don't confirm the heights of
185167
* those items, just update based on the difference.
186-
*
187-
* @param {number} _i
188-
* @param {number => number} heightGetter
189168
*/
190169
confirmHeight(_i: number, heightGetter: number => number) {
191170
let i = _i;

0 commit comments

Comments
 (0)