Merge pull request #2834 from hosseinsh/better-error-handling-dyn

metric tags, to be able to track which domains where failing during t…
This commit is contained in:
Hossein Shafagh 2019-07-30 13:38:12 -07:00 committed by GitHub
commit 0be80e156a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions

View File

@ -33,22 +33,22 @@ def get_dynect_session():
return dynect_session return dynect_session
def _has_dns_propagated(name, token): def _has_dns_propagated(fqdn, token):
txt_records = [] txt_records = []
try: try:
dns_resolver = dns.resolver.Resolver() dns_resolver = dns.resolver.Resolver()
dns_resolver.nameservers = [get_authoritative_nameserver(name)] dns_resolver.nameservers = [get_authoritative_nameserver(fqdn)]
dns_response = dns_resolver.query(name, "TXT") dns_response = dns_resolver.query(fqdn, "TXT")
for rdata in dns_response: for rdata in dns_response:
for txt_record in rdata.strings: for txt_record in rdata.strings:
txt_records.append(txt_record.decode("utf-8")) txt_records.append(txt_record.decode("utf-8"))
except dns.exception.DNSException: except dns.exception.DNSException:
metrics.send("has_dns_propagated_fail", "counter", 1) metrics.send("has_dns_propagated_fail", "counter", 1, metric_tags={"dns": fqdn})
return False return False
for txt_record in txt_records: for txt_record in txt_records:
if txt_record == token: if txt_record == token:
metrics.send("has_dns_propagated_success", "counter", 1) metrics.send("has_dns_propagated_success", "counter", 1, metric_tags={"dns": fqdn})
return True return True
return False return False
@ -61,12 +61,12 @@ def wait_for_dns_change(change_id, account_number=None):
status = _has_dns_propagated(fqdn, token) status = _has_dns_propagated(fqdn, token)
current_app.logger.debug("Record status for fqdn: {}: {}".format(fqdn, status)) current_app.logger.debug("Record status for fqdn: {}: {}".format(fqdn, status))
if status: if status:
metrics.send("wait_for_dns_change_success", "counter", 1) metrics.send("wait_for_dns_change_success", "counter", 1, metric_tags={"dns": fqdn})
break break
time.sleep(10) time.sleep(10)
if not status: if not status:
# TODO: Delete associated DNS text record here # TODO: Delete associated DNS text record here
metrics.send("wait_for_dns_change_fail", "counter", 1) metrics.send("wait_for_dns_change_fail", "counter", 1, metric_tags={"dns": fqdn})
sentry.captureException(extra={"fqdn": str(fqdn), "txt_record": str(token)}) sentry.captureException(extra={"fqdn": str(fqdn), "txt_record": str(token)})
metrics.send( metrics.send(
"wait_for_dns_change_error", "wait_for_dns_change_error",