Skip to content

Commit

Permalink
Fixes endpoint formatting, notably undefined references
Browse files Browse the repository at this point in the history
This omits dummy port zero and undefined IPs when viewing span details
  • Loading branch information
Adrian Cole committed Mar 16, 2018
1 parent 27f922f commit 872a331
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
18 changes: 8 additions & 10 deletions zipkin-ui/js/component_ui/traceToMustache.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,15 @@ function toSpanDepths(spans) {
return treeDepths(entry, 1);
}

export function formatEndpoint({ipv4, ipv6, port = 0, serviceName = ''}) {
if (serviceName) {
if (ipv6) {
return `[${ipv6}]:${port} (${serviceName})`;
}
return `${ipv4}:${port} (${serviceName})`;
}
if (ipv6) {
return `[${ipv6}]:${port}`;
export function formatEndpoint({ipv4, ipv6, port, serviceName}) {
if (ipv4 || ipv6) {
const ip = ipv6 ? `[${ipv6}]` : ipv4; // arbitrarily prefer ipv6
const portString = port ? `:${port}` : '';
const serviceNameString = serviceName ? ` (${serviceName})` : '';
return ip + portString + serviceNameString;
} else {
return serviceName || '';
}
return `${ipv4}:${port}`;
}

export default function traceToMustache(trace, logsUrl = undefined) {
Expand Down
25 changes: 23 additions & 2 deletions zipkin-ui/test/component_ui/traceToMustache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,37 @@ describe('formatEndpoint', () => {
formatEndpoint({ipv4: '150.151.152.153', port: 5000}).should.equal('150.151.152.153:5000');
});

it('should use 0 as default port', () => {
formatEndpoint({ipv4: '150.151.152.153'}).should.equal('150.151.152.153:0');
it('should not use port when missing or zero', () => {
formatEndpoint({ipv4: '150.151.152.153'}).should.equal('150.151.152.153');
formatEndpoint({ipv4: '150.151.152.153', port: 0}).should.equal('150.151.152.153');
});

it('should put service name in parenthesis', () => {
formatEndpoint({ipv4: '150.151.152.153', port: 9042, serviceName: 'cassandra'}).should.equal(
'150.151.152.153:9042 (cassandra)'
);
formatEndpoint({ipv4: '150.151.152.153', serviceName: 'cassandra'}).should.equal(
'150.151.152.153 (cassandra)'
);
});

it('should not show empty service name', () => {
formatEndpoint({ipv4: '150.151.152.153', port: 9042, serviceName: ''}).should.equal(
'150.151.152.153:9042'
);
formatEndpoint({ipv4: '150.151.152.153', serviceName: ''}).should.equal(
'150.151.152.153'
);
});

it('should show service name missing IP', () => {
formatEndpoint({serviceName: 'rabbit'}).should.equal(
'rabbit'
);
});

it('should not crash on no data', () => {
formatEndpoint({}).should.equal('');
});

it('should put ipv6 in brackets', () => {
Expand All @@ -222,5 +239,9 @@ describe('formatEndpoint', () => {
formatEndpoint({ipv6: '2001:db8::c001', port: 9042}).should.equal(
'[2001:db8::c001]:9042'
);

formatEndpoint({ipv6: '2001:db8::c001'}).should.equal(
'[2001:db8::c001]'
);
});
});

0 comments on commit 872a331

Please sign in to comment.