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

Switch Plugins to use Tracing crate Logging and Forward Plugin Logging to Hipcheck core stderr/stdout #968

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

KirilldogU
Copy link
Contributor

Resolves #381 and #933.
This PR switches the Hipcheck plugins to use the tracing crate for logging instead of the logging crate (as will be done on Hipcheck core).
It also forwards the logging output of plugins to the stderr/stdout output of Hipcheck core.
It does this through:

  • Creating a feature in hipcheck_sdk to initialize a tracing_subscriber
  • Calling the init_logger() feature from each plugin
  • When plugins are launched as a child process: pipe their output to a tokio task in manager.rs that deserializes the json logs, parses them, and re-emits them to Hipcheck core output.

It also adds docs in the sdk on how to use the init_logger() feature.

@KirilldogU KirilldogU requested a review from j-lanson February 28, 2025 22:26
@KirilldogU KirilldogU force-pushed the kusubyan/tracing-logging-upgrade branch from d9bd176 to e4ecc93 Compare March 2, 2025 23:47
@KirilldogU KirilldogU marked this pull request as draft March 3, 2025 18:30
@KirilldogU KirilldogU force-pushed the kusubyan/tracing-logging-upgrade branch 7 times, most recently from 7a4e4f1 to ebcd05d Compare March 4, 2025 20:43
@KirilldogU KirilldogU self-assigned this Mar 4, 2025
@KirilldogU KirilldogU marked this pull request as ready for review March 4, 2025 20:44
@KirilldogU KirilldogU force-pushed the kusubyan/tracing-logging-upgrade branch 3 times, most recently from 86db15f to 51dffa6 Compare March 6, 2025 22:08
@KirilldogU KirilldogU marked this pull request as draft March 6, 2025 22:34
@KirilldogU KirilldogU force-pushed the kusubyan/tracing-logging-upgrade branch 3 times, most recently from 534c726 to 9dec34f Compare March 7, 2025 23:58
@KirilldogU KirilldogU marked this pull request as ready for review March 8, 2025 00:02
@j-lanson
Copy link
Collaborator

@KirilldogU please resolve the merge conflicts. probably a rebase on origin/main, and unless you have a good reason, defer to the existing change on origin/main over your own since its mostly Cargo.toml files

@@ -31,7 +31,12 @@ pub struct PluginServer<P> {

impl<P: Plugin> PluginServer<P> {
/// Create a new plugin server for the provided plugin.
pub fn register(plugin: P) -> PluginServer<P> {
pub fn register(plugin: P, log_level: &str) -> PluginServer<P> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

log_level should be an Enum, and probably should be Option<LogLevel> which is equal to LogLevel::Error when set to None. Similarly, should be this way in the Args {} struct

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can do log_level: impl Into<Option<LogLevel>> so that people can pass the raw LogLevel or None depending.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You may want to move LogLevel declaration into the hipcheck-common crate so both the SDK and the core can use it

@alilleybrinker alilleybrinker self-requested a review March 10, 2025 15:25
for setting in settings {
let parts: Vec<&str> = setting.split('=').collect();

if parts.len() == 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you please comment this block and the parts.len() == 2 block with an explanation of what these cases mean, with at least one example for each? I think that would help a lot, since a reader of this code isn't necessarily familiar with the syntax this code is trying to parse.

Copy link
Collaborator

Choose a reason for hiding this comment

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

for setting in settings {
let parts: Vec<&str> = setting.split('=').collect();

if parts.len() == 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

let reader = BufReader::new(reader);
let mut lines = reader.lines();
// parse plugin log json lines to LogEvent objects and output the messages
while let Some(line) = lines.next_line().await.unwrap() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a safety comment for why this unwrap would never be hit, or replace it with error reporting.

@KirilldogU KirilldogU force-pushed the kusubyan/tracing-logging-upgrade branch 2 times, most recently from 937cec1 to 6e51dbe Compare March 11, 2025 04:08
… to hc-core output

Signed-off-by: Kirill Usubyan <kusubyan@mitre.org>
@KirilldogU KirilldogU force-pushed the kusubyan/tracing-logging-upgrade branch from 6e51dbe to 2ac238c Compare March 11, 2025 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Proper logging for plugins
4 participants