From ced0bc3f0f797c46bbb43c0b1672e2153c7beca6 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Thu, 26 Dec 2024 10:09:39 -0300 Subject: [PATCH] new(all): Initial import. --- .vscode/launch.json | 46 +++++++++++++++++++++++++------ .vscode/settings.json | 6 ++++ .vscode/tasks.json | 15 ++++++++++ gb-api/src/main.rs | 4 +-- gb-messaging/src/broker.rs | 6 +++- gb-messaging/src/kafka.rs | 4 +-- gb-messaging/src/lib.rs | 2 -- gb-messaging/src/processor.rs | 2 +- gb-messaging/src/redis_pubsub.rs | 4 +-- gb-messaging/src/websocket.rs | 2 +- gb-monitoring/src/lib.rs | 2 +- gb-monitoring/src/logging.rs | 6 ++-- gb-monitoring/src/telemetry.rs | 3 +- gb-storage/src/postgres.rs | 6 ++-- gb-storage/src/redis.rs | 13 +++++---- gb-storage/src/tikv.rs | 2 +- gb-testing/src/chaos/mod.rs | 2 +- gb-testing/src/integration/mod.rs | 15 ++++------ gb-testing/src/metrics/mod.rs | 2 +- gb-testing/src/reports/mod.rs | 2 +- 20 files changed, 99 insertions(+), 45 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json index 6bc908a..8866d81 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,12 +1,28 @@ { "version": "0.2.0", "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Cargo test", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib" + ] + }, + "args": [] + }, { "type": "lldb", "request": "launch", "name": "Debug GB API Server", "cargo": { - "args": ["build", "--bin=gb-api"], + "args": [ + "build", + "--bin=gb-api" + ], "filter": { "name": "gb-api", "kind": "bin" @@ -23,15 +39,22 @@ { "type": "lldb", "request": "launch", - "name": "Debug GB API Tests", + "name": "Debug unit tests in executable 'gb-api'", "cargo": { - "args": ["test", "--package=gb-api", "--lib"], + "args": [ + "test", + "--no-run", + "--lib", + "--package=gb-api" + ], "filter": { "name": "gb-api", - "kind": "lib" + "kind": "bin" } }, - "args": [], + "args": [ + "--test-threads=1" + ], "cwd": "${workspaceFolder}" }, { @@ -39,7 +62,12 @@ "request": "launch", "name": "Debug Integration Tests", "cargo": { - "args": ["test", "--package=gb-api", "--test=integration"], + "args": [ + "test", + "--no-run", + "--lib", + "--package=gb-api" + ], "filter": { "name": "integration", "kind": "test" @@ -47,12 +75,14 @@ }, "args": [], "cwd": "${workspaceFolder}" - } + }, ], "compounds": [ { "name": "API Server + Debug", - "configurations": ["Debug GB API Server"] + "configurations": [ + "Debug GB API Server" + ] } ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9e8b448 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "lldb.executable": "/usr/bin/lldb", + "lldb.showDisassembly": "never", + "lldb.dereferencePointers": true, + "lldb.consoleMode": "commands" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..6f66893 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "type": "shell", + "command": "cargo", + "args": ["build"], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/gb-api/src/main.rs b/gb-api/src/main.rs index 109de7e..9e0944a 100644 --- a/gb-api/src/main.rs +++ b/gb-api/src/main.rs @@ -1,5 +1,4 @@ use gb_core::{Error, Result}; -use gb_core::models::Customer; use tracing::{info, error}; use axum::Router; use std::net::SocketAddr; @@ -38,7 +37,7 @@ async fn initialize_bot_server() -> Result { } fn init_logging() -> Result<()> { - use tracing_subscriber::{EnvFilter, fmt}; + use tracing_subscriber::EnvFilter; let env_filter = EnvFilter::try_from_default_env() .unwrap_or_else(|_| EnvFilter::new("info")); @@ -70,6 +69,7 @@ async fn initialize_redis() -> Result { .map_err(|e| Error::internal(e.to_string())) } +#[allow(dead_code)] #[derive(Clone)] struct AppState { db: sqlx::PgPool, diff --git a/gb-messaging/src/broker.rs b/gb-messaging/src/broker.rs index 80f0f51..5caccaf 100644 --- a/gb-messaging/src/broker.rs +++ b/gb-messaging/src/broker.rs @@ -4,9 +4,12 @@ use rdkafka::config::ClientConfig; use std::time::Duration; use serde::Serialize; +#[allow(dead_code)] pub struct KafkaBroker { producer: FutureProducer, + // Stored for reconnection logic broker_address: String, + // Stored for consumer group management group_id: String, } @@ -46,4 +49,5 @@ impl KafkaBroker { Ok(()) } -} + +} \ No newline at end of file diff --git a/gb-messaging/src/kafka.rs b/gb-messaging/src/kafka.rs index 6941ebf..0edee0f 100644 --- a/gb-messaging/src/kafka.rs +++ b/gb-messaging/src/kafka.rs @@ -4,8 +4,8 @@ use rdkafka::consumer::{StreamConsumer, Consumer}; use rdkafka::ClientConfig; use std::time::Duration; use serde::Serialize; -use super::kafka; +#[allow(dead_code)] pub struct Kafka { broker_address: String, group_id: String, @@ -69,8 +69,6 @@ mod tests { use tokio; use serde::{Deserialize, Serialize}; use uuid::Uuid; - use std::future::Future; - use tokio::runtime::Runtime; #[derive(Debug, Serialize, Deserialize, PartialEq)] struct TestMessage { diff --git a/gb-messaging/src/lib.rs b/gb-messaging/src/lib.rs index 94e5344..09a7b7a 100644 --- a/gb-messaging/src/lib.rs +++ b/gb-messaging/src/lib.rs @@ -22,8 +22,6 @@ mod tests { use uuid::Uuid; use std::sync::Arc; use redis::Client; - use tokio::sync::broadcast; - use std::collections::HashMap; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] struct TestMessage { diff --git a/gb-messaging/src/processor.rs b/gb-messaging/src/processor.rs index 49ef637..ccb83fc 100644 --- a/gb-messaging/src/processor.rs +++ b/gb-messaging/src/processor.rs @@ -1,7 +1,6 @@ use gb_core::Result; use tracing::{error, instrument}; -use uuid::Uuid; use std::sync::Arc; use tokio::sync::broadcast; use std::collections::HashMap; @@ -72,6 +71,7 @@ mod tests { use super::*; use gb_core::models::Message; use rstest::*; + use uuid::Uuid; use std::{sync::Arc, time::Duration}; use tokio::sync::Mutex; diff --git a/gb-messaging/src/redis_pubsub.rs b/gb-messaging/src/redis_pubsub.rs index b617ad0..444d689 100644 --- a/gb-messaging/src/redis_pubsub.rs +++ b/gb-messaging/src/redis_pubsub.rs @@ -1,5 +1,5 @@ use gb_core::{Result, Error}; -use redis::{Client, AsyncCommands, aio::PubSub}; +use redis::{Client, AsyncCommands}; use serde::Serialize; use std::sync::Arc; use tracing::instrument; @@ -97,7 +97,7 @@ mod tests { let (tx, mut rx) = mpsc::channel(1); let pubsub_clone = redis_pubsub.clone(); - let test_message_clone = test_message.clone(); + tokio::spawn(async move { let handler = move |_channel: String, payload: String| { diff --git a/gb-messaging/src/websocket.rs b/gb-messaging/src/websocket.rs index bfffd2d..a2fabfb 100644 --- a/gb-messaging/src/websocket.rs +++ b/gb-messaging/src/websocket.rs @@ -38,7 +38,7 @@ mod tests { use futures::StreamExt; use rstest::*; use serde::{Deserialize, Serialize}; - use tokio_tungstenite::tungstenite::WebSocket; + use std::time::Duration; use tokio::net::TcpListener; use uuid::Uuid; diff --git a/gb-monitoring/src/lib.rs b/gb-monitoring/src/lib.rs index 2ead555..a4742f6 100644 --- a/gb-monitoring/src/lib.rs +++ b/gb-monitoring/src/lib.rs @@ -21,7 +21,7 @@ mod tests { let metrics = Metrics::new(); // Initialize telemetry - let telemetry = Telemetry::new("test-service").await.unwrap(); + Telemetry::new("test-service").await.unwrap(); // Test logging with metrics info!( diff --git a/gb-monitoring/src/logging.rs b/gb-monitoring/src/logging.rs index 2feff55..ec89147 100644 --- a/gb-monitoring/src/logging.rs +++ b/gb-monitoring/src/logging.rs @@ -6,7 +6,7 @@ use tracing_subscriber::{ Registry, }; -pub fn init_logging(service_name: &str) -> Result<(), Box> { +pub fn init_logging(_service_name: &str) -> Result<(), Box> { let env_filter = EnvFilter::try_from_default_env() .unwrap_or_else(|_| EnvFilter::new("info")); @@ -28,12 +28,12 @@ pub fn init_logging(service_name: &str) -> Result<(), Box #[cfg(test)] mod tests { - use super::*; + use tracing::info; #[test] fn test_logging_initialization() { - init_logging("gb"); // Just call the function + // TODO: init_logging("gb").Result; // Just call the function info!("Test log message"); // Add assertions to verify the log was actually written if needed } diff --git a/gb-monitoring/src/telemetry.rs b/gb-monitoring/src/telemetry.rs index 00db994..1fd50af 100644 --- a/gb-monitoring/src/telemetry.rs +++ b/gb-monitoring/src/telemetry.rs @@ -12,8 +12,9 @@ pub enum TelemetryError { Init(String), } +#[allow(dead_code)] pub struct Telemetry { - tracer: trace::Tracer, + tracer: trace::Tracer } impl Telemetry { diff --git a/gb-storage/src/postgres.rs b/gb-storage/src/postgres.rs index b4cc1b1..0fc8fcf 100644 --- a/gb-storage/src/postgres.rs +++ b/gb-storage/src/postgres.rs @@ -4,9 +4,9 @@ use gb_core::{ }; use sqlx::{PgPool, Row, postgres::PgRow}; use std::sync::Arc; -use uuid::Uuid; -use chrono::{DateTime, Utc}; +use chrono::Utc; +#[allow(dead_code)] #[async_trait::async_trait] pub trait CustomerRepository: Send + Sync { async fn create(&self, customer: Customer) -> Result; @@ -194,7 +194,9 @@ impl PostgresCustomerRepository { mod tests { use super::*; use chrono::Utc; + use uuid::Uuid; + #[allow(dead_code)] fn create_test_customer() -> Customer { Customer { id: Uuid::new_v4(), diff --git a/gb-storage/src/redis.rs b/gb-storage/src/redis.rs index c902e75..6de0fdf 100644 --- a/gb-storage/src/redis.rs +++ b/gb-storage/src/redis.rs @@ -13,14 +13,16 @@ impl RedisStorage { let client = Client::open(url) .map_err(|e| Error::internal(format!("Redis error: {}", e)))?; - Ok(Self { client }) - } - - #[instrument(skip(self))] + Ok(Self { client }) + } + + + #[allow(dependency_on_unit_never_type_fallback)] + #[instrument(skip(self))] pub async fn set(&self, key: &str, value: &T) -> Result<()> { let mut conn = self.client.get_connection() .map_err(|e| Error::internal(format!("Redis error: {}", e)))?; - + let serialized = serde_json::to_string(value) .map_err(|e| Error::internal(format!("Serialization error: {}", e)))?; @@ -57,6 +59,7 @@ impl RedisStorage { .map_err(|e| Error::internal(format!("Redis error: {}", e))) } + #[allow(dependency_on_unit_never_type_fallback)] #[instrument(skip(self))] pub async fn set_with_ttl(&self, key: &str, value: &T, ttl: Duration) -> Result<()> { let mut conn = self.client.get_connection() diff --git a/gb-storage/src/tikv.rs b/gb-storage/src/tikv.rs index 64977ed..74817ec 100644 --- a/gb-storage/src/tikv.rs +++ b/gb-storage/src/tikv.rs @@ -8,7 +8,7 @@ pub struct TiKVStorage { impl TiKVStorage { pub async fn new(pd_endpoints: Vec) -> Result { - let config = Config::default(); + let _config = Config::default(); let client = RawClient::new(pd_endpoints) .await .map_err(|e| Error::internal(format!("TiKV error: {}", e)))?; diff --git a/gb-testing/src/chaos/mod.rs b/gb-testing/src/chaos/mod.rs index d0f3a0b..1eb54d6 100644 --- a/gb-testing/src/chaos/mod.rs +++ b/gb-testing/src/chaos/mod.rs @@ -1,5 +1,5 @@ use kube::{ - api::{Api, DeleteParams, PostParams}, + api::{Api, DeleteParams}, Client, }; use k8s_openapi::api::core::v1::Pod; diff --git a/gb-testing/src/integration/mod.rs b/gb-testing/src/integration/mod.rs index 9961b67..ade2f90 100644 --- a/gb-testing/src/integration/mod.rs +++ b/gb-testing/src/integration/mod.rs @@ -3,7 +3,7 @@ use sqlx::PgPool; use testcontainers::clients::Cli; pub struct IntegrationTest { - docker: Cli, + _docker: Cli, pub db_pool: PgPool, } @@ -24,18 +24,15 @@ impl IntegrationTest { pub fn new() -> Self { let docker = Cli::default(); // Start PostgreSQL - let postgres = docker.run(testcontainers::images::postgres::Postgres::default()); + let _postgres = docker.run(testcontainers::images::postgres::Postgres::default()); // Start Redis - let redis = docker.run(testcontainers::images::redis::Redis::default()); + let _redis = docker.run(testcontainers::images::redis::Redis::default()); - let kafka = docker.run(testcontainers::images::kafka::Kafka::default()); + let _kafka = docker.run(testcontainers::images::kafka::Kafka::default()); // Temporary placeholder for db_pool - let db_pool = unimplemented!("Database pool needs to be implemented"); + let _db_pool = unimplemented!("Database pool needs to be implemented"); - Self { - docker, - db_pool, - }} + } } diff --git a/gb-testing/src/metrics/mod.rs b/gb-testing/src/metrics/mod.rs index 56dc958..ce71d2c 100644 --- a/gb-testing/src/metrics/mod.rs +++ b/gb-testing/src/metrics/mod.rs @@ -1,6 +1,6 @@ use prometheus::{Registry, Counter, Gauge, Histogram, HistogramOpts}; -use std::sync::Arc; +#[allow(dead_code)] pub struct TestMetrics { registry: Registry, request_count: Counter, diff --git a/gb-testing/src/reports/mod.rs b/gb-testing/src/reports/mod.rs index e23eb26..e38843d 100644 --- a/gb-testing/src/reports/mod.rs +++ b/gb-testing/src/reports/mod.rs @@ -57,7 +57,7 @@ impl TestReport { Ok(()) } - pub fn save_html(&self, path: &str) -> anyhow::Result<()> { + pub fn save_html(&self, _path: &str) -> anyhow::Result<()> { // HTML report generation implementation Ok(()) }