From dfcce8a14701625972d12a4d89bde70a09bb6bf7 Mon Sep 17 00:00:00 2001 From: ralvescosta Date: Tue, 14 Feb 2023 07:07:01 -0300 Subject: [PATCH 1/4] refactor: otel --- Cargo.lock | 28 ++++++++++++++++++++++++++++ httpw/Cargo.toml | 2 ++ httpw/src/server/server.rs | 36 ++++++++++++++++++++++++++++++++---- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6a1eed9..d279b4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -198,6 +198,20 @@ dependencies = [ "syn", ] +[[package]] +name = "actix-web-opentelemetry" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaa592a5b9b3d96101434bca1024c6da6c23630163aec485428e613cd7100dcf" +dependencies = [ + "actix-http", + "actix-web", + "futures-util", + "opentelemetry", + "opentelemetry-semantic-conventions", + "serde", +] + [[package]] name = "adler" version = "1.0.2" @@ -1643,6 +1657,11 @@ version = "0.1.0" dependencies = [ "actix-cors", "actix-web", +<<<<<<< Updated upstream +======= + "actix-web-opentelemetry", + "auth", +>>>>>>> Stashed changes "env", "errors", "serde", @@ -2159,6 +2178,15 @@ dependencies = [ "tonic-build", ] +[[package]] +name = "opentelemetry-semantic-conventions" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b02e0230abb0ab6636d18e2ba8fa02903ea63772281340ccac18e0af3ec9eeb" +dependencies = [ + "opentelemetry", +] + [[package]] name = "opentelemetry_api" version = "0.18.0" diff --git a/httpw/Cargo.toml b/httpw/Cargo.toml index d13523a..fd720a2 100644 --- a/httpw/Cargo.toml +++ b/httpw/Cargo.toml @@ -13,3 +13,5 @@ actix-web = { version = "4.3.0" } actix-cors = { version = "0.6.3" } serde = { version = "1.0.152", features = ["derive"] } tracing = { version = "0.1.37" } +opentelemetry = { version = "0.18.0" } +actix-web-opentelemetry = { version = "0.13.0", features = ["metrics"] } diff --git a/httpw/src/server/server.rs b/httpw/src/server/server.rs index d9665ba..164bd13 100644 --- a/httpw/src/server/server.rs +++ b/httpw/src/server/server.rs @@ -1,8 +1,17 @@ -use super::types::AppConfig; +use super::types::RouteConfig; use crate::middlewares; -use actix_web::{middleware as actix_middleware, web, App, HttpServer}; +use crate::{errors::HttpServerError, middlewares}; +use actix_web::{ + middleware as actix_middleware, + web::{self, Data}, + App, HttpResponse, HttpServer, Responder, +}; +use actix_web_opentelemetry::{RequestMetricsBuilder, RequestTracing}; +use auth::jwt_manager::JwtManager; use env::AppConfig as AppEnv; +use env::AppConfig; use errors::http_server::HttpServerError; +use opentelemetry::global; use std::sync::Arc; use tracing::error; @@ -30,17 +39,30 @@ impl HttpwServerImpl { HttpServer::new({ let services = self.services.to_vec(); move || { + let meter = global::meter("actix_web"); + let mut app = App::new() .wrap(actix_middleware::Compress::default()) .wrap(middlewares::headers::config()) .wrap(middlewares::cors::config()) - .wrap(actix_middleware::Logger::default()); + .wrap(RequestTracing::new()) + .wrap(RequestMetricsBuilder::new().build(meter)); + + if let Some(jwt_manager) = jwt_manager.clone() { + app = app.app_data::>>(web::Data::< + Arc, + >::new( + jwt_manager.clone(), + )); + } for svc in services.clone() { app = app.configure(svc); } - app.default_service(web::to(middlewares::not_found::not_found)) + app.route("/health", web::get().to(health_handler)) + .default_service(web::to(middlewares::not_found::not_found)) + .wrap(actix_middleware::Logger::default()) } }) .bind(&self.addr) @@ -58,6 +80,12 @@ impl HttpwServerImpl { HttpServerError::ServerError {} })?; + global::shutdown_tracer_provider(); + Ok(()) } } + +async fn health_handler() -> impl Responder { + HttpResponse::Ok().body("health") +} From 6b646e6375e2f4711ef481b3842055234bc0946a Mon Sep 17 00:00:00 2001 From: ralvescosta Date: Tue, 14 Feb 2023 09:46:47 -0300 Subject: [PATCH 2/4] feat: openapi --- httpw/src/server/server.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/httpw/src/server/server.rs b/httpw/src/server/server.rs index 1e4ae91..26b0057 100644 --- a/httpw/src/server/server.rs +++ b/httpw/src/server/server.rs @@ -16,6 +16,7 @@ pub struct HttpwServerImpl { services: Vec, jwt_manager: Option>, addr: String, + // openapi_file_path: Option, } impl HttpwServerImpl { @@ -24,6 +25,7 @@ impl HttpwServerImpl { services: vec![], addr: cfg.app_addr(), jwt_manager: None, + // openapi_file_path: None, } } } @@ -39,10 +41,16 @@ impl HttpwServerImpl { self } + // pub fn openapi_file_path(mut self, file_path: String) -> Self { + // self.openapi_file_path = Some(file_path); + // self + // } + pub async fn start(&self) -> Result<(), HttpServerError> { HttpServer::new({ let services = self.services.to_vec(); let jwt_manager = self.jwt_manager.clone(); + // let openapi_file = self.openapi_file_path.clone(); move || { let meter = global::meter("actix_web"); @@ -66,6 +74,17 @@ impl HttpwServerImpl { app = app.configure(svc); } + // if let Some(_openapi) = openapi_file.clone() { + // let spec = swagger_ui::swagger_spec_file!("../../swagger-ui/examples/openapi.json"); + // let config = swagger_ui::Config::default(); + // + // let app = app.service( + // scope("/v1/doc") + // .configure(actix_web_swagger_ui::swagger(spec, config)) + // ); + // + // } + app.route("/health", web::get().to(health_handler)) .default_service(web::to(middlewares::not_found::not_found)) .wrap(actix_middleware::Logger::default()) From da08ac9e0bcb0853b1f4dbd8d77aa489c2e7f1d3 Mon Sep 17 00:00:00 2001 From: ralvescosta Date: Mon, 20 Feb 2023 15:33:29 -0300 Subject: [PATCH 3/4] feat: openapi --- Cargo.lock | 195 ++++++++++++++++++++++++++++++++++ httpw/Cargo.toml | 2 + httpw/src/server/server.rs | 37 +++---- httpw/src/viewmodels/error.rs | 6 +- 4 files changed, 219 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e2f63be..39e0a29 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1271,6 +1271,26 @@ dependencies = [ "subtle", ] +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "doc-comment" version = "0.3.3" @@ -1708,6 +1728,8 @@ dependencies = [ "serde_json", "thiserror", "tracing", + "utoipa", + "utoipa-swagger-ui", ] [[package]] @@ -1816,6 +1838,7 @@ checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", "hashbrown", + "serde", ] [[package]] @@ -2037,6 +2060,16 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -2588,6 +2621,30 @@ dependencies = [ "syn", ] +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.51" @@ -2720,6 +2777,17 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom", + "redox_syscall", + "thiserror", +] + [[package]] name = "regex" version = "1.7.1" @@ -2818,6 +2886,41 @@ dependencies = [ "smallvec", ] +[[package]] +name = "rust-embed" +version = "6.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "283ffe2f866869428c92e0d61c2f35dfb4355293cdfdc48f49e895c15f1333d1" +dependencies = [ + "rust-embed-impl", + "rust-embed-utils", + "walkdir", +] + +[[package]] +name = "rust-embed-impl" +version = "6.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31ab23d42d71fb9be1b643fe6765d292c5e14d46912d13f3ae2815ca048ea04d" +dependencies = [ + "proc-macro2", + "quote", + "rust-embed-utils", + "shellexpand", + "syn", + "walkdir", +] + +[[package]] +name = "rust-embed-utils" +version = "7.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1669d81dfabd1b5f8e2856b8bbe146c6192b0ba22162edc738ac0a5de18f054" +dependencies = [ + "sha2", + "walkdir", +] + [[package]] name = "rustc_version" version = "0.4.0" @@ -2884,6 +2987,15 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "schannel" version = "0.1.21" @@ -3032,6 +3144,15 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shellexpand" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" +dependencies = [ + "dirs", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -3566,6 +3687,15 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.10" @@ -3616,6 +3746,48 @@ version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8db7427f936968176eaa7cdf81b7f98b980b18495ec28f1b5791ac3bfe3eea9" +[[package]] +name = "utoipa" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15f6da6a2b471134ca44b7d18e8a76d73035cf8b3ed24c4dd5ca6a63aa439c5" +dependencies = [ + "indexmap", + "serde", + "serde_json", + "utoipa-gen", +] + +[[package]] +name = "utoipa-gen" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f2e33027986a4707b3f5c37ed01b33d0e5a53da30204b52ff18f80600f1d0ec" +dependencies = [ + "lazy_static", + "proc-macro-error", + "proc-macro2", + "quote", + "regex", + "syn", +] + +[[package]] +name = "utoipa-swagger-ui" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae3d4f4da6408f0f20ff58196ed619c94306ab32635aeca3d3fa0768c0bd0de2" +dependencies = [ + "actix-web", + "mime_guess", + "regex", + "rust-embed", + "serde", + "serde_json", + "utoipa", + "zip", +] + [[package]] name = "uuid" version = "0.8.2" @@ -3655,6 +3827,17 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" +[[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + [[package]] name = "want" version = "0.3.0" @@ -3916,6 +4099,18 @@ version = "1.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" +[[package]] +name = "zip" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0445d0fbc924bb93539b4316c11afb121ea39296f99a3c4c9edad09e3658cdef" +dependencies = [ + "byteorder", + "crc32fast", + "crossbeam-utils", + "flate2", +] + [[package]] name = "zstd" version = "0.12.3+zstd.1.5.2" diff --git a/httpw/Cargo.toml b/httpw/Cargo.toml index 08e2222..f61c350 100644 --- a/httpw/Cargo.toml +++ b/httpw/Cargo.toml @@ -15,3 +15,5 @@ serde_json = { version = "1.0.93" } tracing = { version = "0.1.37" } opentelemetry = { version = "0.18.0" } actix-web-opentelemetry = { version = "0.13.0", features = ["metrics"] } +utoipa = { version = "3.0.2", features = ["actix_extras"] } +utoipa-swagger-ui = { version = "3.0.2", features = ["actix-web"] } diff --git a/httpw/src/server/server.rs b/httpw/src/server/server.rs index 26b0057..36ef41e 100644 --- a/httpw/src/server/server.rs +++ b/httpw/src/server/server.rs @@ -1,6 +1,7 @@ use super::types::RouteConfig; use crate::{errors::HttpServerError, middlewares}; use actix_web::{ + http::KeepAlive, middleware as actix_middleware, web::{self, Data}, App, HttpResponse, HttpServer, Responder, @@ -9,14 +10,16 @@ use actix_web_opentelemetry::{RequestMetricsBuilder, RequestTracing}; use auth::jwt_manager::JwtManager; use env::AppConfig; use opentelemetry::global; -use std::sync::Arc; +use std::{sync::Arc, time::Duration}; use tracing::error; +use utoipa::openapi::OpenApi; +use utoipa_swagger_ui::SwaggerUi; pub struct HttpwServerImpl { services: Vec, jwt_manager: Option>, addr: String, - // openapi_file_path: Option, + openapi: Option, } impl HttpwServerImpl { @@ -25,7 +28,7 @@ impl HttpwServerImpl { services: vec![], addr: cfg.app_addr(), jwt_manager: None, - // openapi_file_path: None, + openapi: None, } } } @@ -41,16 +44,16 @@ impl HttpwServerImpl { self } - // pub fn openapi_file_path(mut self, file_path: String) -> Self { - // self.openapi_file_path = Some(file_path); - // self - // } + pub fn openapi(mut self, openapi: &OpenApi) -> Self { + self.openapi = Some(openapi.to_owned()); + self + } pub async fn start(&self) -> Result<(), HttpServerError> { HttpServer::new({ let services = self.services.to_vec(); let jwt_manager = self.jwt_manager.clone(); - // let openapi_file = self.openapi_file_path.clone(); + let openapi = self.openapi.clone(); move || { let meter = global::meter("actix_web"); @@ -74,22 +77,20 @@ impl HttpwServerImpl { app = app.configure(svc); } - // if let Some(_openapi) = openapi_file.clone() { - // let spec = swagger_ui::swagger_spec_file!("../../swagger-ui/examples/openapi.json"); - // let config = swagger_ui::Config::default(); - // - // let app = app.service( - // scope("/v1/doc") - // .configure(actix_web_swagger_ui::swagger(spec, config)) - // ); - // - // } + if openapi.is_some() { + app = app.service( + SwaggerUi::new("/docs/{_:.*}") + .url("/docs/openapi.json", openapi.clone().unwrap()), + ); + } app.route("/health", web::get().to(health_handler)) .default_service(web::to(middlewares::not_found::not_found)) .wrap(actix_middleware::Logger::default()) } }) + .shutdown_timeout(60) + .keep_alive(KeepAlive::Timeout(Duration::new(2, 0))) .bind(&self.addr) .map_err(|e| { error!( diff --git a/httpw/src/viewmodels/error.rs b/httpw/src/viewmodels/error.rs index 2f61e33..0cd7f9f 100644 --- a/httpw/src/viewmodels/error.rs +++ b/httpw/src/viewmodels/error.rs @@ -1,8 +1,8 @@ -use std::fmt; - use serde::Serialize; +use std::fmt; +use utoipa::ToSchema; -#[derive(Debug, Default, Serialize)] +#[derive(Debug, Default, Serialize, ToSchema)] pub struct HttpErrorViewModel { pub status_code: u16, pub message: String, From 7bd61d9ad2587167510ec84f40ded696d72c81b0 Mon Sep 17 00:00:00 2001 From: ralvescosta Date: Tue, 21 Feb 2023 16:26:28 -0300 Subject: [PATCH 4/4] feat: remove errors crate --- Cargo.lock | 83 +++++++++---------- Cargo.toml | 1 - amqp/Cargo.toml | 2 +- amqp/src/client.rs | 4 +- amqp/src/consumer.rs | 2 +- amqp/src/dispatcher.rs | 2 +- errors/src/amqp.rs => amqp/src/errors.rs | 0 amqp/src/lib.rs | 1 + amqp/src/mocks.rs | 3 +- amqp/src/topology.rs | 6 +- amqp/src/types.rs | 2 +- auth/src/defs.rs | 3 - auth/src/lib.rs | 2 +- env/Cargo.toml | 2 +- env/src/configs_builder.rs | 2 +- errors/src/configs.rs => env/src/errors.rs | 2 +- env/src/lib.rs | 3 +- errors/Cargo.toml | 7 -- errors/README.md | 1 - errors/src/http_server.rs | 7 -- errors/src/lib.rs | 12 --- errors/src/otel.rs | 13 --- errors/src/protocol.rs | 10 --- errors/src/repositories.rs | 7 -- health_readiness/Cargo.toml | 2 +- .../src/errors.rs | 0 health_readiness/src/lib.rs | 1 + health_readiness/src/mqtt/check.rs | 3 +- health_readiness/src/postgres/check.rs | 3 +- health_readiness/src/rabbitmq/check.rs | 3 +- health_readiness/src/server.rs | 11 ++- health_readiness/src/service.rs | 2 +- logging/Cargo.toml | 5 +- .../src/logging.rs => logging/src/errors.rs | 0 logging/src/lib.rs | 1 + logging/src/logger.rs | 2 +- metrics/Cargo.toml | 2 +- migrator/Cargo.toml | 2 +- .../src/migrator.rs => migrator/src/errors.rs | 0 migrator/src/lib.rs | 1 + migrator/src/postgres.rs | 3 +- migrator/src/service.rs | 2 +- migrator/src/sqlite.rs | 3 +- mqtt/Cargo.toml | 2 +- mqtt/src/builder.rs | 3 +- mqtt/src/client.rs | 3 +- mqtt/src/dispatcher.rs | 4 +- errors/src/mqtt.rs => mqtt/src/errors.rs | 0 mqtt/src/lib.rs | 5 +- mqtt/src/mocks.rs | 6 +- mqtt/src/types.rs | 2 +- secrets_manager/Cargo.toml | 3 +- secrets_manager/src/aws_client.rs | 3 +- secrets_manager/src/aws_client_builder.rs | 3 +- secrets_manager/src/dummy_client.rs | 3 +- .../src/errors.rs | 0 secrets_manager/src/lib.rs | 1 + secrets_manager/src/mocks.rs | 3 +- secrets_manager/src/types.rs | 2 +- sql_pool/Cargo.toml | 11 +-- .../src/sql_pool.rs => sql_pool/src/errors.rs | 0 sql_pool/src/lib.rs | 1 + sql_pool/src/postgres.rs | 2 +- sql_pool/src/sqlite.rs | 2 +- traces/Cargo.toml | 1 + 65 files changed, 103 insertions(+), 180 deletions(-) rename errors/src/amqp.rs => amqp/src/errors.rs (100%) rename errors/src/configs.rs => env/src/errors.rs (86%) delete mode 100644 errors/Cargo.toml delete mode 100644 errors/README.md delete mode 100644 errors/src/http_server.rs delete mode 100644 errors/src/lib.rs delete mode 100644 errors/src/otel.rs delete mode 100644 errors/src/protocol.rs delete mode 100644 errors/src/repositories.rs rename errors/src/health_readiness.rs => health_readiness/src/errors.rs (100%) rename errors/src/logging.rs => logging/src/errors.rs (100%) rename errors/src/migrator.rs => migrator/src/errors.rs (100%) rename errors/src/mqtt.rs => mqtt/src/errors.rs (100%) rename errors/src/secrets_manager.rs => secrets_manager/src/errors.rs (100%) rename errors/src/sql_pool.rs => sql_pool/src/errors.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 39e0a29..af9799b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -332,13 +332,13 @@ version = "0.1.0" dependencies = [ "async-trait", "env", - "errors", "futures-util", "lapin", "mockall", "opentelemetry", "serde", "serde_json", + "thiserror", "tokio", "traces", "tracing", @@ -455,19 +455,20 @@ dependencies = [ [[package]] name = "async-stream" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e" +checksum = "ad445822218ce64be7a341abfb0b1ea43b5c23aa83902542a4542e78309d8e5e" dependencies = [ "async-stream-impl", "futures-core", + "pin-project-lite", ] [[package]] name = "async-stream-impl" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" +checksum = "e4655ae1a7b0cdf149156f780c5bf3f1352bc53cbd9e0a361a7ef7b22947e965" dependencies = [ "proc-macro2", "quote", @@ -806,9 +807,9 @@ dependencies = [ [[package]] name = "axum" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e246206a63c9830e118d12c894f56a82033da1a2361f5544deeee3df85c99d9" +checksum = "2fb79c228270dcf2426e74864cabc94babb5dbab01a4314e702d2f16540e1591" dependencies = [ "async-trait", "axum-core", @@ -1123,9 +1124,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.90" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90d59d9acd2a682b4e40605a242f6670eaa58c5957471cbf85e8aa6a0b97a5e8" +checksum = "86d3488e7665a7a483b57e25bdd90d0aeb2bc7608c8d0346acf2ad3f1caf1d62" dependencies = [ "cc", "cxxbridge-flags", @@ -1135,9 +1136,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.90" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebfa40bda659dd5c864e65f4c9a2b0aff19bea56b017b9b77c73d3766a453a38" +checksum = "48fcaf066a053a41a81dfb14d57d99738b767febb8b735c3016e469fac5da690" dependencies = [ "cc", "codespan-reporting", @@ -1150,15 +1151,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.90" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "457ce6757c5c70dc6ecdbda6925b958aae7f959bda7d8fb9bde889e34a09dc03" +checksum = "a2ef98b8b717a829ca5603af80e1f9e2e48013ab227b68ef37872ef84ee479bf" [[package]] name = "cxxbridge-macro" -version = "1.0.90" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebf883b7aacd7b2aeb2a7b338648ee19f57c140d4ee8e52c68979c6b2f7f2263" +checksum = "086c685979a698443656e5cf7856c95c642295a38599f12fb1ff76fb28d19892" dependencies = [ "proc-macro2", "quote", @@ -1330,16 +1331,9 @@ version = "0.1.0" dependencies = [ "base64 0.13.1", "dotenvy", - "errors", "secrets-manager", - "tracing", -] - -[[package]] -name = "errors" -version = "0.1.0" -dependencies = [ "thiserror", + "tracing", ] [[package]] @@ -1637,10 +1631,10 @@ dependencies = [ "async-trait", "deadpool-postgres", "env", - "errors", "httpw", "lapin", "paho-mqtt", + "thiserror", "tracing", ] @@ -1676,9 +1670,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" dependencies = [ "bytes", "fnv", @@ -2000,7 +1994,7 @@ name = "logging" version = "0.1.0" dependencies = [ "env", - "errors", + "thiserror", "tracing", "tracing-bunyan-formatter", "tracing-log", @@ -2033,7 +2027,6 @@ name = "metrics" version = "0.1.0" dependencies = [ "env", - "errors", "opentelemetry", "opentelemetry-otlp", "tokio", @@ -2049,8 +2042,8 @@ dependencies = [ "deadpool-postgres", "deadpool-sqlite", "env", - "errors", "logging", + "thiserror", "tracing", ] @@ -2087,14 +2080,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" +checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" dependencies = [ "libc", "log", "wasi", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -2131,13 +2124,13 @@ dependencies = [ "async-trait", "bytes", "env", - "errors", "futures-util", "mockall", "opentelemetry", "paho-mqtt", "serde", "serde_json", + "thiserror", "tokio", "traces", "tracing", @@ -2224,9 +2217,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.17.0" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] name = "openssl" @@ -3034,9 +3027,9 @@ dependencies = [ "async-trait", "aws-config", "aws-sdk-secretsmanager", - "errors", "mockall", "serde_json", + "thiserror", "tokio", "tracing", ] @@ -3170,9 +3163,9 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" [[package]] name = "slab" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" dependencies = [ "autocfg", ] @@ -3215,7 +3208,7 @@ dependencies = [ "deadpool-postgres", "deadpool-sqlite", "env", - "errors", + "thiserror", "tokio-postgres", "tracing", ] @@ -3326,9 +3319,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" +checksum = "53250a3b3fed8ff8fd988587d8925d26a83ac3845d9e03b220b37f34c2b8d6c2" dependencies = [ "itoa", "serde", @@ -3344,9 +3337,9 @@ checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" [[package]] name = "time-macros" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2" +checksum = "a460aeb8de6dcb0f381e1ee05f1cd56fcf5a5f6eb8187ff3d8f0b11078d38b7c" dependencies = [ "time-core", ] @@ -3453,9 +3446,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d660770404473ccd7bc9f8b28494a811bc18542b915c0855c51e8f419d5223ce" +checksum = "8fb52b74f05dbf495a8fba459fdc331812b96aa086d9eb78101fa0d4569c3313" dependencies = [ "futures-core", "pin-project-lite", diff --git a/Cargo.toml b/Cargo.toml index 614de52..3a0b247 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,6 @@ members = [ "amqp", "env", - "errors", "health_readiness", "httpw", "logging", diff --git a/amqp/Cargo.toml b/amqp/Cargo.toml index 7b38421..0c784f9 100644 --- a/amqp/Cargo.toml +++ b/amqp/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" mocks = ["dep:mockall"] [dependencies] -errors = { path = "../errors" } env = { path = "../env" } traces = { path = "../traces" } @@ -20,6 +19,7 @@ serde_json = { version = "1.0.91" } serde = { version = "1.0.152", features = ["derive"] } tokio = { version = "1.25.0", features = ["default"] } futures-util = { version = "0.3.26"} +thiserror = { version = "1.0.38" } # Used only with feature mock mockall = { version = "0.11.3", optional = true } diff --git a/amqp/src/client.rs b/amqp/src/client.rs index bcc3ba9..d1a4b77 100644 --- a/amqp/src/client.rs +++ b/amqp/src/client.rs @@ -1,13 +1,11 @@ -use crate::types::PublishParams; - use super::{ defs, topology::ExchangeKind as MyExchangeKind, types::{AmqpPayload, AmqpTracePropagator}, }; +use crate::{errors::AmqpError, types::PublishParams}; use async_trait::async_trait; use env::{Configs, DynamicConfig}; -use errors::amqp::AmqpError; use lapin::{ message::BasicGetMessage, options::{ diff --git a/amqp/src/consumer.rs b/amqp/src/consumer.rs index e9cd87b..c7264e0 100644 --- a/amqp/src/consumer.rs +++ b/amqp/src/consumer.rs @@ -1,9 +1,9 @@ use crate::{ client::Amqp, + errors::AmqpError, topology::{ConsumerHandler, QueueDefinition}, types::{new_span, Metadata}, }; -use errors::amqp::AmqpError; use lapin::{ message::Delivery, options::{BasicAckOptions, BasicNackOptions, BasicPublishOptions}, diff --git a/amqp/src/dispatcher.rs b/amqp/src/dispatcher.rs index d39ad2d..0182955 100644 --- a/amqp/src/dispatcher.rs +++ b/amqp/src/dispatcher.rs @@ -1,9 +1,9 @@ use crate::{ client::Amqp, consumer::consume, + errors::AmqpError, topology::{ConsumerHandler, QueueDefinition}, }; -use errors::amqp::AmqpError; use futures_util::{future::join_all, StreamExt}; use opentelemetry::global; use std::sync::Arc; diff --git a/errors/src/amqp.rs b/amqp/src/errors.rs similarity index 100% rename from errors/src/amqp.rs rename to amqp/src/errors.rs diff --git a/amqp/src/lib.rs b/amqp/src/lib.rs index af737d3..3904962 100644 --- a/amqp/src/lib.rs +++ b/amqp/src/lib.rs @@ -3,6 +3,7 @@ mod consumer; pub mod client; pub mod defs; pub mod dispatcher; +pub mod errors; #[cfg(test)] pub mod mocks; #[cfg(feature = "mocks")] diff --git a/amqp/src/mocks.rs b/amqp/src/mocks.rs index 45b9328..7eedf0f 100644 --- a/amqp/src/mocks.rs +++ b/amqp/src/mocks.rs @@ -2,9 +2,8 @@ use super::{ topology::ExchangeKind as MyExchangeKind, types::{AmqpPayload, PublishParams}, }; -use crate::client::Amqp; +use crate::{client::Amqp, errors::AmqpError}; use async_trait::async_trait; -use errors::amqp::AmqpError; use lapin::{ message::BasicGetMessage, types::{AMQPValue, FieldTable, ShortString}, diff --git a/amqp/src/topology.rs b/amqp/src/topology.rs index 2d849a3..68917c7 100644 --- a/amqp/src/topology.rs +++ b/amqp/src/topology.rs @@ -1,10 +1,8 @@ -use std::{collections::BTreeMap, sync::Arc}; - -use crate::{client::Amqp, defs}; +use crate::{client::Amqp, defs, errors::AmqpError}; use async_trait::async_trait; -use errors::amqp::AmqpError; use lapin::types::{AMQPValue, FieldTable, LongInt, LongString, ShortString}; use opentelemetry::Context; +use std::{collections::BTreeMap, sync::Arc}; use tracing::debug; #[derive(Debug, Clone, Default)] diff --git a/amqp/src/types.rs b/amqp/src/types.rs index baf72d7..c9b9c16 100644 --- a/amqp/src/types.rs +++ b/amqp/src/types.rs @@ -1,5 +1,5 @@ use super::defs; -use errors::amqp::AmqpError; +use crate::errors::AmqpError; use lapin::{ protocol::basic::AMQPProperties, types::{AMQPValue, FieldTable, LongInt, ShortString}, diff --git a/auth/src/defs.rs b/auth/src/defs.rs index 06ca17f..3488f1b 100644 --- a/auth/src/defs.rs +++ b/auth/src/defs.rs @@ -1,11 +1,8 @@ pub enum UsersScopes {} -pub enum ThingsScopes {} - pub enum PlatformScopes {} pub enum Scopes { USER(UsersScopes), - THING(ThingsScopes), PLATFORM(PlatformScopes), } diff --git a/auth/src/lib.rs b/auth/src/lib.rs index 4a95d83..c242d07 100644 --- a/auth/src/lib.rs +++ b/auth/src/lib.rs @@ -2,4 +2,4 @@ mod defs; pub mod jwt_manager; mod types; -pub use defs::{PlatformScopes, Scopes, ThingsScopes, UsersScopes}; +pub use defs::{PlatformScopes, Scopes, UsersScopes}; diff --git a/env/Cargo.toml b/env/Cargo.toml index 436b313..0085dcb 100644 --- a/env/Cargo.toml +++ b/env/Cargo.toml @@ -4,9 +4,9 @@ version = "0.1.0" edition = "2021" [dependencies] -errors = { path = "../errors" } secrets-manager = { path = "../secrets_manager" } dotenvy = { version = "0.15.6" } base64 = { version = "0.13.1" } tracing = { version = "0.1.37" } +thiserror = { version = "1.0.38" } diff --git a/env/src/configs_builder.rs b/env/src/configs_builder.rs index ea4906c..cad8caa 100644 --- a/env/src/configs_builder.rs +++ b/env/src/configs_builder.rs @@ -13,10 +13,10 @@ use crate::{ POSTGRES_PORT_ENV_KEY, POSTGRES_USER_ENV_KEY, SECRET_KEY_ENV_KEY, SECRET_PREFIX, SECRET_PREFIX_TO_DECODE, SQLITE_FILE_NAME_ENV_KEY, }, + errors::ConfigsError, Environment, }; use dotenvy::from_filename; -use errors::configs::ConfigsError; use secrets_manager::{AwsSecretClientBuilder, DummyClient, SecretClient}; use std::{env, sync::Arc}; use tracing::error; diff --git a/errors/src/configs.rs b/env/src/errors.rs similarity index 86% rename from errors/src/configs.rs rename to env/src/errors.rs index 1815162..0b9bb8f 100644 --- a/errors/src/configs.rs +++ b/env/src/errors.rs @@ -6,5 +6,5 @@ pub enum ConfigsError { InternalError, #[error("error to load secrets from secret manager - `{0}`")] - SecretLoadingError(String) + SecretLoadingError(String), } diff --git a/env/src/lib.rs b/env/src/lib.rs index 134a19c..b8aea12 100644 --- a/env/src/lib.rs +++ b/env/src/lib.rs @@ -2,10 +2,11 @@ mod configs; mod configs_builder; pub mod def; mod environment; +pub mod errors; pub use configs::{ AppConfig, AwsConfig, Configs, DynamicConfig, DynamoConfig, Empty, HealthReadinessConfig, MQTTConfig, OTLPConfig, PostgresConfig, SqliteConfig, }; pub use configs_builder::ConfigBuilder; -pub use environment::Environment; \ No newline at end of file +pub use environment::Environment; diff --git a/errors/Cargo.toml b/errors/Cargo.toml deleted file mode 100644 index 715e7fd..0000000 --- a/errors/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "errors" -version = "0.1.0" -edition = "2021" - -[dependencies] -thiserror = { version = "1.0.38" } \ No newline at end of file diff --git a/errors/README.md b/errors/README.md deleted file mode 100644 index 096d372..0000000 --- a/errors/README.md +++ /dev/null @@ -1 +0,0 @@ -# Errors Crate \ No newline at end of file diff --git a/errors/src/http_server.rs b/errors/src/http_server.rs deleted file mode 100644 index 4d91540..0000000 --- a/errors/src/http_server.rs +++ /dev/null @@ -1,7 +0,0 @@ -use thiserror::Error; - -#[derive(Error, Debug, PartialEq, Eq)] -pub enum HttpServerError { - #[error("http server error")] - ServerError, -} diff --git a/errors/src/lib.rs b/errors/src/lib.rs deleted file mode 100644 index 817d166..0000000 --- a/errors/src/lib.rs +++ /dev/null @@ -1,12 +0,0 @@ -pub mod amqp; -pub mod configs; -pub mod health_readiness; -pub mod http_server; -pub mod logging; -pub mod migrator; -pub mod mqtt; -pub mod otel; -pub mod protocol; -pub mod repositories; -pub mod secrets_manager; -pub mod sql_pool; diff --git a/errors/src/otel.rs b/errors/src/otel.rs deleted file mode 100644 index 26c29d9..0000000 --- a/errors/src/otel.rs +++ /dev/null @@ -1,13 +0,0 @@ -use thiserror::Error; - -#[derive(Error, Debug, PartialEq, Eq, Clone)] -pub enum OtelError { - #[error("mqtt internal error")] - InternalError, - - #[error("failed to read proc file")] - ProcFileError, - - #[error("failed to register metric callback")] - MetricCallbackError, -} diff --git a/errors/src/protocol.rs b/errors/src/protocol.rs deleted file mode 100644 index 7133d46..0000000 --- a/errors/src/protocol.rs +++ /dev/null @@ -1,10 +0,0 @@ -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum ProtocolError { - #[error("Internal Error")] - InternalError, - - #[error("str conversion error")] - ConversionError(), -} diff --git a/errors/src/repositories.rs b/errors/src/repositories.rs deleted file mode 100644 index 6475b80..0000000 --- a/errors/src/repositories.rs +++ /dev/null @@ -1,7 +0,0 @@ -use thiserror::Error; - -#[derive(Error, Debug, PartialEq, Eq)] -pub enum RepositoriesError { - #[error("internal error")] - InternalError, -} diff --git a/health_readiness/Cargo.toml b/health_readiness/Cargo.toml index d776f59..d33dc67 100644 --- a/health_readiness/Cargo.toml +++ b/health_readiness/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" edition = "2021" [dependencies] -errors = { path = "../errors" } httpw = { path = "../httpw" } env = { path = "../env" } @@ -14,4 +13,5 @@ deadpool-postgres = { version = "0.10.5" } lapin = { version = "2.1.1" } paho-mqtt = { version = "0.12.0" } actix-web = { version = "4.3.0" } +thiserror = { version = "1.0.38" } diff --git a/errors/src/health_readiness.rs b/health_readiness/src/errors.rs similarity index 100% rename from errors/src/health_readiness.rs rename to health_readiness/src/errors.rs diff --git a/health_readiness/src/lib.rs b/health_readiness/src/lib.rs index 5c78d0d..c2621e0 100644 --- a/health_readiness/src/lib.rs +++ b/health_readiness/src/lib.rs @@ -1,5 +1,6 @@ mod controller; mod dynamodb; +pub mod errors; mod mqtt; mod postgres; mod rabbitmq; diff --git a/health_readiness/src/mqtt/check.rs b/health_readiness/src/mqtt/check.rs index cb5a001..180656c 100644 --- a/health_readiness/src/mqtt/check.rs +++ b/health_readiness/src/mqtt/check.rs @@ -1,5 +1,4 @@ -use crate::HealthChecker; -use errors::health_readiness::HealthReadinessError; +use crate::{errors::HealthReadinessError, HealthChecker}; use paho_mqtt::AsyncClient; use std::sync::Arc; use tracing::debug; diff --git a/health_readiness/src/postgres/check.rs b/health_readiness/src/postgres/check.rs index 94e6f39..8c81628 100644 --- a/health_readiness/src/postgres/check.rs +++ b/health_readiness/src/postgres/check.rs @@ -1,6 +1,5 @@ -use crate::HealthChecker; +use crate::{errors::HealthReadinessError, HealthChecker}; use deadpool_postgres::Pool; -use errors::health_readiness::HealthReadinessError; use std::sync::Arc; use tracing::error; diff --git a/health_readiness/src/rabbitmq/check.rs b/health_readiness/src/rabbitmq/check.rs index a212627..f77e089 100644 --- a/health_readiness/src/rabbitmq/check.rs +++ b/health_readiness/src/rabbitmq/check.rs @@ -1,5 +1,4 @@ -use crate::HealthChecker; -use errors::health_readiness::HealthReadinessError; +use crate::{errors::HealthReadinessError, HealthChecker}; use lapin::Connection; use std::sync::Arc; diff --git a/health_readiness/src/server.rs b/health_readiness/src/server.rs index de29681..7ea8a49 100644 --- a/health_readiness/src/server.rs +++ b/health_readiness/src/server.rs @@ -1,12 +1,11 @@ -use crate::controller; -use crate::postgres::PostgresHealthChecker; -use crate::rabbitmq::RabbitMqHealthChecker; -use crate::HealthReadinessImpl; -use crate::{mqtt::MqttHealthChecker, HealthChecker}; +use crate::{ + controller, errors::HealthReadinessError, mqtt::MqttHealthChecker, + postgres::PostgresHealthChecker, rabbitmq::RabbitMqHealthChecker, HealthChecker, + HealthReadinessImpl, +}; use actix_web::{middleware as actix_middleware, web, App, HttpServer}; use deadpool_postgres::Pool; use env::HealthReadinessConfig; -use errors::health_readiness::HealthReadinessError; use httpw::middlewares; use lapin::Connection; use paho_mqtt::AsyncClient; diff --git a/health_readiness/src/service.rs b/health_readiness/src/service.rs index 0ee0aeb..0a25110 100644 --- a/health_readiness/src/service.rs +++ b/health_readiness/src/service.rs @@ -1,4 +1,4 @@ -use errors::health_readiness::HealthReadinessError; +use crate::errors::HealthReadinessError; use std::sync::Arc; use tracing::error; diff --git a/logging/Cargo.toml b/logging/Cargo.toml index 11b3a4f..228d3b7 100644 --- a/logging/Cargo.toml +++ b/logging/Cargo.toml @@ -4,9 +4,10 @@ version = "0.1.0" edition = "2021" [dependencies] -errors = { path = "../errors" } env = { path = "../env" } + tracing-bunyan-formatter = { version = "0.3.6" } tracing-subscriber = { version = "0.3.16" } tracing-log = { version = "0.1.3" } -tracing = { version = "0.1.37" } \ No newline at end of file +tracing = { version = "0.1.37" } +thiserror = { version = "1.0.38" } \ No newline at end of file diff --git a/errors/src/logging.rs b/logging/src/errors.rs similarity index 100% rename from errors/src/logging.rs rename to logging/src/errors.rs diff --git a/logging/src/lib.rs b/logging/src/lib.rs index 9083675..5588ff9 100644 --- a/logging/src/lib.rs +++ b/logging/src/lib.rs @@ -1,3 +1,4 @@ +pub mod errors; mod logger; pub use logger::setup; diff --git a/logging/src/logger.rs b/logging/src/logger.rs index 7c63d06..9f419a5 100644 --- a/logging/src/logger.rs +++ b/logging/src/logger.rs @@ -1,5 +1,5 @@ +use crate::errors::LoggingError; use env::{AppConfig, Environment}; -use errors::logging::LoggingError; use tracing_bunyan_formatter::BunyanFormattingLayer; use tracing_log::LogTracer; use tracing_subscriber::{ diff --git a/metrics/Cargo.toml b/metrics/Cargo.toml index a5828c7..6f677c4 100644 --- a/metrics/Cargo.toml +++ b/metrics/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] env = { path = "../env" } -errors = { path = "../errors" } + opentelemetry = { version = "0.18.0", features = ["rt-tokio", "metrics"] } opentelemetry-otlp = { version = "0.11.0", features = ["tonic", "metrics", "grpc-tonic" , "tls", "tls-roots"] } tracing = { version = "0.1.37" } diff --git a/migrator/Cargo.toml b/migrator/Cargo.toml index 8b59fe0..ad3f52e 100644 --- a/migrator/Cargo.toml +++ b/migrator/Cargo.toml @@ -10,10 +10,10 @@ sqlite = ["dep:deadpool-sqlite"] [dependencies] env = { path = "../env" } logging = { path = "../logging" } -errors = { path = "../errors" } async-trait = { version = "0.1.64" } tracing = { version = "0.1.37" } +thiserror = { version = "1.0.38" } deadpool-postgres = { version = "0.10.2", optional = true } deadpool-sqlite = { version = "0.5.0", optional = true } \ No newline at end of file diff --git a/errors/src/migrator.rs b/migrator/src/errors.rs similarity index 100% rename from errors/src/migrator.rs rename to migrator/src/errors.rs diff --git a/migrator/src/lib.rs b/migrator/src/lib.rs index b776c3f..64ff91d 100644 --- a/migrator/src/lib.rs +++ b/migrator/src/lib.rs @@ -1,3 +1,4 @@ +pub mod errors; #[cfg(feature = "postgres")] mod postgres; mod service; diff --git a/migrator/src/postgres.rs b/migrator/src/postgres.rs index 340dc33..d092923 100644 --- a/migrator/src/postgres.rs +++ b/migrator/src/postgres.rs @@ -1,7 +1,6 @@ -use crate::service::MigratorDriver; +use crate::{errors::MigrationError, service::MigratorDriver}; use async_trait::async_trait; use deadpool_postgres::{tokio_postgres::error::SqlState, Object, Pool}; -use errors::migrator::MigrationError; use std::{fs, sync::Arc}; use tracing::{debug, error}; diff --git a/migrator/src/service.rs b/migrator/src/service.rs index 7446e60..22aa5a1 100644 --- a/migrator/src/service.rs +++ b/migrator/src/service.rs @@ -1,5 +1,5 @@ +use crate::errors::MigrationError; use async_trait::async_trait; -use errors::migrator::MigrationError; use std::sync::Arc; #[async_trait] diff --git a/migrator/src/sqlite.rs b/migrator/src/sqlite.rs index f947e8d..fe8fb64 100644 --- a/migrator/src/sqlite.rs +++ b/migrator/src/sqlite.rs @@ -1,7 +1,6 @@ -use crate::service::MigratorDriver; +use crate::{errors::MigrationError, service::MigratorDriver}; use async_trait::async_trait; use deadpool_sqlite::{rusqlite::ErrorCode, Object, Pool}; -use errors::migrator::MigrationError; use std::{fs, sync::Arc}; use tracing::{debug, error, warn}; diff --git a/mqtt/Cargo.toml b/mqtt/Cargo.toml index 36c251d..258e481 100644 --- a/mqtt/Cargo.toml +++ b/mqtt/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" mocks = ["dep:mockall"] [dependencies] -errors = { path = "../errors" } env = { path = "../env" } traces = { path = "../traces" } @@ -19,6 +18,7 @@ paho-mqtt = { version = "0.12.0" } serde = { version = "1.0.152", features = ["derive"] } serde_json = { version = "1.0.93" } futures-util = { version = "0.3.26" } +thiserror = { version = "1.0.38" } # Used only with feature mock mockall = { version = "0.11.3", optional = true } diff --git a/mqtt/src/builder.rs b/mqtt/src/builder.rs index b4fd4c9..02b5e9c 100644 --- a/mqtt/src/builder.rs +++ b/mqtt/src/builder.rs @@ -1,6 +1,5 @@ -use crate::{types::BrokerKind, MqttClientImpl}; +use crate::{errors::MqttError, types::BrokerKind, MqttClientImpl}; use env::{AppConfig, Configs, DynamicConfig, MQTTConfig}; -use errors::mqtt::MqttError; use paho_mqtt::{ AsyncClient, ConnectOptions, ConnectOptionsBuilder, CreateOptions, CreateOptionsBuilder, SslOptionsBuilder, SslVersion, diff --git a/mqtt/src/client.rs b/mqtt/src/client.rs index 6c5c798..0802791 100644 --- a/mqtt/src/client.rs +++ b/mqtt/src/client.rs @@ -1,6 +1,5 @@ -use crate::types::MqttPayload; +use crate::{errors::MqttError, types::MqttPayload}; use async_trait::async_trait; -use errors::mqtt::MqttError; use paho_mqtt::{AsyncClient, AsyncReceiver, Message, MessageBuilder}; use std::sync::Arc; use tracing::{debug, error}; diff --git a/mqtt/src/dispatcher.rs b/mqtt/src/dispatcher.rs index 84946bc..0d2b2d2 100644 --- a/mqtt/src/dispatcher.rs +++ b/mqtt/src/dispatcher.rs @@ -1,8 +1,8 @@ use crate::{ client::MqttClient, + errors::MqttError, types::{Controller, TopicMessage}, }; -use errors::mqtt::MqttError; use futures_util::StreamExt; use opentelemetry::{ global::{self, BoxedTracer}, @@ -165,8 +165,8 @@ mod tests { use std::vec; use super::*; + use crate::errors::MqttError; use async_trait::async_trait; - use errors::mqtt::MqttError; #[test] fn test_new() { diff --git a/errors/src/mqtt.rs b/mqtt/src/errors.rs similarity index 100% rename from errors/src/mqtt.rs rename to mqtt/src/errors.rs diff --git a/mqtt/src/lib.rs b/mqtt/src/lib.rs index a9f3da1..c7f386d 100644 --- a/mqtt/src/lib.rs +++ b/mqtt/src/lib.rs @@ -1,12 +1,13 @@ -mod client; mod builder; +mod client; pub mod dispatcher; +pub mod errors; #[cfg(test)] pub mod mocks; #[cfg(feature = "mocks")] pub mod mocks; pub mod types; +pub use builder::MqttClientBuilder; pub use client::{MqttClient, MqttClientImpl}; -pub use builder::{MqttClientBuilder}; diff --git a/mqtt/src/mocks.rs b/mqtt/src/mocks.rs index d930ce9..1bfaf04 100644 --- a/mqtt/src/mocks.rs +++ b/mqtt/src/mocks.rs @@ -1,10 +1,8 @@ -use std::sync::Arc; - -use crate::{client::MqttClient, types::MqttPayload}; +use crate::{client::MqttClient, errors::MqttError, types::MqttPayload}; use async_trait::async_trait; -use errors::mqtt::MqttError; use mockall::*; use paho_mqtt::{AsyncClient, AsyncReceiver, Message}; +use std::sync::Arc; mock! { pub MqttClientImpl{} diff --git a/mqtt/src/types.rs b/mqtt/src/types.rs index d7b7d43..2d67b88 100644 --- a/mqtt/src/types.rs +++ b/mqtt/src/types.rs @@ -1,5 +1,5 @@ +use crate::errors::MqttError; use async_trait::async_trait; -use errors::mqtt::MqttError; use opentelemetry::Context; use serde::{Deserialize, Serialize}; use tracing::error; diff --git a/secrets_manager/Cargo.toml b/secrets_manager/Cargo.toml index 72b668c..51709eb 100644 --- a/secrets_manager/Cargo.toml +++ b/secrets_manager/Cargo.toml @@ -7,13 +7,12 @@ edition = "2021" mocks = ["dep:mockall"] [dependencies] -errors = { path = "../errors" } - async-trait = { version = "0.1.64" } tracing = { version = "0.1.37" } aws-config = { version = "0.51.0" } aws-sdk-secretsmanager = { version = "0.21.0" } serde_json = { version = "1.0.91" } +thiserror = { version = "1.0.38" } # Used only with feature mock mockall = { version = "0.11.3", optional = true } diff --git a/secrets_manager/src/aws_client.rs b/secrets_manager/src/aws_client.rs index 72789be..2dbda0e 100644 --- a/secrets_manager/src/aws_client.rs +++ b/secrets_manager/src/aws_client.rs @@ -1,5 +1,4 @@ -use crate::SecretClient; -use errors::secrets_manager::SecretsManagerError; +use crate::{errors::SecretsManagerError, SecretClient}; use serde_json::Value; use tracing::error; diff --git a/secrets_manager/src/aws_client_builder.rs b/secrets_manager/src/aws_client_builder.rs index 1413a0d..f65696e 100644 --- a/secrets_manager/src/aws_client_builder.rs +++ b/secrets_manager/src/aws_client_builder.rs @@ -1,6 +1,5 @@ -use crate::AwsSecretClient; +use crate::{errors::SecretsManagerError, AwsSecretClient}; use aws_sdk_secretsmanager as secretsmanager; -use errors::secrets_manager::SecretsManagerError; use secretsmanager::Client; use serde_json::Value; use tracing::error; diff --git a/secrets_manager/src/dummy_client.rs b/secrets_manager/src/dummy_client.rs index 1e7d2c2..db467b6 100644 --- a/secrets_manager/src/dummy_client.rs +++ b/secrets_manager/src/dummy_client.rs @@ -1,5 +1,4 @@ -use crate::SecretClient; -use errors::secrets_manager::SecretsManagerError; +use crate::{errors::SecretsManagerError, SecretClient}; pub struct DummyClient; diff --git a/errors/src/secrets_manager.rs b/secrets_manager/src/errors.rs similarity index 100% rename from errors/src/secrets_manager.rs rename to secrets_manager/src/errors.rs diff --git a/secrets_manager/src/lib.rs b/secrets_manager/src/lib.rs index 3e924fd..13c752c 100644 --- a/secrets_manager/src/lib.rs +++ b/secrets_manager/src/lib.rs @@ -2,6 +2,7 @@ mod aws_client; mod aws_client_builder; mod dummy_client; +pub mod errors; #[cfg(test)] pub mod mocks; #[cfg(feature = "mocks")] diff --git a/secrets_manager/src/mocks.rs b/secrets_manager/src/mocks.rs index e74bfc7..7c25b68 100644 --- a/secrets_manager/src/mocks.rs +++ b/secrets_manager/src/mocks.rs @@ -1,6 +1,5 @@ -use crate::SecretClient; +use crate::{errors::SecretsManagerError, SecretClient}; use async_trait::async_trait; -use errors::secrets_manager::SecretsManagerError; use mockall::*; mock! { diff --git a/secrets_manager/src/types.rs b/secrets_manager/src/types.rs index a0ec3d4..d745c33 100644 --- a/secrets_manager/src/types.rs +++ b/secrets_manager/src/types.rs @@ -1,5 +1,5 @@ +use crate::errors::SecretsManagerError; use async_trait::async_trait; -use errors::secrets_manager::SecretsManagerError; #[async_trait] pub trait SecretClient { diff --git a/sql_pool/Cargo.toml b/sql_pool/Cargo.toml index 060f295..33fcb4c 100644 --- a/sql_pool/Cargo.toml +++ b/sql_pool/Cargo.toml @@ -9,12 +9,13 @@ sqlite = ["dep:deadpool-sqlite"] [dependencies] env = { path = "../env" } -errors = { path = "../errors" } + +tracing = { version = "0.1.37" } +thiserror = { version = "1.0.38" } + ## -deadpool-postgres = { version = "0.10.2", optional = true } +deadpool-postgres = { version = "0.10.5", optional = true } tokio-postgres = { version = "0.7.7", features = ["with-chrono-0_4", "with-uuid-0_8"], optional = true } ## -deadpool-sqlite = { version = "0.5.0", optional = true } - -tracing = { version = "0.1.37" } \ No newline at end of file +deadpool-sqlite = { version = "0.5.0", optional = true } \ No newline at end of file diff --git a/errors/src/sql_pool.rs b/sql_pool/src/errors.rs similarity index 100% rename from errors/src/sql_pool.rs rename to sql_pool/src/errors.rs diff --git a/sql_pool/src/lib.rs b/sql_pool/src/lib.rs index 34efed9..5ec0822 100644 --- a/sql_pool/src/lib.rs +++ b/sql_pool/src/lib.rs @@ -1,3 +1,4 @@ +pub mod errors; #[cfg(feature = "postgres")] pub mod postgres; #[cfg(feature = "sqlite")] diff --git a/sql_pool/src/postgres.rs b/sql_pool/src/postgres.rs index d982f52..073c6f4 100644 --- a/sql_pool/src/postgres.rs +++ b/sql_pool/src/postgres.rs @@ -1,6 +1,6 @@ +use crate::errors::SqlPoolError; use deadpool_postgres::{Manager, ManagerConfig, Pool, RecyclingMethod}; use env::PostgresConfig; -use errors::sql_pool::SqlPoolError; use tokio_postgres::NoTls; use tracing::error; diff --git a/sql_pool/src/sqlite.rs b/sql_pool/src/sqlite.rs index 1720905..bf8ddbc 100644 --- a/sql_pool/src/sqlite.rs +++ b/sql_pool/src/sqlite.rs @@ -1,6 +1,6 @@ +use crate::errors::SqlPoolError; use deadpool_sqlite::{Config, Pool, Runtime}; use env::SqliteConfig; -use errors::sql_pool::SqlPoolError; use tracing::error; pub fn conn_pool(cfg: &SqliteConfig) -> Result { diff --git a/traces/Cargo.toml b/traces/Cargo.toml index 0046443..fe6abcb 100644 --- a/traces/Cargo.toml +++ b/traces/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] env = { path = "../env" } + opentelemetry = { version = "0.18.0", features = ["rt-tokio"] } opentelemetry-otlp = { version = "0.11.0", features = ["tonic", "tls", "tls-roots"] } tracing = { version = "0.1.37" }