Skip to content

Commit 26350df

Browse files
authored
Added a bash script to check the log format. (#4150)
1 parent 7a29318 commit 26350df

File tree

58 files changed

+164
-132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+164
-132
lines changed

CODE_STYLE.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,26 @@ These assert will not be part of the release binary and won't hurt the execution
109109

110110
**example needed**
111111

112-
## Errors
112+
## Errors and log messages
113113

114-
Error messages should be concise, lowercase (except proper names), and without trailing punctuation.
114+
Error and log messages follow the same format. They should be concise, lowercase (except proper names), and without trailing punctuation.
115115

116-
### Examples
116+
As a loose rule, where it does not hurt readability, log messages should rely on `tracing`
117+
structured logging instead of templating.
118+
119+
In other words, prefer:
120+
`warn!(remaining=remaining_attempts, "trubulizor rpc plane retry failed")`
121+
to
122+
`warn!("trubulizor rpc plane retry failed ({remaining_attempts} attempts remaining)")`
123+
124+
### Error Examples
117125
- "failed to start actor runtimes"
118126
- "cannot join PostgreSQL URI {} with path {:?}"
119127
- "could not find split metadata in Metastore {}"
120-
- "unkown output format {:?}"
128+
- "unknown output format {:?}"
129+
130+
### Log examples
131+
121132

122133
## Comments
123134

quickwit/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ fmt:
66
@(rustup toolchain list | ( ! grep -q nightly && echo "Toolchain 'nightly' is not installed. Please install using 'rustup toolchain install nightly'.") ) || cargo +nightly fmt
77
@echo "Checking license headers"
88
@bash scripts/check_license_headers.sh
9+
@echo "Checking log format"
10+
@bash scripts/check_log_format.sh
911

1012
fix:
1113
@echo "Running cargo clippy --fix"

quickwit/quickwit-actors/src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ pub use observation::{Observation, ObservationType};
6060
use quickwit_common::KillSwitch;
6161
pub use spawn_builder::SpawnContext;
6262
use thiserror::Error;
63-
use tracing::info;
64-
use tracing::log::warn;
63+
use tracing::{info, warn};
6564
pub use universe::Universe;
6665

6766
pub use self::actor_context::ActorContext;
@@ -93,19 +92,19 @@ fn heartbeat_from_env_or_default() -> Duration {
9392
match std::env::var("QW_ACTOR_HEARTBEAT_SECS") {
9493
Ok(actor_hearbeat_secs_str) => {
9594
if let Ok(actor_hearbeat_secs) = actor_hearbeat_secs_str.parse::<NonZeroU64>() {
96-
info!("Set the actor heartbeat to {actor_hearbeat_secs} seconds.");
95+
info!("set the actor heartbeat to {actor_hearbeat_secs} seconds");
9796
return Duration::from_secs(actor_hearbeat_secs.get());
9897
} else {
9998
warn!(
100-
"Failed to parse `QW_ACTOR_HEARTBEAT_SECS={actor_hearbeat_secs_str}` in \
101-
seconds > 0, using default heartbeat (30 seconds)."
99+
"failed to parse `QW_ACTOR_HEARTBEAT_SECS={actor_hearbeat_secs_str}` in \
100+
seconds > 0, using default heartbeat (30 seconds)"
102101
);
103102
};
104103
}
105104
Err(std::env::VarError::NotUnicode(os_str)) => {
106105
warn!(
107-
"Failed to parse `QW_ACTOR_HEARTBEAT_SECS={os_str:?}` in a valid unicode string, \
108-
using default heartbeat (30 seconds)."
106+
"failed to parse `QW_ACTOR_HEARTBEAT_SECS={os_str:?}` in a valid unicode string, \
107+
using default heartbeat (30 seconds)"
109108
);
110109
}
111110
Err(std::env::VarError::NotPresent) => {}

quickwit/quickwit-cli/src/jemalloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub async fn jemalloc_metrics_loop() -> tikv_jemalloc_ctl::Result<()> {
5959
pub fn start_jemalloc_metrics_loop() {
6060
tokio::task::spawn(async {
6161
if let Err(jemalloc_metrics_err) = jemalloc_metrics_loop().await {
62-
error!(err=?jemalloc_metrics_err, "Failed to gather metrics from jemalloc.");
62+
error!(err=?jemalloc_metrics_err, "failed to gather metrics from jemalloc");
6363
}
6464
});
6565
}

quickwit/quickwit-cli/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ async fn load_node_config(config_uri: &Uri) -> anyhow::Result<NodeConfig> {
222222
let config = NodeConfig::load(config_format, config_content.as_slice())
223223
.await
224224
.with_context(|| format!("failed to parse node config `{config_uri}`"))?;
225-
info!(config_uri=%config_uri, config=?config, "Loaded node config.");
225+
info!(config_uri=%config_uri, config=?config, "loaded node config");
226226
Ok(config)
227227
}
228228

@@ -402,10 +402,10 @@ pub mod busy_detector {
402402

403403
let suppressed = SUPPRESSED_DEBUG_COUNT.swap(0, Ordering::Relaxed);
404404
if suppressed == 0 {
405-
debug!("Thread wasn't parked for {delta}µs, is the runtime too busy?");
405+
debug!("thread wasn't parked for {delta}µs, is the runtime too busy?");
406406
} else {
407407
debug!(
408-
"Thread wasn't parked for {delta}µs, is the runtime too busy? ({suppressed} \
408+
"thread wasn't parked for {delta}µs, is the runtime too busy? ({suppressed} \
409409
similar messages suppressed)"
410410
);
411411
}

quickwit/quickwit-cli/src/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl RunCliCommand {
8181
crate::busy_detector::set_enabled(true);
8282

8383
if let Some(services) = &self.services {
84-
tracing::info!(services = %services.iter().join(", "), "Setting services from override.");
84+
tracing::info!(services = %services.iter().join(", "), "setting services from override");
8585
node_config.enabled_services = services.clone();
8686
}
8787
let telemetry_handle_opt =

quickwit/quickwit-cli/src/tool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,12 +630,12 @@ pub async fn merge_cli(args: MergeArgs) -> anyhow::Result<()> {
630630
let observation = pipeline_handle.last_observation();
631631

632632
if observation.num_ongoing_merges == 0 {
633-
info!("Merge pipeline has no more ongoing merges, Exiting.");
633+
info!("merge pipeline has no more ongoing merges, exiting");
634634
break;
635635
}
636636

637637
if pipeline_handle.state().is_exit() {
638-
info!("Merge pipeline has exited, Exiting.");
638+
info!("merge pipeline has exited, exiting");
639639
break;
640640
}
641641
}

quickwit/quickwit-cli/tests/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl TestEnv {
158158
};
159159
tokio::spawn(async move {
160160
if let Err(error) = run_command.execute().await {
161-
error!(err=?error, "Failed to start a quickwit server.");
161+
error!(err=?error, "failed to start a quickwit server");
162162
}
163163
});
164164
wait_for_server_ready(([127, 0, 0, 1], self.rest_listen_port).into()).await?;

quickwit/quickwit-cluster/src/member.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn parse_indexing_cpu_capacity(node_state: &NodeState) -> CpuCapacity {
122122
if let Ok(indexing_capacity) = CpuCapacity::from_str(indexing_capacity_str) {
123123
indexing_capacity
124124
} else {
125-
error!(indexing_capacity=?indexing_capacity_str, "Received an unparseable indexing capacity from node.");
125+
error!(indexing_capacity=?indexing_capacity_str, "received an unparseable indexing capacity from node");
126126
CpuCapacity::zero()
127127
}
128128
}

quickwit/quickwit-common/src/runtimes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl RuntimeType {
120120
.get_or_init(|| {
121121
#[cfg(any(test, feature = "testsuite"))]
122122
{
123-
tracing::warn!("Starting Tokio actor runtimes for tests.");
123+
tracing::warn!("starting Tokio actor runtimes for tests");
124124
start_runtimes(RuntimesConfig::light_for_tests())
125125
}
126126
#[cfg(not(any(test, feature = "testsuite")))]

0 commit comments

Comments
 (0)