Skip to content

Commit 0cd0607

Browse files
enhancement: add log level override subcommand to ADP binary (#767)
## Summary This PR adds two debug subcommands for dynamically configuring the log level of the ADP process: `debug set-log-level` and `debug reset-log-level`. For setting the log level, this should be `agent-data-plane debug set-log-level`. The subcommand would call out to /logging/override. For resetting the log level, this should be `agent-data-plane debug reset-log-level`. The subcommand would call out to /logging/reset. ## Change Type - [ ] Bug fix - [x] New feature - [ ] Non-functional (chore, refactoring, docs) - [ ] Performance ## How did you test this PR? Manually tested by running the run-adp-standalone and testing various set and reset commands ## References Closes #731.
1 parent 99f6591 commit 0cd0607

File tree

4 files changed

+96
-16
lines changed

4 files changed

+96
-16
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/agent-data-plane/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ memory-accounting = { workspace = true }
2323
papaya = { workspace = true }
2424
rand = { workspace = true }
2525
rand_distr = { workspace = true }
26+
reqwest = { workspace = true, features = ["rustls-tls-native-roots-no-provider", "json"] }
2627
saluki-app = { workspace = true, features = ["full"] }
2728
saluki-common = { workspace = true }
2829
saluki-components = { workspace = true }

bin/agent-data-plane/src/config.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clap::{Args, Parser, Subcommand};
55
#[derive(Parser)]
66
#[command(about)]
77
pub struct Cli {
8-
/// Subcommand to run.
8+
/// Subcommand to run.
99
#[command(subcommand)]
1010
pub action: Option<Action>,
1111
}
@@ -15,6 +15,10 @@ pub enum Action {
1515
/// Runs the data plane.
1616
#[command(name = "run")]
1717
Run(RunConfig),
18+
19+
/// Various debugging commands.
20+
#[command(subcommand)]
21+
Debug(DebugConfig),
1822
}
1923

2024
/// Run subcommand configuration.
@@ -24,3 +28,27 @@ pub struct RunConfig {
2428
#[arg(short = 'c', long = "config", default_value = "/etc/datadog-agent/datadog.yaml")]
2529
pub config: PathBuf,
2630
}
31+
32+
/// Debug subcommand configuration.
33+
#[derive(Subcommand, Debug)]
34+
pub enum DebugConfig {
35+
/// Resets log level.
36+
#[command(name = "reset-log-level")]
37+
ResetLogLevel,
38+
39+
/// Overrides the current log level.
40+
#[command(name = "set-log-level")]
41+
SetLogLevel(SetLogLevelConfig),
42+
}
43+
44+
/// Set log level configuration.
45+
#[derive(Args, Debug)]
46+
pub struct SetLogLevelConfig {
47+
/// Filter directives to apply.
48+
#[arg(required = true)]
49+
pub filter_directives: String,
50+
51+
/// Amount of time to apply the log level override, in seconds.
52+
#[arg(required = true)]
53+
pub duration_secs: u64,
54+
}

bin/agent-data-plane/src/main.rs

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use tracing::{error, info, warn};
2929
mod components;
3030

3131
mod config;
32-
use self::config::{Action, Cli, RunConfig};
32+
use self::config::{Action, Cli, DebugConfig, RunConfig};
3333

3434
mod env_provider;
3535
use self::env_provider::ADPEnvironmentProvider;
@@ -70,19 +70,69 @@ async fn main() {
7070
fatal_and_exit(format!("failed to initialize TLS: {}", e));
7171
}
7272

73-
// Use default configuration path when no subcommand is provided.
74-
let run_config = match cli.action {
75-
Some(Action::Run(config)) => config,
76-
None => RunConfig {
77-
config: std::path::PathBuf::from("/etc/datadog-agent/datadog.yaml"),
73+
let client = reqwest::Client::builder()
74+
.danger_accept_invalid_certs(true)
75+
.build()
76+
.unwrap();
77+
78+
match cli.action {
79+
Some(Action::Run(config)) => match run(started, config).await {
80+
Ok(()) => info!("Agent Data Plane stopped."),
81+
Err(e) => {
82+
error!("{:?}", e);
83+
std::process::exit(1);
84+
}
7885
},
79-
};
80-
81-
match run(started, run_config).await {
82-
Ok(()) => info!("Agent Data Plane stopped."),
83-
Err(e) => {
84-
error!("{:?}", e);
85-
std::process::exit(1);
86+
Some(Action::Debug(DebugConfig::ResetLogLevel)) => {
87+
let response = match client.post("https://localhost:5101/logging/reset").send().await {
88+
Ok(resp) => resp,
89+
Err(e) => {
90+
error!("Failed to send request: {}", e);
91+
std::process::exit(1);
92+
}
93+
};
94+
95+
if response.status().is_success() {
96+
println!("Log level reset successful");
97+
} else {
98+
eprintln!("Failed to reset log level: {}", response.status());
99+
}
100+
}
101+
Some(Action::Debug(DebugConfig::SetLogLevel(config))) => {
102+
let filter_directives = config.filter_directives;
103+
let duration_secs = config.duration_secs;
104+
105+
let response = match client
106+
.post("https://localhost:5101/logging/override")
107+
.query(&[("time_secs", duration_secs)])
108+
.body(filter_directives)
109+
.send()
110+
.await
111+
{
112+
Ok(resp) => resp,
113+
Err(e) => {
114+
error!("Failed to send request: {}", e);
115+
std::process::exit(1);
116+
}
117+
};
118+
119+
if response.status().is_success() {
120+
println!("Log level override successful");
121+
} else {
122+
eprintln!("Failed to override log level: {}", response.status());
123+
}
124+
}
125+
None => {
126+
let default_config = RunConfig {
127+
config: std::path::PathBuf::from("/etc/datadog-agent/datadog.yaml"),
128+
};
129+
match run(started, default_config).await {
130+
Ok(()) => info!("Agent Data Plane stopped."),
131+
Err(e) => {
132+
error!("{:?}", e);
133+
std::process::exit(1);
134+
}
135+
}
86136
}
87137
}
88138
}
@@ -217,8 +267,8 @@ async fn create_topology(
217267
}
218268
Err(_) => {
219269
info!(
220-
"Dynamic configuration refreshing will be unavailable due to failure to configure refresher configuration."
221-
)
270+
"Dynamic configuration refreshing will be unavailable due to failure to configure refresher configuration."
271+
)
222272
}
223273
}
224274

0 commit comments

Comments
 (0)