-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for changing
tracing
directives at runtime (#3565)
* Add handler to update tracing filter * Add documentation for 'hermes logs' commands * Add documentation regarding ZMQ interaction in guide * Add comments * Rename 'logs' subcommands * Remove unnecessary error * Fix config example * Use TCP client/server instead of ZMQ * Cleanup * Only start tracing server for `start` command * Show message returned by server when setting log level * Fix for server hanging * Add changelog entry --------- Co-authored-by: Romain Ruetschi <[email protected]>
- Loading branch information
Showing
25 changed files
with
440 additions
and
6 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
.changelog/unreleased/features/ibc-relayer-cli/3564-tracing-filter.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- Add support for changing `tracing` directives at runtime. | ||
Please see the [corresponding page in the Hermes guide][tracing-guide] for more information. | ||
([\#3564](https://github.com/informalsystems/hermes/issues/3564)) | ||
|
||
[tracing-guide]: https://hermes.informal.systems/advanced/troubleshooting/log-level.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use abscissa_core::clap::Parser; | ||
use abscissa_core::Command; | ||
use abscissa_core::Runnable; | ||
|
||
pub mod log_level; | ||
pub mod raw; | ||
pub mod reset; | ||
|
||
/// `logs` subcommand | ||
#[derive(Command, Debug, Parser, Runnable)] | ||
pub enum LogsCmd { | ||
/// Subcommand used to easily update the lowest log level displayed | ||
SetLogLevel(log_level::SetLogLevelCmd), | ||
|
||
/// Subcommand used to send a raw filter directive for logs displayed | ||
SetRawFilter(raw::SetRawFilterCmd), | ||
|
||
/// Subcommand to restore the log level by using the configuration defined in the config.toml file | ||
Reset(reset::ResetCmd), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use abscissa_core::clap::Parser; | ||
use abscissa_core::Command; | ||
use abscissa_core::Runnable; | ||
use tracing::info; | ||
use tracing::Level; | ||
|
||
use crate::prelude::app_config; | ||
use crate::tracing_handle::send_command; | ||
|
||
#[derive(Clone, Command, Debug, Parser, PartialEq, Eq)] | ||
pub struct SetLogLevelCmd { | ||
#[clap( | ||
long = "log-level", | ||
required = true, | ||
value_name = "LOG_LEVEL", | ||
help = "The new lowest log level which will be displayed. Possible values are `trace`, `debug`, `info`, `warn` or `error`" | ||
)] | ||
log_level: Level, | ||
|
||
#[clap( | ||
long = "log-filter", | ||
help_heading = "FLAGS", | ||
value_name = "LOG_FILTER", | ||
help = "The target of the log level to update, if left empty all the targets will be updated. Example `ibc` or `tendermint_rpc`" | ||
)] | ||
log_filter: Option<String>, | ||
} | ||
|
||
impl Runnable for SetLogLevelCmd { | ||
fn run(&self) { | ||
let rt = tokio::runtime::Builder::new_current_thread() | ||
.enable_all() | ||
.build() | ||
.unwrap(); | ||
|
||
rt.block_on(run(&self.log_level, self.log_filter.as_ref())); | ||
} | ||
} | ||
|
||
async fn run(log_level: &Level, log_filter: Option<&String>) { | ||
let config = app_config(); | ||
|
||
let port = config.tracing_server.port; | ||
|
||
let str_log = log_level.to_string(); | ||
|
||
let result = if let Some(log_filter) = log_filter { | ||
let log_cmd = format!("{log_filter}={str_log}"); | ||
info!("Setting log level to: {log_cmd}"); | ||
send_command(&log_cmd, port).await | ||
} else { | ||
info!("Setting log level to: {str_log}"); | ||
send_command(&str_log, port).await | ||
}; | ||
|
||
match result { | ||
Ok(msg) => info!("{msg}"), | ||
Err(e) => info!("Failed to set log level: {e}"), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use abscissa_core::clap::Parser; | ||
use abscissa_core::Command; | ||
use abscissa_core::Runnable; | ||
use tracing::error; | ||
use tracing::info; | ||
|
||
use crate::prelude::app_config; | ||
use crate::tracing_handle::send_command; | ||
|
||
// TODO `hermes set-raw-filter` | ||
#[derive(Clone, Command, Debug, Parser, PartialEq, Eq)] | ||
pub struct SetRawFilterCmd { | ||
#[clap( | ||
long = "raw-filter", | ||
required = true, | ||
value_name = "RAW_FILTER", | ||
help = "Raw filter used as new tracing directive. Use with caution" | ||
)] | ||
raw_filter: String, | ||
} | ||
|
||
impl Runnable for SetRawFilterCmd { | ||
fn run(&self) { | ||
let config = app_config(); | ||
|
||
let rt = tokio::runtime::Builder::new_current_thread() | ||
.enable_all() | ||
.build() | ||
.unwrap(); | ||
|
||
let port = config.tracing_server.port; | ||
|
||
rt.block_on(run(&self.raw_filter, port)); | ||
} | ||
} | ||
|
||
async fn run(raw_filter: &str, port: u16) { | ||
info!("Setting raw log filter to: {raw_filter}"); | ||
let result = send_command(raw_filter, port).await; | ||
|
||
match result { | ||
Ok(_) => info!("Successfully set raw filter"), | ||
Err(e) => error!("Failed to set raw filter: {e}"), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use abscissa_core::clap::Parser; | ||
use abscissa_core::Command; | ||
use abscissa_core::Runnable; | ||
|
||
use crate::components::default_directive; | ||
use crate::prelude::*; | ||
use crate::tracing_handle::send_command; | ||
|
||
#[derive(Clone, Command, Debug, Parser, PartialEq, Eq)] | ||
pub struct ResetCmd {} | ||
|
||
impl Runnable for ResetCmd { | ||
fn run(&self) { | ||
let config = app_config(); | ||
|
||
let rt = tokio::runtime::Builder::new_current_thread() | ||
.enable_all() | ||
.build() | ||
.unwrap(); | ||
|
||
let port = config.tracing_server.port; | ||
let directive = default_directive(config.global.log_level); | ||
|
||
rt.block_on(run(&directive, port)); | ||
} | ||
} | ||
|
||
async fn run(directive: &str, port: u16) { | ||
info!("Resetting log filter to: {directive}"); | ||
let result = send_command(directive, port).await; | ||
|
||
match result { | ||
Ok(_) => info!("Successfully reset log filter"), | ||
Err(e) => error!("Failed to reset log filter: {e}"), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.