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

Add error icon to errored services in trace list view #927

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,15 @@ limitations under the License.
.ResultItem--serviceTag {
border-left-width: 15px;
margin: 0;
display: flex;
align-items: center;
}

.ResultItem--errorIcon {
background: #db2828;
border-radius: 6.5px;
color: #fff;
font-size: 0.85em;
margin-right: 0.25rem;
padding: 1px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { Link } from 'react-router-dom';
import { sortBy } from 'lodash';
import moment from 'moment';

import IoAlert from 'react-icons/lib/io/alert';
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved

import { trackConversions, EAltViewActions } from './index.track';
import * as markers from './ResultItem.markers';
import ResultItemTitle from './ResultItemTitle';
Expand All @@ -38,10 +40,43 @@ type Props = {
disableComparision: boolean;
};

type State = {
erroredServices: Set<string>;
numSpans: number;
numErredSpans: number;
timeStr: string;
fromNow: string | boolean;
};

const isErrorTag = ({ key, value }: KeyValuePair) => key === 'error' && (value === true || value === 'true');
const trackTraceConversions = () => trackConversions(EAltViewActions.Traces);

export default class ResultItem extends React.PureComponent<Props> {
export default class ResultItem extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);
const { startTime, spans } = props.trace;

const mDate = moment(startTime / 1000);

const erroredServices: Set<string> = new Set<string>();

const numErredSpans = spans.filter(sp => {
const hasError = sp.tags.some(isErrorTag);
if (hasError) {
erroredServices.add(sp.process.serviceName);
}
return hasError;
}).length;

this.state = {
Copy link
Member

Choose a reason for hiding this comment

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

just curious, how/where is this .state field associated with the State type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

export default class ResultItem extends React.PureComponent<Props, State> {

It is associated here :)

numSpans: spans.length,
timeStr: mDate.format('h:mm:ss a'),
fromNow: mDate.fromNow(),
numErredSpans,
erroredServices,
};
}

render() {
const {
disableComparision,
Expand All @@ -51,12 +86,7 @@ export default class ResultItem extends React.PureComponent<Props> {
toggleComparison,
trace,
} = this.props;
const { duration, services, startTime, spans, traceName, traceID } = trace;
const mDate = moment(startTime / 1000);
const timeStr = mDate.format('h:mm:ss a');
const fromNow = mDate.fromNow();
const numSpans = spans.length;
const numErredSpans = spans.filter(sp => sp.tags.some(isErrorTag)).length;
const { duration, services, startTime, traceName, traceID } = trace;
return (
<div className="ResultItem" onClick={trackTraceConversions} role="button">
<ResultItemTitle
Expand All @@ -73,11 +103,11 @@ export default class ResultItem extends React.PureComponent<Props> {
<Row>
<Col span={4} className="ub-p2">
<Tag className="ub-m1" data-test={markers.NUM_SPANS}>
{numSpans} Span{numSpans > 1 && 's'}
{this.state.numSpans} Span{this.state.numSpans > 1 && 's'}
</Tag>
{Boolean(numErredSpans) && (
{Boolean(this.state.numErredSpans) && (
<Tag className="ub-m1" color="red">
{numErredSpans} Error{numErredSpans > 1 && 's'}
{this.state.numErredSpans} Error{this.state.numErredSpans > 1 && 's'}
</Tag>
)}
</Col>
Expand All @@ -91,6 +121,9 @@ export default class ResultItem extends React.PureComponent<Props> {
className="ResultItem--serviceTag"
style={{ borderLeftColor: colorGenerator.getColorByKey(name) }}
>
{this.state.erroredServices.has(name) && (
<IoAlert className="ResultItem--errorIcon" />
)}
{name} ({count})
</Tag>
</li>
Expand All @@ -101,9 +134,9 @@ export default class ResultItem extends React.PureComponent<Props> {
<Col span={4} className="ub-p3 ub-tx-right-align">
{formatRelativeDate(startTime / 1000)}
<Divider type="vertical" />
{timeStr.slice(0, -3)}&nbsp;{timeStr.slice(-2)}
{this.state.timeStr.slice(0, -3)}&nbsp;{this.state.timeStr.slice(-2)}
<br />
<small>{fromNow}</small>
<small>{this.state.fromNow}</small>
</Col>
</Row>
</Link>
Expand Down