about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBaitinq <[email protected]>2024-05-29 23:03:48 +0200
committerBaitinq <[email protected]>2024-05-29 23:03:48 +0200
commitaee40b59c4430463c962c48f92f128e8932d733d (patch)
tree3da26184fa28f014484ddf772f2617ae7d41175f
parentmisc: Update readme (diff)
downloadfs-tracer-aee40b59c4430463c962c48f92f128e8932d733d.tar.gz
fs-tracer-aee40b59c4430463c962c48f92f128e8932d733d.tar.bz2
fs-tracer-aee40b59c4430463c962c48f92f128e8932d733d.zip
fs-tracer: send requests to new intake with api key
-rw-r--r--fs-tracer/Cargo.toml1
-rw-r--r--fs-tracer/src/main.rs27
2 files changed, 22 insertions, 6 deletions
diff --git a/fs-tracer/Cargo.toml b/fs-tracer/Cargo.toml
index 3a74bf7..68c318c 100644
--- a/fs-tracer/Cargo.toml
+++ b/fs-tracer/Cargo.toml
@@ -17,6 +17,7 @@ tokio = { version = "1.25", features = ["macros", "rt", "rt-multi-thread", "net"
 ureq = "2.9.7"
 ctrlc = "3.4.4"
 futures = "0.3.30"
+chrono = "0.4.38"
 
 [[bin]]
 name = "fs-tracer"
diff --git a/fs-tracer/src/main.rs b/fs-tracer/src/main.rs
index 9b61144..d126771 100644
--- a/fs-tracer/src/main.rs
+++ b/fs-tracer/src/main.rs
@@ -1,7 +1,6 @@
-use aya::maps::AsyncPerfEventArray;
-use aya::programs::TracePoint;
 use aya::util::online_cpus;
 use aya::{include_bytes_aligned, Ebpf};
+use aya::{maps::AsyncPerfEventArray, programs::TracePoint};
 use aya_log::EbpfLogger;
 use bytes::BytesMut;
 use fs_tracer_common::SyscallInfo;
@@ -17,7 +16,9 @@ async fn main() -> Result<(), anyhow::Error> {
 
     let fs_tracer_server_host =
         env::var("FS_TRACER_SERVER_HOST").expect("FS_TRACER_SERVER_HOST must be set");
-    let url = format!("http://{fs_tracer_server_host}:9999/payload");
+    let fs_tracer_api_key = env::var("FS_TRACER_API_KEY").expect("FS_TRACER_API_KEY must be set");
+
+    let url = format!("http://{fs_tracer_server_host}:9999/file/");
 
     // Bump the memlock rlimit. This is needed for older kernels that don't use the
     // new memcg based accounting, see https://lwn.net/Articles/837122/
@@ -77,6 +78,7 @@ async fn main() -> Result<(), anyhow::Error> {
         let mut buf = perf_array.open(cpu_id, None)?;
 
         let thread_url = url.clone();
+        let thread_api_key = fs_tracer_api_key.clone();
         let thread_exit = exit.clone();
         handles.push(task::spawn(async move {
             let mut buffers = (0..10)
@@ -94,10 +96,23 @@ async fn main() -> Result<(), anyhow::Error> {
                     match data {
                         SyscallInfo::Write(x) => {
                             println!("WRITE KERNEL: DATA {:?}", x);
-                            // TODO: Batching. Also add agent key
-                            let _ = ureq::post(thread_url.as_str())
-                                .send_string(format!("hi world! {:?}", x).as_str())
+                            // TODO: Batching.
+                            let resp = ureq::post(&thread_url)
+                                .set("API_KEY", &thread_api_key)
+                                .send_string(&format!(
+                                    r#"
+{{
+    "timestamp": "{}",
+    "absolute_path": "/tmp/test.txt",
+    "contents": "Hello, world!"
+}}
+"#,
+                                    chrono::Utc::now().to_rfc3339()
+                                ))
                                 .expect("Failed to send request");
+                            if resp.status() != 200 {
+                                panic!("Failed to send request: {:?}", resp);
+                            }
                         }
                         SyscallInfo::Open(x) => {
                             // if !CStr::from_bytes_until_nul(&x.filename)