From 6f129f58189b01b0b624d5e4036116fc6f116247 Mon Sep 17 00:00:00 2001 From: Brad Reed Date: Tue, 22 Oct 2024 12:00:45 +0100 Subject: [PATCH] b64 log; ret if ws fail --- metrics/Cargo.lock | 13 ++++++++++--- metrics/Cargo.toml | 1 + metrics/src/logprocessor.rs | 3 ++- metrics/src/logreceiver.rs | 5 ++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/metrics/Cargo.lock b/metrics/Cargo.lock index 2b44af8..a956c28 100644 --- a/metrics/Cargo.lock +++ b/metrics/Cargo.lock @@ -30,7 +30,7 @@ dependencies = [ "actix-service", "actix-utils", "ahash", - "base64", + "base64 0.13.0", "bitflags", "brotli", "bytes", @@ -367,6 +367,12 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bitflags" version = "1.3.2" @@ -1102,6 +1108,7 @@ version = "0.1.7" dependencies = [ "actix-web", "actix-ws", + "base64 0.22.1", "clap", "env_logger", "futures", @@ -1619,7 +1626,7 @@ version = "0.11.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" dependencies = [ - "base64", + "base64 0.13.0", "bytes", "encoding_rs", "futures-core", @@ -2044,7 +2051,7 @@ dependencies = [ "async-stream", "async-trait", "axum", - "base64", + "base64 0.13.0", "bytes", "futures-core", "futures-util", diff --git a/metrics/Cargo.toml b/metrics/Cargo.toml index d8b8c03..61ca736 100644 --- a/metrics/Cargo.toml +++ b/metrics/Cargo.toml @@ -13,6 +13,7 @@ log = "0.4.16" reqwest = { version = "0.11", features = ["json"]} +base64 = "0.22.1" tokio = { version = "1.37", features = ["full"]} actix-web = "4.0.1" actix-ws = "0.3.0" diff --git a/metrics/src/logprocessor.rs b/metrics/src/logprocessor.rs index e5dec10..c1da429 100644 --- a/metrics/src/logprocessor.rs +++ b/metrics/src/logprocessor.rs @@ -2,6 +2,7 @@ use log::warn; use serde::Deserialize; use serde_json::{from_str, from_value}; +use base64::prelude::{Engine as _, BASE64_STANDARD_NO_PAD}; use crate::Telemetry; use opentelemetry::{ @@ -220,7 +221,7 @@ pub async fn log_processor(logline: &String, metric_obj: &Telemetry, tracer: &tr } Err(e) => { warn!("Failed to parse log line: {}", e); - warn!("Line was: {}", logline); + warn!("Line was b64: {}", BASE64_STANDARD_NO_PAD.encode(logline)); } }; } diff --git a/metrics/src/logreceiver.rs b/metrics/src/logreceiver.rs index f1ef1a2..8ccf3cc 100644 --- a/metrics/src/logreceiver.rs +++ b/metrics/src/logreceiver.rs @@ -19,8 +19,11 @@ async fn receive_log( if let Ok(Message::Text(text)) = msg { let _ = logprocessor::log_processor(&text.trim().to_string(), &metric_obj, &tracer).await; session.text("{\"success\": true}").await.unwrap(); + } else { + // TODO: improve + warn!("Success: false"); + session.text("{\"success\": false}").await.unwrap(); } - // TODO: log if failed } });