Skip to content

Commit 4ddc8fd

Browse files
authored
Don't include worker_id in the service name in worker log (#1110)
1 parent 235ccf8 commit 4ddc8fd

4 files changed

Lines changed: 20 additions & 13 deletions

File tree

crates/arroyo-server-common/src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ pub const VERSION: &str = "0.16.0-dev";
5454

5555
static CLUSTER_ID: OnceCell<String> = OnceCell::new();
5656

57-
pub fn init_logging(name: &str) -> Option<WorkerGuard> {
57+
pub fn init_logging(name: &str, tags: &[(&str, &str)]) -> Option<WorkerGuard> {
5858
init_logging_with_filter(
5959
name,
60+
tags,
6061
EnvFilter::builder()
6162
.with_default_directive(LevelFilter::INFO.into())
6263
.from_env_lossy(),
@@ -80,7 +81,11 @@ macro_rules! register_log {
8081
}};
8182
}
8283

83-
pub fn init_logging_with_filter(name: &str, filter: EnvFilter) -> Option<WorkerGuard> {
84+
pub fn init_logging_with_filter(
85+
name: &str,
86+
tags: &[(&str, &str)],
87+
filter: EnvFilter,
88+
) -> Option<WorkerGuard> {
8489
init_event_logger(Arc::new(AnalyticsEventLogger::new()));
8590

8691
if let Err(e) = LogTracer::init() {
@@ -144,6 +149,10 @@ pub fn init_logging_with_filter(name: &str, filter: EnvFilter) -> Option<WorkerG
144149
layer.add_static_field("pipeline_id", serde_json::json!(pipeline_id));
145150
}
146151

152+
for (k, v) in tags {
153+
layer.add_static_field(*k, json!(*v));
154+
}
155+
147156
// add static fields
148157
for (key, value) in &config().logging.static_fields {
149158
layer.add_static_field(key, serde_json::json!(value));

crates/arroyo-worker/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use tokio::select;
4141
use tokio::sync::mpsc::{Receiver, Sender, channel};
4242
use tokio_stream::wrappers::TcpListenerStream;
4343
use tonic::{Request, Response, Status};
44-
use tracing::{debug, error, info, warn};
44+
use tracing::{debug, error, info, trace, warn};
4545

4646
use crate::job_controller::controller::WorkerJobController;
4747
use crate::utils::{MAX_TASK_ERROR_FIELD_BYTES, maybe_truncate, to_d2};
@@ -1349,7 +1349,7 @@ impl JobControllerGrpc for LeaderServer {
13491349

13501350
self.validate_req(req.worker_context.as_ref())?;
13511351

1352-
debug!(
1352+
trace!(
13531353
worker_id =? self.state.worker_context.worker_id,
13541354
?req,
13551355
"received heartbeat",

crates/arroyo/src/main.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ where
377377
}
378378

379379
async fn migrate(wait: Option<u32>) -> anyhow::Result<()> {
380-
let _guard = arroyo_server_common::init_logging("migrate");
380+
let _guard = arroyo_server_common::init_logging("migrate", &[]);
381381

382382
let mut client = if let Some(wait) = wait {
383383
info!("Waiting for database to be ready to run migrations");
@@ -443,7 +443,7 @@ async fn migrate(wait: Option<u32>) -> anyhow::Result<()> {
443443
}
444444

445445
async fn start_control_plane(service: CPService) {
446-
let _guard = arroyo_server_common::init_logging(service.name());
446+
let _guard = arroyo_server_common::init_logging(service.name(), &[]);
447447

448448
let config = config::config();
449449

@@ -494,11 +494,8 @@ async fn start_worker() {
494494
let server =
495495
WorkerServer::from_config(shutdown.guard("worker")).expect("Could not start worker");
496496

497-
let _guard = arroyo_server_common::init_logging(&format!(
498-
"worker-{}-{}",
499-
server.id().0,
500-
server.job_id()
501-
));
497+
let _guard =
498+
arroyo_server_common::init_logging("worker", &[("worker_id", &server.id().to_string())]);
502499

503500
shutdown.spawn_task("admin", start_admin_server("worker"));
504501
let token = shutdown.token();
@@ -516,15 +513,15 @@ async fn start_node() {
516513
let shutdown = Shutdown::new("node", SignalBehavior::Handle);
517514
let id = arroyo_node::start_server(shutdown.guard("node")).await;
518515

519-
let _guard = arroyo_server_common::init_logging(&format!("node-{}", id.0,));
516+
let _guard = arroyo_server_common::init_logging("node", &[("node_id", &id)]);
520517

521518
shutdown.spawn_task("admin", start_admin_server("worker"));
522519

523520
Shutdown::handle_shutdown(shutdown.wait_for_shutdown(Duration::from_secs(30)).await);
524521
}
525522

526523
async fn visualize(query: Input, open: bool) {
527-
let _guard = arroyo_server_common::init_logging("visualize");
524+
let _guard = arroyo_server_common::init_logging("visualize", &[]);
528525

529526
let query = std::io::read_to_string(query).expect("Failed to read query");
530527

crates/arroyo/src/run.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ pub(crate) fn add_client_auth_headers(mut client_builder: ClientBuilder) -> Clie
400400
pub async fn run(args: RunArgs) {
401401
let _guard = arroyo_server_common::init_logging_with_filter(
402402
"pipeline",
403+
&[],
403404
if env::var("RUST_LOG").is_err() {
404405
unsafe { set_var("RUST_LOG", "WARN") };
405406
EnvFilter::builder()

0 commit comments

Comments
 (0)