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

Handle the listening interface not yet existing in the metrics exporter. #1351

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion ntpd/src/metrics/exporter.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use timestamped_socket::interface::ChangeDetector;
use tokio::io::AsyncWriteExt;
use tokio::net::TcpListener;

Expand Down Expand Up @@ -136,7 +137,27 @@ async fn run(options: NtpMetricsExporterOptions) -> Result<(), Box<dyn std::erro
&config.observability.metrics_exporter_listen
);

let listener = TcpListener::bind(&config.observability.metrics_exporter_listen).await?;
let listener = loop {
match TcpListener::bind(&config.observability.metrics_exporter_listen).await {
Err(e) if e.kind() == std::io::ErrorKind::AddrNotAvailable => {
tracing::info!("Could not open listening socket, waiting for interface to come up");
let _ = tokio::time::timeout(
std::time::Duration::from_secs(60),
ChangeDetector::new()?.wait_for_change(),
)
.await;
}
Err(e) => {
tracing::warn!("Could not open listening socket: {}", e);
let _ = tokio::time::timeout(
std::time::Duration::from_secs(60),
ChangeDetector::new()?.wait_for_change(),
)
.await;
}
Ok(listener) => break listener,
};
};
let mut buf = String::with_capacity(4 * 1024);

loop {
Expand Down
Loading