Skip to content

Commit fd55568

Browse files
committed
gw: Better error logging
1 parent 4f673ba commit fd55568

2 files changed

Lines changed: 49 additions & 49 deletions

File tree

gateway/src/distributed_certbot.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ impl DistributedCertBot {
5252
pub async fn init_all(&self) -> Result<()> {
5353
let configs = self.kv_store.list_zt_domain_configs();
5454
for config in configs {
55-
if let Err(e) = self.init_domain(&config.domain).await {
56-
error!("cert[{}]: failed to initialize: {}", config.domain, e);
55+
if let Err(err) = self.init_domain(&config.domain).await {
56+
error!("cert[{}]: failed to initialize: {err:?}", config.domain);
5757
}
5858
}
5959
Ok(())
@@ -86,8 +86,8 @@ impl DistributedCertBot {
8686
pub async fn try_renew_all(&self) -> Result<()> {
8787
let configs = self.kv_store.list_zt_domain_configs();
8888
for config in configs {
89-
if let Err(e) = self.try_renew(&config.domain, false).await {
90-
error!("cert[{}]: failed to renew: {}", config.domain, e);
89+
if let Err(err) = self.try_renew(&config.domain, false).await {
90+
error!("cert[{}]: failed to renew: {err:?}", config.domain);
9191
}
9292
}
9393
Ok(())
@@ -140,8 +140,8 @@ impl DistributedCertBot {
140140
};
141141

142142
// Release lock regardless of result
143-
if let Err(e) = self.kv_store.release_cert_lock(domain) {
144-
error!("failed to release lock: {e}");
143+
if let Err(err) = self.kv_store.release_cert_lock(domain) {
144+
error!("failed to release lock: {err:?}");
145145
}
146146

147147
result
@@ -172,8 +172,8 @@ impl DistributedCertBot {
172172

173173
let result = self.do_request_new(domain, &config).await;
174174

175-
if let Err(e) = self.kv_store.release_cert_lock(domain) {
176-
error!("failed to release lock: {e}");
175+
if let Err(err) = self.kv_store.release_cert_lock(domain) {
176+
error!("failed to release lock: {err:?}");
177177
}
178178

179179
result
@@ -364,8 +364,8 @@ impl DistributedCertBot {
364364
async fn generate_and_save_acme_attestation(&self, account_uri: &str) -> Result<()> {
365365
let agent = match crate::dstack_agent() {
366366
Ok(a) => a,
367-
Err(e) => {
368-
warn!("failed to create dstack agent: {e}");
367+
Err(err) => {
368+
warn!("failed to create dstack agent: {err:?}");
369369
return Ok(());
370370
}
371371
};
@@ -382,17 +382,17 @@ impl DistributedCertBot {
382382
.await
383383
{
384384
Ok(resp) => serde_json::to_string(&resp).unwrap_or_default(),
385-
Err(e) => {
386-
warn!("failed to get TDX quote for ACME account: {e}");
385+
Err(err) => {
386+
warn!("failed to get TDX quote for ACME account: {err:?}");
387387
return Ok(());
388388
}
389389
};
390390

391391
// Get attestation
392392
let attestation_str = match agent.attest(RawQuoteArgs { report_data }).await {
393393
Ok(resp) => serde_json::to_string(&resp).unwrap_or_default(),
394-
Err(e) => {
395-
warn!("failed to get attestation for ACME account: {e}");
394+
Err(err) => {
395+
warn!("failed to get attestation for ACME account: {err:?}");
396396
String::new()
397397
}
398398
};
@@ -434,8 +434,8 @@ impl DistributedCertBot {
434434
) -> Result<()> {
435435
let agent = match crate::dstack_agent() {
436436
Ok(a) => a,
437-
Err(e) => {
438-
warn!(domain, "failed to create dstack agent: {e}");
437+
Err(err) => {
438+
warn!(domain, "failed to create dstack agent: {err:?}");
439439
return Ok(());
440440
}
441441
};
@@ -452,17 +452,17 @@ impl DistributedCertBot {
452452
.await
453453
{
454454
Ok(resp) => serde_json::to_string(&resp).unwrap_or_default(),
455-
Err(e) => {
456-
warn!(domain, "failed to generate TDX quote: {e}");
455+
Err(err) => {
456+
warn!(domain, "failed to generate TDX quote: {err:?}");
457457
return Ok(());
458458
}
459459
};
460460

461461
// Get attestation
462462
let attestation = match agent.attest(RawQuoteArgs { report_data }).await {
463463
Ok(resp) => serde_json::to_string(&resp).unwrap_or_default(),
464-
Err(e) => {
465-
warn!(domain, "failed to get attestation: {e}");
464+
Err(err) => {
465+
warn!(domain, "failed to get attestation: {err:?}");
466466
String::new()
467467
}
468468
};

gateway/src/main_service.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ impl ProxyInner {
150150
wg_ip: config.wg.ip.to_string(),
151151
};
152152
if let Err(err) = kv_store.sync_node(config.sync.node_id, &node_data) {
153-
error!("Failed to sync this node to KvStore: {err}");
153+
error!("Failed to sync this node to KvStore: {err:?}");
154154
}
155155
// Set this node's status to Online
156156
if let Err(err) = kv_store.set_node_status(config.sync.node_id, NodeStatus::Up) {
157-
error!("Failed to set node status: {err}");
157+
error!("Failed to set node status: {err:?}");
158158
}
159159
// Register this node's sync URL in DB (for peer discovery)
160160
if let Err(err) = kv_store.register_peer_url(config.sync.node_id, &config.sync.my_url) {
161-
error!("Failed to register peer URL: {err}");
161+
error!("Failed to register peer URL: {err:?}");
162162
}
163163

164164
// Build HttpsClientConfig for mTLS communication
@@ -185,7 +185,7 @@ impl ProxyInner {
185185
)
186186
.await
187187
{
188-
warn!("Failed to fetch peers from bootnode: {err}");
188+
warn!("Failed to fetch peers from bootnode: {err:?}");
189189
}
190190
}
191191

@@ -194,7 +194,7 @@ impl ProxyInner {
194194
match WaveKvSyncService::new(&kv_store, &config.sync, https_config.clone()) {
195195
Ok(sync_service) => Some(Arc::new(sync_service)),
196196
Err(err) => {
197-
error!("Failed to create WaveKV sync service: {err}");
197+
error!("Failed to create WaveKV sync service: {err:?}");
198198
None
199199
}
200200
}
@@ -212,7 +212,7 @@ impl ProxyInner {
212212
if let Some(ref wavekv_sync) = wavekv_sync {
213213
info!("WaveKV: bootstrapping from peers...");
214214
if let Err(err) = wavekv_sync.bootstrap().await {
215-
warn!("WaveKV bootstrap failed: {err}");
215+
warn!("WaveKV bootstrap failed: {err:?}");
216216
}
217217
}
218218

@@ -223,7 +223,7 @@ impl ProxyInner {
223223
let mut builder = CertStoreBuilder::new();
224224
for (domain, data) in &all_cert_data {
225225
if let Err(err) = builder.add_cert(domain, data) {
226-
warn!("failed to load certificate for {}: {}", domain, err);
226+
warn!("failed to load certificate for {domain}: {err:?}");
227227
}
228228
}
229229
cert_resolver.set(Arc::new(builder.build()));
@@ -240,7 +240,7 @@ impl ProxyInner {
240240
));
241241
// Initialize any configured domains
242242
if let Err(err) = certbot.init_all().await {
243-
warn!("Failed to initialize multi-domain certbot: {}", err);
243+
warn!("Failed to initialize multi-domain certbot: {err:?}");
244244
}
245245

246246
// Create TLS acceptors with CertResolver for SNI-based resolution
@@ -305,15 +305,15 @@ impl Proxy {
305305
let mut loaded = 0;
306306
for (domain, data) in &all_cert_data {
307307
if let Err(err) = builder.add_cert(domain, data) {
308-
warn!("failed to reload certificate for {}: {}", domain, err);
308+
warn!("failed to reload certificate for {domain}: {err:?}");
309309
} else {
310310
loaded += 1;
311311
}
312312
}
313313

314314
// Atomically replace the CertStore (no need to recreate acceptors)
315315
self.cert_resolver.set(Arc::new(builder.build()));
316-
info!("CertStore: reloaded {} certificates from KvStore", loaded);
316+
info!("CertStore: reloaded {loaded} certificates from KvStore");
317317
Ok(())
318318
}
319319

@@ -405,7 +405,7 @@ impl Proxy {
405405
.new_client_by_id(instance_id, app_id, client_public_key)
406406
.context("failed to allocate IP address for client")?;
407407
if let Err(err) = state.reconfigure() {
408-
error!("failed to reconfigure: {}", err);
408+
error!("failed to reconfigure: {err:?}");
409409
}
410410
let gateways = state.get_active_nodes();
411411
let servers = gateways
@@ -470,7 +470,7 @@ fn start_recycle_thread(proxy: Proxy) {
470470
std::thread::spawn(move || loop {
471471
std::thread::sleep(proxy.config.recycle.interval);
472472
if let Err(err) = proxy.lock().recycle() {
473-
error!("failed to run recycle: {err}");
473+
error!("failed to run recycle: {err:?}");
474474
};
475475
});
476476
}
@@ -484,7 +484,7 @@ async fn start_certbot_task(proxy: Proxy) {
484484
// Run once at startup to check for any pending renewals
485485
info!("running initial certificate renewal check");
486486
if let Err(err) = proxy.renew_cert(None, false).await {
487-
error!("failed initial certificate renewal: {err}");
487+
error!("failed initial certificate renewal: {err:?}");
488488
}
489489

490490
loop {
@@ -501,7 +501,7 @@ async fn start_certbot_task(proxy: Proxy) {
501501

502502
// Renew certificates
503503
if let Err(err) = proxy.renew_cert(None, false).await {
504-
error!("failed to renew certificates: {err}");
504+
error!("failed to renew certificates: {err:?}");
505505
}
506506
}
507507
});
@@ -520,7 +520,7 @@ fn start_cert_store_watch_task(proxy: Proxy) {
520520
}
521521
info!("WaveKV: detected certificate changes, reloading CertStore...");
522522
if let Err(err) = proxy.reload_all_certs_from_kvstore() {
523-
error!("Failed to reload certificates from KvStore: {err}");
523+
error!("Failed to reload certificates from KvStore: {err:?}");
524524
}
525525
}
526526
});
@@ -577,7 +577,7 @@ fn start_zt_domain_watch_task(proxy: Proxy) {
577577
}
578578
}
579579
Err(e) => {
580-
warn!("cert[{domain}]: auto-renewal failed: {e}");
580+
warn!("cert[{domain}]: auto-renewal failed: {e:?}");
581581
}
582582
}
583583
});
@@ -620,7 +620,7 @@ fn start_bootnode_discovery_task(proxy: Proxy) {
620620
if let Err(err) =
621621
fetch_peers_from_bootnode(&bootnode, &kv_store, node_id, &https_config).await
622622
{
623-
debug!("bootnode discovery retry failed: {err}");
623+
warn!("bootnode discovery retry failed: {err:?}");
624624
} else {
625625
info!("bootnode peer discovery succeeded");
626626
}
@@ -662,7 +662,7 @@ fn start_wavekv_watch_task(proxy: Proxy) -> Result<()> {
662662
}
663663
info!("WaveKV: detected remote instance changes, reloading...");
664664
if let Err(err) = reload_instances_from_kv_store(&proxy_clone, &store_clone) {
665-
error!("Failed to reload instances from KvStore: {err}");
665+
error!("Failed to reload instances from KvStore: {err:?}");
666666
}
667667
}
668668
});
@@ -680,7 +680,7 @@ fn start_wavekv_watch_task(proxy: Proxy) -> Result<()> {
680680
}
681681
info!("WaveKV: detected remote node changes, reconfiguring WireGuard...");
682682
if let Err(err) = proxy_for_nodes.lock().reconfigure() {
683-
error!("Failed to reconfigure WireGuard: {err}");
683+
error!("Failed to reconfigure WireGuard: {err:?}");
684684
}
685685
}
686686
});
@@ -696,7 +696,7 @@ fn start_wavekv_watch_task(proxy: Proxy) -> Result<()> {
696696
match kv_store_for_persist.persist_if_dirty() {
697697
Ok(true) => info!("WaveKV: periodic persist completed"),
698698
Ok(false) => {} // No changes to persist
699-
Err(err) => error!("WaveKV: periodic persist failed: {err}"),
699+
Err(err) => error!("WaveKV: periodic persist failed: {err:?}"),
700700
}
701701
}
702702
});
@@ -830,7 +830,7 @@ impl ProxyState {
830830
reg_time: encode_ts(existing.reg_time),
831831
};
832832
if let Err(err) = self.kv_store.sync_instance(&existing.id, &data) {
833-
error!("failed to sync existing instance to KvStore: {err}");
833+
error!("failed to sync existing instance to KvStore: {err:?}");
834834
}
835835
return Some(existing);
836836
}
@@ -859,7 +859,7 @@ impl ProxyState {
859859
reg_time: encode_ts(info.reg_time),
860860
};
861861
if let Err(err) = self.kv_store.sync_instance(&info.id, &data) {
862-
error!("failed to sync instance to KvStore: {err}");
862+
error!("failed to sync instance to KvStore: {err:?}");
863863
}
864864

865865
self.state
@@ -888,7 +888,7 @@ impl ProxyState {
888888

889889
match cmd!(wg syncconf $ifname $config_path) {
890890
Ok(_) => info!("wg config updated"),
891-
Err(e) => error!("failed to set wg config: {e}"),
891+
Err(err) => error!("failed to set wg config: {err:?}"),
892892
}
893893
Ok(())
894894
}
@@ -924,7 +924,7 @@ impl ProxyState {
924924
let handshakes = self.latest_handshakes(None);
925925
let mut instances = match handshakes {
926926
Err(err) => {
927-
warn!("Failed to get handshakes, fallback to random selection: {err}");
927+
warn!("Failed to get handshakes, fallback to random selection: {err:?}");
928928
return Ok(self.random_select_a_host(id).unwrap_or_default());
929929
}
930930
Ok(handshakes) => app_instances
@@ -1039,7 +1039,7 @@ impl ProxyState {
10391039

10401040
// Sync deletion to KvStore
10411041
if let Err(err) = self.kv_store.sync_delete_instance(id) {
1042-
error!("Failed to sync instance deletion to KvStore: {err}");
1042+
error!("Failed to sync instance deletion to KvStore: {err:?}");
10431043
}
10441044

10451045
self.state.allocated_addresses.remove(&info.ip);
@@ -1055,7 +1055,7 @@ impl ProxyState {
10551055
fn recycle(&mut self) -> Result<()> {
10561056
// Refresh state: sync local handshakes to KvStore, update local last_seen from global
10571057
if let Err(err) = self.refresh_state() {
1058-
warn!("failed to refresh state: {err}");
1058+
warn!("failed to refresh state: {err:?}");
10591059
}
10601060

10611061
// Note: Gateway nodes are not removed from KvStore, only marked offline/retired
@@ -1122,7 +1122,7 @@ impl ProxyState {
11221122
for (pk, (ts, _)) in &handshakes {
11231123
if let Some(&instance_id) = pk_to_id.get(pk.as_str()) {
11241124
if let Err(err) = self.kv_store.sync_instance_handshake(instance_id, *ts) {
1125-
debug!("failed to sync instance handshake: {err}");
1125+
debug!("failed to sync instance handshake: {err:?}");
11261126
}
11271127
}
11281128
}
@@ -1136,15 +1136,15 @@ impl ProxyState {
11361136
.kv_store
11371137
.sync_node_last_seen(self.config.sync.node_id, now)
11381138
{
1139-
debug!("failed to sync node last_seen: {err}");
1139+
debug!("failed to sync node last_seen: {err:?}");
11401140
}
11411141
Ok(())
11421142
}
11431143

11441144
/// Sync connection count for an instance to KvStore
11451145
pub(crate) fn sync_connections(&self, instance_id: &str, count: u64) {
11461146
if let Err(err) = self.kv_store.sync_connections(instance_id, count) {
1147-
debug!("Failed to sync connections: {err}");
1147+
debug!("Failed to sync connections: {err:?}");
11481148
}
11491149
}
11501150

0 commit comments

Comments
 (0)