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

[internal-dns] Add utilities in the client library #1177

Merged
merged 33 commits into from
Jun 24, 2022
Merged

[internal-dns] Add utilities in the client library #1177

merged 33 commits into from
Jun 24, 2022

Conversation

smklein
Copy link
Collaborator

@smklein smklein commented Jun 8, 2022

Adds utilities in the internal DNS client library to:

  • Encourage correct usage of SRV / AAAA names (See: RFD 248)
  • Provide a "single point of entry" for updating multiple DNS servers

This PR has been pulled out of #1216 , where it is used in both Nexus and RSS

@smklein smklein changed the base branch from main to nexus-argsplit June 15, 2022 20:46
@smklein smklein changed the base branch from nexus-argsplit to fix-internal-dns-api June 20, 2022 19:30
@smklein smklein marked this pull request as ready for review June 20, 2022 19:31
@smklein smklein changed the title [internal DNS] Add utilities in the helper library [internal DNS] Add utilities in the client library Jun 20, 2022
@smklein smklein changed the title [internal DNS] Add utilities in the client library [internal-dns] Add utilities in the client library Jun 20, 2022

/// Sets a records on all DNS servers.
///
/// Returns an error if setting the record fails on any server.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's pretty likely we'll want to change this behavior to cope with one or more of the DNS servers failing.

However, I really want our behavior to be "fail loud" until we have a good way of coping. If one of the DNS servers starts failing, ideally Nexus could:

  • Notice when it is actually setting the records, pick out which server failed
  • If it continues to not respond (or throw errors), mark the service as "deprecated", re-establish service redundancy elsewhere

Until then though, if an internal DNS server fails, I want high-visibility on the error. Hopefully this tradeoff makes sense?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also of note: This is exclusively on the "setting DNS records" side of things. The "getting DNS records" side should be able to cope with a server going offline already.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I generally agree about failing loud, but it does seem slightly at odds with the availability-first ethos of DNS. This is probably good for now though, without more information about how the client-side will work.

Base automatically changed from fix-internal-dns-api to main June 21, 2022 17:39
@smklein smklein requested a review from bnaecker June 23, 2022 12:53
/// This method is most efficient when records are sorted by SRV key.
pub async fn insert_dns_records(
&self,
records: &Vec<impl Service>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure exactly how to express this, but I can't help but feeling this should be a map. In the case where records is sorted by SRV, then that's effectively what we're doing inside by coalescing all AAAA records and addresses. A map might be frustrating for consumers, though, since it seems like we'll want to impl Service for some types (which returns exactly one AAAA and address) and pass one or more of them.

This isn't a correctness issue, I think, so deferring it is fine. I think the while let loop on L100 could use a quick comment that we are in fact coalescing, mostly for efficiency in terms of actually inserting the KV records. (I think...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can do a &HashMap<SRV, Vec<(AAAA, SocketAddr)>> - that seems to accomplish what you're describing.

Although I do think this is slightly more burden on consumers, I also think it's more clear on both sides. I've updated to use this format (one SRV, many AAAA/addrs).

/// A wrapper around a DNS resolver, providing a way to conveniently
/// look up IP addresses of services based on their SRV keys.
pub struct Resolver {
inner: Box<TokioAsyncResolver>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the motivation for boxing this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm using it in subsequent patches in an enum (you can provide an IP from a config, or use a resolver), and Clippy complained that it was too large (500+ bytes). Since it's internal to the struct, it shouldn't matter for users of this API.

Comment on lines 581 to 583
.dns_records_delete(&vec![DnsRecordKey {
name: records[0].aaaa.to_string(),
}])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious about the API here, but both records[0] and records[1] could be deleted simultaneously, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup; might as well show that. Call updated.

Copy link
Collaborator

@bnaecker bnaecker left a comment

Choose a reason for hiding this comment

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

Looks good, nice work! A few questions, one data-structure comment that shouldn't block merging. Thanks!

@smklein smklein enabled auto-merge (squash) June 24, 2022 01:56
@smklein smklein merged commit 4220e39 into main Jun 24, 2022
@smklein smklein deleted the dns-client branch June 24, 2022 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants