-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from davincios/feature/stdout-capture
STDOUT Bash Capture
- Loading branch information
Showing
12 changed files
with
127 additions
and
13 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod bashrc_intercept; | ||
mod config; | ||
pub mod target_process; | ||
pub use bashrc_intercept::INTERCEPTOR_STDOUT_FILE; | ||
pub use config::{Config, ConfigManager}; |
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,73 @@ | ||
use std::sync::Arc; | ||
|
||
use anyhow::Result; | ||
use linemux::MuxedLines; | ||
use serde_json::json; | ||
use tokio::sync::RwLock; | ||
use tokio_stream::StreamExt; | ||
|
||
use crate::{debug_log::Logger, http_client::send_http_body}; | ||
|
||
// Todo: A lot of code is duplicated between this file and syslog. Maybe we could extract the file reading code into a separate module? | ||
pub struct StdoutWatcher {} | ||
|
||
pub async fn run_stdout_lines_read_thread( | ||
file_path: &str, | ||
pending_lines: Arc<RwLock<Vec<String>>>, | ||
) { | ||
let line_reader = MuxedLines::new(); | ||
|
||
if line_reader.is_err() { | ||
return; | ||
} | ||
|
||
let mut line_reader = line_reader.unwrap(); | ||
|
||
let result = line_reader.add_file(file_path).await; | ||
|
||
if result.is_err() { | ||
return; | ||
} | ||
|
||
while let Ok(Some(line)) = line_reader.try_next().await { | ||
let mut vec = pending_lines.write().await; | ||
let line = line.line(); | ||
vec.push(line.to_string()); | ||
} | ||
} | ||
|
||
impl StdoutWatcher { | ||
pub fn new() -> StdoutWatcher { | ||
StdoutWatcher {} | ||
} | ||
|
||
pub async fn poll_stdout( | ||
&mut self, | ||
service_url: &str, | ||
api_key: &str, | ||
pending_lines: Arc<RwLock<Vec<String>>>, | ||
) -> Result<()> { | ||
let logger = Logger::new(); | ||
|
||
if pending_lines.read().await.is_empty() { | ||
logger.log("No lines from stdout to send", None).await; | ||
return Ok(()); | ||
} | ||
|
||
let url = format!("{}/stdout-capture", service_url); | ||
|
||
let body = json!({ | ||
"lines": *pending_lines.as_ref().read().await | ||
}); | ||
|
||
logger | ||
.log(&format!("Sending stdout lines: {:?}", body), None) | ||
.await; | ||
|
||
pending_lines.write().await.clear(); | ||
|
||
send_http_body(&url, api_key, &body).await?; | ||
|
||
Ok(()) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
api_key = "<YOUR_API_KEY>" | ||
service_url = "https://app.tracer.bio/api/data-collector-api" | ||
service_url = "https://app.tracer.bio/api" | ||
process_polling_interval_ms = 20 | ||
batch_submission_interval_ms = 5000 |