From 05f908f665bd081854c2c2d3e1fc3a27e898f2d1 Mon Sep 17 00:00:00 2001 From: Simon Leinen Date: Wed, 1 Feb 2023 18:20:00 +0100 Subject: [PATCH] DNS Answers: Add ancillary information (#828) * Rename FiveColRow to DNSAnswerRow We may want to add some columns in the future. * DNSAnswerRow -> DnsAnswerRow For consistency with the pre-existing DnsAnswerCell. * DnsAnswerRow: Add ancillary information If the measurement JSON for a DNS answer contains "asn" and/or "as_org_name" fields, we use that to populate the new "Ancillary info" column in human-readable form. * DnsAnswerRow: Improve readability by varying column widths The TTL/class/type values are always short, so make the corresponding fields narrower to leave more space for the other fields, which can be longer. * Renamed "ancillary information" to "Answer IP Info" Also improve output in the (impossible?) case where "asn" is not set, but "as_org_name" is. * DnsAnswerIpInfo: New utility function Factored out from QueryContainer. * Rename DnsAnswerIpInfo to dnsAnswerIpInfo Normal functions seem to use camelCase by convention. * Simplify dnsAnswerIpInfo() Use auxiliary variables to avoid nested conditionals. --- .../measurement/nettests/WebConnectivity.js | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/components/measurement/nettests/WebConnectivity.js b/components/measurement/nettests/WebConnectivity.js index 667002aa2..3b261dfbc 100644 --- a/components/measurement/nettests/WebConnectivity.js +++ b/components/measurement/nettests/WebConnectivity.js @@ -167,32 +167,45 @@ FailureString.propTypes = { failure: PropTypes.string } +const DnsNarrowAnswerCell = (props) => ( + {props.children} +) + const DnsAnswerCell = (props) => ( - {props.children} + {props.children} ) DnsAnswerCell.propTypes = { children: PropTypes.any } -const FiveColRow = ({ name = 'Name', netClass = 'Class', ttl = 'TTL', type = 'Type', data = 'DATA', header = false}) => ( +const dnsAnswerIpInfo = (dnsAnswer) => { + const asn = dnsAnswer.asn ? `AS${dnsAnswer.asn}` : 'Unknown AS' + const asOrgName = dnsAnswer.as_org_name ? `(${dnsAnswer.as_org_name})` : '' + + return `${asn} ${asOrgName}`.trim() +} + +const DnsAnswerRow = ({ name = 'Name', netClass = 'Class', ttl = 'TTL', type = 'Type', data = 'DATA', answer_ip_info = 'Answer IP Info', header = false}) => ( {name} - {netClass} - {ttl} - {type} + {netClass} + {ttl} + {type} {data} + {answer_ip_info} ) -FiveColRow.propTypes = { +DnsAnswerRow.propTypes = { name: PropTypes.string, netClass: PropTypes.string, ttl: PropTypes.number, type: PropTypes.string, data: PropTypes.string, + answer_ip_info: PropTypes.string, header: PropTypes.bool } @@ -228,9 +241,9 @@ const QueryContainer = ({query}) => { {failure && } {!failure && - + {Array.isArray(answers) && answers.map((dnsAnswer, index) => ( - { ? dnsAnswer.hostname : null // for any other answer_type, DATA column will be empty } + answer_ip_info={dnsAnswerIpInfo(dnsAnswer)} /> ))}