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

Fix endless trace HTTP requests #136

Merged
merged 2 commits into from
Dec 16, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
9 changes: 7 additions & 2 deletions src/model/transform-trace-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ 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 {
const traceID = data.traceID.toLowerCase();
if (!traceID) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a check for traceID==null, shouldn't it be before L29?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking for empty string, but to be cautious will adjust.

return null;
}

let traceEndTime = 0;
let traceStartTime = Number.MAX_SAFE_INTEGER;
const spanIdCounts = new Map();
Expand Down Expand Up @@ -87,11 +92,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