Skip to content

Commit

Permalink
Merge pull request #136 from jaegertracing/issue-128-endless-trace-ht…
Browse files Browse the repository at this point in the history
…tp-reqs

Fix endless trace HTTP requests
  • Loading branch information
tiffon authored Dec 16, 2017
2 parents ffbbcea + 6c6a82c commit 6e5fa22
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/components/App/TraceIDSearchInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';

import prefixUrl from '../../utils/prefix-url';

class TraceIDSearchInput extends Component {
goToTrace(e) {
this.props.history.push(`/trace/${this.traceIDInput.value}`);
this.props.history.push(prefixUrl(`/trace/${this.traceIDInput.value}`));
e.preventDefault();
return false;
}
Expand Down
13 changes: 10 additions & 3 deletions src/components/TracePage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import _mapValues from 'lodash/mapValues';
import _maxBy from 'lodash/maxBy';
import _values from 'lodash/values';
import { connect } from 'react-redux';
import type { Match } from 'react-router-dom';
import type { RouterHistory, Match } from 'react-router-dom';
import { bindActionCreators } from 'redux';

import type { CombokeysHandler, ShortcutCallbacks } from './keyboard-shortcuts';
Expand All @@ -35,14 +35,16 @@ import NotFound from '../App/NotFound';
import * as jaegerApiActions from '../../actions/jaeger-api';
import { getTraceName } from '../../model/trace-viewer';
import type { Trace } from '../../types';
import prefixUrl from '../../utils/prefix-url';

import './index.css';

type TracePageProps = {
fetchTrace: string => void,
trace: ?Trace,
loading: boolean,
history: RouterHistory,
id: string,
loading: boolean,
trace: ?Trace,
};

type TracePageState = {
Expand Down Expand Up @@ -205,6 +207,11 @@ export default class TracePage extends React.PureComponent<TracePageProps, Trace
const { fetchTrace, trace, id, loading } = this.props;
if (!trace && !loading) {
fetchTrace(id);
return;
}
const { history } = this.props;
if (id && id !== id.toLowerCase()) {
history.push(prefixUrl(`/trace/${id.toLowerCase()}`));
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/model/transform-trace-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ type SpanWithProcess = SpanData & { process: Process };
* NOTE: Mutates `data` - Transform the HTTP response data into the form the app
* generally requires.
*/
export default function transfromTraceData(data: TraceData & { spans: SpanWithProcess[] }): Trace {
export default function transfromTraceData(data: TraceData & { spans: SpanWithProcess[] }): ?Trace {
let { traceID } = data;
if (!traceID) {
return null;
}
traceID = traceID.toLowerCase();

let traceEndTime = 0;
let traceStartTime = Number.MAX_SAFE_INTEGER;
const spanIdCounts = new Map();
Expand Down Expand Up @@ -87,11 +93,11 @@ export default function transfromTraceData(data: TraceData & { spans: SpanWithPr
});
return {
spans,
traceID,
// can't use spread operator for intersection types
// repl: https://goo.gl/4Z23MJ
// issue: https://github.com/facebook/flow/issues/1511
processes: data.processes,
traceID: data.traceID,
duration: traceEndTime - traceStartTime,
startTime: traceStartTime,
endTime: traceEndTime,
Expand Down
9 changes: 7 additions & 2 deletions src/reducers/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ function fetchStarted(state) {
return { ...state, loading: true };
}

function fetchTraceDone(state, { payload }) {
function fetchTraceDone(state, { meta, payload }) {
const trace = transformTraceData(payload.data[0]);
const traces = { ...state.traces, [trace.traceID]: trace };
let traces;
if (!trace) {
traces = { ...state.traces, [meta.id]: new Error('Invalid trace data recieved.') };
} else {
traces = { ...state.traces, [trace.traceID]: trace };
}
return { ...state, traces, loading: false };
}

Expand Down

0 comments on commit 6e5fa22

Please sign in to comment.