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

feat: show thread name in logs for playground and standalone #14114

Merged
merged 6 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public class TracingSlf4jImpl {
public static final int TRACE = 4;

public static void event(String name, int level, String message) {
Binding.tracingSlf4jEvent(name, level, message);
Binding.tracingSlf4jEvent(Thread.currentThread().getName(), name, level, message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class Binding {
}
}

public static native void tracingSlf4jEvent(String name, int level, String message);
public static native void tracingSlf4jEvent(
String threadName, String name, int level, String message);

public static native int vnodeCount();

Expand Down
2 changes: 1 addition & 1 deletion src/batch/src/task/task_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl BatchManager {
builder.worker_threads(worker_threads_num);
}
builder
.thread_name("risingwave-batch-tasks")
.thread_name("rw-batch")
.enable_all()
.build()
.unwrap()
Expand Down
6 changes: 4 additions & 2 deletions src/cmd_all/src/bin/risingwave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,16 @@ fn main() -> Result<()> {

fn playground(opts: PlaygroundOpts) {
let settings = risingwave_rt::LoggerSettings::new("playground")
.with_target("risingwave_storage", Level::WARN);
.with_target("risingwave_storage", Level::WARN)
.with_thread_name(true);
risingwave_rt::init_risingwave_logger(settings);
risingwave_rt::main_okk(risingwave_cmd_all::playground(opts)).unwrap();
}

fn standalone(opts: StandaloneOpts) {
let settings = risingwave_rt::LoggerSettings::new("standalone")
.with_target("risingwave_storage", Level::WARN);
.with_target("risingwave_storage", Level::WARN)
.with_thread_name(true);
risingwave_rt::init_risingwave_logger(settings);
risingwave_rt::main_okk(risingwave_cmd_all::standalone(opts)).unwrap();
}
2 changes: 1 addition & 1 deletion src/connector/src/source/data_gen_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn spawn_data_generation_stream<T: Send + 'static>(
) -> impl Stream<Item = T> + Send + 'static {
static RUNTIME: LazyLock<Runtime> = LazyLock::new(|| {
tokio::runtime::Builder::new_multi_thread()
.thread_name("risingwave-data-generation")
.thread_name("rw-datagen")
.enable_all()
.build()
.expect("failed to build data-generation runtime")
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ impl FrontendEnv {
Arc::new(BackgroundShutdownRuntime::from(
Builder::new_multi_thread()
.worker_threads(4)
.thread_name("frontend-compute-threads")
.thread_name("rw-batch-local")
.enable_all()
.build()
.unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions src/jni_core/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ macro_rules! for_all_plain_native_methods {
($macro:path $(,$args:tt)*) => {
$macro! {
{
public static native void tracingSlf4jEvent(String name, int level, String string);
public static native void tracingSlf4jEvent(String threadName, String name, int level, String string);

public static native int vnodeCount();

Expand Down Expand Up @@ -882,7 +882,7 @@ mod tests {
// This test shows the signature of all native methods
let expected = expect_test::expect![[r#"
[
tracingSlf4jEvent (Ljava/lang/String;ILjava/lang/String;)V,
tracingSlf4jEvent (Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)V,
vnodeCount ()I,
iteratorNewHummock ([B)J,
iteratorNewStreamChunk (J)J,
Expand Down
7 changes: 6 additions & 1 deletion src/jni_core/src/tracing_slf4j.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ use crate::{execute_and_catch, EnvParam};
#[no_mangle]
pub(crate) extern "system" fn Java_com_risingwave_java_binding_Binding_tracingSlf4jEvent(
env: EnvParam<'_>,
thread_name: JString<'_>,
class_name: JString<'_>,
level: jint,
message: JString<'_>,
) {
execute_and_catch(env, move |env| {
let thread_name = env.get_string(&thread_name)?;
let thread_name: Cow<'_, str> = (&thread_name).into();

let class_name = env.get_string(&class_name)?;
let class_name: Cow<'_, str> = (&class_name).into();

Expand All @@ -39,7 +43,8 @@ pub(crate) extern "system" fn Java_com_risingwave_java_binding_Binding_tracingSl
tracing::event!(
target: "risingwave_connector_node",
$lvl,
class = class_name.as_ref(),
thread = &*thread_name,
class = &*class_name,
"{message}",
)
};
Expand Down
2 changes: 1 addition & 1 deletion src/storage/src/hummock/compactor/compaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl CompactionExecutor {
let mut worker_num = resource_util::cpu::total_cpu_available() as usize;
let runtime = {
let mut builder = tokio::runtime::Builder::new_multi_thread();
builder.thread_name("risingwave-compaction");
builder.thread_name("rw-compaction");
if let Some(worker_threads_num) = worker_threads_num {
builder.worker_threads(worker_threads_num);
worker_num = worker_threads_num;
Expand Down
2 changes: 1 addition & 1 deletion src/stream/src/task/stream_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ impl LocalStreamManagerCore {
builder.worker_threads(worker_threads_num);
}
builder
.thread_name("risingwave-streaming-actor")
.thread_name("rw-streaming")
.enable_all()
.build()
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion src/utils/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ where
}

tokio::runtime::Builder::new_multi_thread()
.thread_name("risingwave-main")
.thread_name("rw-main")
.enable_all()
.build()
.unwrap()
Expand Down
12 changes: 11 additions & 1 deletion src/utils/runtime/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub struct LoggerSettings {
colorful: bool,
/// Output to `stderr` instead of `stdout`.
stderr: bool,
/// Whether to include thread name in the log.
with_thread_name: bool,
/// Override target settings.
targets: Vec<(String, tracing::metadata::LevelFilter)>,
/// Override the default level.
Expand All @@ -57,6 +59,7 @@ impl LoggerSettings {
enable_tokio_console: false,
colorful: console::colors_enabled_stderr() && console::colors_enabled(),
stderr: false,
with_thread_name: false,
targets: vec![],
default_level: None,
}
Expand All @@ -74,6 +77,12 @@ impl LoggerSettings {
self
}

/// Whether to include thread name in the log.
pub fn with_thread_name(mut self, enabled: bool) -> Self {
self.with_thread_name = enabled;
self
}

/// Overrides the default target settings.
pub fn with_target(
mut self,
Expand Down Expand Up @@ -210,6 +219,7 @@ pub fn init_risingwave_logger(settings: LoggerSettings) {
// fmt layer (formatting and logging to `stdout` or `stderr`)
{
let fmt_layer = tracing_subscriber::fmt::layer()
.with_thread_names(settings.with_thread_name)
.with_timer(default_timer.clone())
.with_ansi(settings.colorful)
.with_writer(move || {
Expand Down Expand Up @@ -359,7 +369,7 @@ pub fn init_risingwave_logger(settings: LoggerSettings) {
let otel_tracer = {
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.thread_name("risingwave-otel")
.thread_name("rw-otel")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does otel mean?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the abbreviation of opentelemetry.

.worker_threads(2)
.build()
.unwrap();
Expand Down
Loading