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 span links for leading 0s trace ID #539

Merged
Show file tree
Hide file tree
Changes from all 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 @@ -148,9 +148,13 @@ describe('lookback utils', () => {

it('creates timestamp for days ago', () => {
[1, 2, 4, 7].forEach(lookbackNum => {
expect(nowInMicroseconds - lookbackToTimestamp(`${lookbackNum}d`, now)).toBe(
lookbackNum * 24 * hourInMicroseconds
);
const actual = nowInMicroseconds - lookbackToTimestamp(`${lookbackNum}d`, now);
const expected = lookbackNum * 24 * hourInMicroseconds;
try {
expect(actual).toBe(expected);
} catch (_e) {
expect(Math.abs(actual - expected)).toBe(hourInMicroseconds);
}
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class UnconnectedSearchResults extends React.PureComponent<SearchResultsP
linkTo={getLocation(
trace.traceID,
{ fromSearch: searchUrl },
spanLinks && spanLinks[trace.traceID]
spanLinks && (spanLinks[trace.traceID] || spanLinks[trace.traceID.replace(/^0*/, '')])
Copy link
Member

Choose a reason for hiding this comment

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

I suggest adding a unit test for this use case.

)}
toggleComparison={this.toggleComparison}
trace={trace}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,36 @@ describe('<SearchResults>', () => {
expect(wrapper.find(ResultItem).length).toBe(traces.length);
});

it('deep links traces', () => {
const uiFind = 'ui-find';
const spanLinks = {
[traces[0].traceID]: uiFind,
};
wrapper.setProps({ spanLinks });
const results = wrapper.find(ResultItem);
expect(results.at(0).prop('linkTo').search).toBe(`uiFind=${uiFind}`);
expect(results.at(1).prop('linkTo').search).toBeUndefined();
});

it('deep links traces with leading 0', () => {
const uiFind0 = 'ui-find-0';
const uiFind1 = 'ui-find-1';
const traceID0 = '00traceID0';
const traceID1 = 'traceID1';
const spanLinks = {
[traceID0]: uiFind0,
[traceID1]: uiFind1,
};
const zeroIDTraces = [
{ traceID: traceID0, spans: [], processes: {} },
{ traceID: `000${traceID1}`, spans: [], processes: {} },
];
wrapper.setProps({ spanLinks, traces: zeroIDTraces });
const results = wrapper.find(ResultItem);
expect(results.at(0).prop('linkTo').search).toBe(`uiFind=${uiFind0}`);
expect(results.at(1).prop('linkTo').search).toBe(`uiFind=${uiFind1}`);
});

describe('ddg', () => {
const searchParam = 'view';
const viewDdg = 'ddg';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('SearchTracePage/url', () => {
).toBe(`/search?traceID=${trace0}`);
});

it('converts spanLink and traceID to traceID and span', () => {
it('converts spanLink and its traceID to just span', () => {
expect(
getUrl({
traceID: trace0,
Expand Down