fix: use full hostname as worker ping hostname and add it in other contexts

This commit is contained in:
Ruben Fiszel
2024-06-05 11:28:45 +02:00
parent d02430a2e0
commit ebf37eb16b
2 changed files with 22 additions and 18 deletions
+12 -10
View File
@@ -675,17 +675,18 @@ pub async fn run_workers<R: rsmq_async::RsmqConnection + Send + Sync + Clone + '
tracing::info!("Received killpill, exiting");
return Ok(());
}
let instance_name = gethostname()
let hostname = gethostname()
.to_str()
.map(|x| {
x.replace(" ", "")
.split("-")
.last()
.unwrap()
.to_ascii_lowercase()
.to_string()
})
.map(|x| x.to_string())
.unwrap_or_else(|| rd_string(5));
let instance_name = hostname
.clone()
.replace(" ", "")
.split("-")
.last()
.unwrap()
.to_ascii_lowercase()
.to_string();
// #[cfg(tokio_unstable)]
// let monitor = tokio_metrics::TaskMonitor::new();
@@ -729,13 +730,14 @@ pub async fn run_workers<R: rsmq_async::RsmqConnection + Send + Sync + Clone + '
let tx = tx.clone();
let base_internal_url = base_internal_url.clone();
let rsmq2 = rsmq.clone();
let hostname = hostname.clone();
handles.push(tokio::spawn(async move {
tracing::info!(worker = %worker_name, "starting worker");
let f = windmill_worker::run_worker(
&db1,
&instance_name,
&hostname,
worker_name,
i as u64,
num_workers as u32,
+10 -8
View File
@@ -687,10 +687,10 @@ fn add_outstanding_wait_time(
}.in_current_span());
}
#[tracing::instrument(name = "worker", level = "info", skip_all, fields(worker = %worker_name))]
#[tracing::instrument(name = "worker", level = "info", skip_all, fields(worker = %worker_name, hostname = %hostname))]
pub async fn run_worker<R: rsmq_async::RsmqConnection + Send + Sync + Clone + 'static>(
db: &Pool<Postgres>,
worker_instance: &str,
hostname: &str,
worker_name: String,
i_worker: u64,
_num_workers: u32,
@@ -735,7 +735,7 @@ pub async fn run_worker<R: rsmq_async::RsmqConnection + Send + Sync + Clone + 's
let mut last_ping = Instant::now() - Duration::from_secs(NUM_SECS_PING + 1);
update_ping(worker_instance, &worker_name, ip, db).await;
update_ping(hostname, &worker_name, ip, db).await;
#[cfg(feature = "prometheus")]
let uptime_metric = if METRICS_ENABLED.load(Ordering::Relaxed) {
@@ -1504,9 +1504,9 @@ pub async fn run_worker<R: rsmq_async::RsmqConnection + Send + Sync + Clone + 's
killpill_tx.send(()).unwrap_or_default();
}
tracing::info!(
"ping update and worker memory snapshot {}kB/{}kB",
memory_usage.unwrap_or_default() / 1024,
wm_memory_usage.unwrap_or_default() / 1024
"ping update, memory: container={}MB, windmill={}MB",
memory_usage.unwrap_or_default() / (1024 * 1024),
wm_memory_usage.unwrap_or_default() / (1024 * 1024)
);
last_ping = Instant::now();
@@ -1805,6 +1805,7 @@ pub async fn run_worker<R: rsmq_async::RsmqConnection + Send + Sync + Clone + 's
arc_job.clone(),
db,
&authed_client,
&hostname,
&worker_name,
&worker_dir,
&job_dir,
@@ -2721,6 +2722,7 @@ async fn handle_queued_job<R: rsmq_async::RsmqConnection + Send + Sync + Clone>(
job: Arc<QueuedJob>,
db: &DB,
client: &AuthedClientBackgroundTask,
hostname: &str,
worker_name: &str,
worker_dir: &str,
job_dir: &str,
@@ -2870,8 +2872,8 @@ async fn handle_queued_job<R: rsmq_async::RsmqConnection + Send + Sync + Clone>(
// println!("handle queue {:?}", SystemTime::now());
logs.push_str(&format!(
"job {} on worker {} (tag: {})\n",
&job.id, &worker_name, &job.tag
"job={} tag={} worker={} hostname={}\n",
&job.id, &job.tag, &worker_name, &hostname
));
if *NO_LOGS_AT_ALL {