Skip to content

Commit

Permalink
buck2: allow getting the log level set on either forkserver or daemon
Browse files Browse the repository at this point in the history
Summary: Like it says in the title.

Reviewed By: bobyangyf

Differential Revision: D42099161

fbshipit-source-id: e9ecaef3036e12f933ae1d497d6be00f105d650e
  • Loading branch information
krallin authored and facebook-github-bot committed Jan 4, 2023
1 parent 782e0b4 commit 2165bcf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
6 changes: 3 additions & 3 deletions app/buck2_client_ctx/src/daemon/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,10 @@ impl BuckdClient {
))
}

pub async fn set_log_filter(&mut self, log_filter: String) -> anyhow::Result<()> {
pub async fn set_log_filter(&mut self, req: SetLogFilterRequest) -> anyhow::Result<()> {
self.client
.daemon_only_mut()
.set_log_filter(Request::new(SetLogFilterRequest { log_filter }))
.set_log_filter(Request::new(req))
.await?;

Ok(())
Expand Down Expand Up @@ -614,7 +614,7 @@ impl<'a> FlushingBuckdClient<'a> {
wrap_method!(kill(reason: &str), ());
wrap_method!(status(snapshot: bool), StatusResponse);
wrap_method!(check_version(), VersionCheckResult);
wrap_method!(set_log_filter(log_filter: String), ());
wrap_method!(set_log_filter(log_filter: SetLogFilterRequest), ());
}

/// Create a stream that is sent over as a parameter via GRPC to the daemon.
Expand Down
16 changes: 15 additions & 1 deletion buck2_client/src/commands/debug/set_log_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@
use buck2_client_ctx::client_ctx::ClientCommandContext;
use buck2_client_ctx::daemon::client::connect::BuckdConnectOptions;
use buck2_client_ctx::exit_result::ExitResult;
use cli_proto::SetLogFilterRequest;

#[derive(Debug, clap::Parser)]
#[clap()]
pub struct SetLogFilterCommand {
/// The log filter to apply.
#[clap()]
log_filter: String,

/// Whether not to apply it to the daemon.
#[clap(long)]
no_daemon: bool,

/// Whether not to apply it to the forkserver.
#[clap(long)]
no_forkserver: bool,
}

impl SetLogFilterCommand {
Expand All @@ -27,7 +37,11 @@ impl SetLogFilterCommand {

buckd
.with_flushing()
.set_log_filter(self.log_filter)
.set_log_filter(SetLogFilterRequest {
log_filter: self.log_filter,
daemon: !self.no_daemon,
forkserver: !self.no_forkserver,
})
.await?;

ExitResult::success()
Expand Down
30 changes: 17 additions & 13 deletions buck2_server/src/daemon/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,19 +1113,23 @@ impl DaemonApi for BuckdServer {
) -> Result<Response<SetLogFilterResponse>, Status> {
let req = req.into_inner();

self.0
.log_reload_handle
.update_log_filter(&req.log_filter)
.context("Error updating daemon log filter")
.map_err(|e| Status::invalid_argument(format!("{:#}", e)))?;

if let Ok(data) = self.0.daemon_state.data() {
if let Some(forkserver) = data.forkserver.as_ref() {
forkserver
.set_log_filter(req.log_filter)
.await
.context("Error forwarding daemon log filter to forkserver")
.map_err(|e| Status::invalid_argument(format!("{:#}", e)))?;
if req.daemon {
self.0
.log_reload_handle
.update_log_filter(&req.log_filter)
.context("Error updating daemon log filter")
.map_err(|e| Status::invalid_argument(format!("{:#}", e)))?;
}

if req.forkserver {
if let Ok(data) = self.0.daemon_state.data() {
if let Some(forkserver) = data.forkserver.as_ref() {
forkserver
.set_log_filter(req.log_filter)
.await
.context("Error forwarding daemon log filter to forkserver")
.map_err(|e| Status::invalid_argument(format!("{:#}", e)))?;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions cli_proto/daemon.proto
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,8 @@ message FlushDepFilesRequest {}

message SetLogFilterRequest {
string log_filter = 1;
bool daemon = 2;
bool forkserver = 3;
}

message SetLogFilterResponse {}
Expand Down

0 comments on commit 2165bcf

Please sign in to comment.