Skip to content

Commit

Permalink
Update hickory, adapt code (#2971)
Browse files Browse the repository at this point in the history
* Update hickory-resolver version.

Also: change renamed feature name (see hickory-dns/hickory-dns@c96a234)

* Make some adaptations because SemVer lost its meaning

* More changes for ZeroVersioned dependency minor bump

* Cargo.lock after rebase

* changelog

* More changes for a dependency's "minor" version

Also, added to CONTRIBUTING.md how to check agent code on macOS.
  • Loading branch information
t4lz authored Dec 9, 2024
1 parent d0e0cd4 commit 7e35718
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 83 deletions.
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,27 @@ If you're using rust-analyzer VSCode extension, put this block in `.vscode/setti
]
}
```

You can use `cargo-zigbuild` to run `cargo check` or `clippy` on the agent's code on macOS.

`cargo check`

```shell
cargo-zigbuild check -p mirrord-agent --target x86_64-unknown-linux-gnu
```

`clippy` only for the agent

```shell
cargo-zigbuild clippy --target x86_64-unknown-linux-gnu -p mirrord-agent -- -Wclippy::indexing_slicing -D warnings
```

`clippy` for all code:

```shell
cargo-zigbuild clippy --lib --bins --all-features --target x86_64-unknown-linux-gnu --tests -- -Wclippy::indexing_slicing -D warnings
```

If it doesn't work, try updating `cargo-zigbuild`
(`cargo install cargo-zigbuild` or maybe `cargo install cargo-zigbuild --force`)
or via `homebrew` if it was installed via homebrew.
136 changes: 87 additions & 49 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ kube = { git = "https://github.com/kube-rs/kube.git", rev = "ecbdafc214538aadc78
"socks5",
"http-proxy",
] }
hickory-resolver = { version = "0.24", features = [
"serde-config",
hickory-resolver = { version = "0.25.0-alpha.4", features = [
"serde",
"tokio-runtime",
] }
hickory-proto = "0.25.0-alpha.4"
tokio-util = { version = "0.7", features = ["net", "codec"] }

# Used by `layer`, `intproxy`, `tests`, `medschool`, `cli`, `agent`, `operator`.
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+update-deps.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update hickory dependency version.
15 changes: 8 additions & 7 deletions mirrord/agent/src/dns.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{future, path::PathBuf, time::Duration};

use futures::{stream::FuturesOrdered, StreamExt};
use hickory_resolver::{system_conf::parse_resolv_conf, AsyncResolver, Hosts};
use hickory_resolver::{system_conf::parse_resolv_conf, Hosts, Resolver};
use mirrord_protocol::{
dns::{DnsLookup, GetAddrInfoRequest, GetAddrInfoResponse},
DnsLookupError, RemoteResult, ResolveErrorKindInternal, ResponseError,
Expand Down Expand Up @@ -69,21 +69,21 @@ impl DnsWorker {
}
}

/// Reads `/etc/resolv.conf` and `/etc/hosts` files, then uses [`AsyncResolver`] to resolve
/// address of the given `host`.
/// Reads `/etc/resolv.conf` and `/etc/hosts` files, then uses [`hickory_resolver::Resolver`] to
/// resolve address of the given `host`.
///
/// # TODO
///
/// We could probably cache results here.
/// We cannot cache the [`AsyncResolver`] itself, becaues the configuration in `etc` may change.
/// We cannot cache the [`Resolver`] itself, becaues the configuration in `etc` may change.
#[tracing::instrument(level = Level::TRACE, ret, err(level = Level::TRACE))]
async fn do_lookup(
etc_path: PathBuf,
host: String,
attempts: usize,
timeout: Duration,
) -> RemoteResult<DnsLookup> {
// Prepares the `AsyncResolver` after reading some `/etc` DNS files.
// Prepares the `Resolver` after reading some `/etc` DNS files.
//
// We care about logging these errors, at an `error!` level.
let resolver: Result<_, ResponseError> = try {
Expand All @@ -100,9 +100,10 @@ impl DnsWorker {
options.attempts = attempts;
options.ip_strategy = hickory_resolver::config::LookupIpStrategy::Ipv4Only;

let mut resolver = AsyncResolver::tokio(config, options);
let mut resolver = Resolver::tokio(config, options);

let hosts = Hosts::default().read_hosts_conf(hosts_conf.as_slice())?;
let mut hosts = Hosts::default();
hosts.read_hosts_conf(hosts_conf.as_slice())?;
resolver.set_hosts(Some(hosts));

resolver
Expand Down
1 change: 1 addition & 0 deletions mirrord/protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ actix-codec.workspace = true
bytes.workspace = true
thiserror.workspace = true
hickory-resolver.workspace = true
hickory-proto.workspace = true
serde.workspace = true
bincode.workspace = true
tracing.workspace = true
Expand Down
10 changes: 4 additions & 6 deletions mirrord/protocol/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ impl From<LookupIp> for DnsLookup {
name_labels, rdata, ..
} = record.into_parts();

rdata
.and_then(|rdata| rdata.ip_addr())
.map(|ip| LookupRecord {
name: name_labels.to_string(),
ip,
})
rdata.ip_addr().map(|ip| LookupRecord {
name: name_labels.to_string(),
ip,
})
})
.collect::<Vec<_>>();

Expand Down
Loading

0 comments on commit 7e35718

Please sign in to comment.