Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #13 from ralvescosta/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ralvescosta authored Feb 5, 2023
2 parents 7c1302d + 4cfed98 commit b0b5775
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 124 deletions.
8 changes: 4 additions & 4 deletions amqp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ traces = { path = "../traces" }

lapin = { version = "2.1.1" }
opentelemetry = { version = "0.18.0" }
uuid = { version = "1.2.2", features = ["v4"] }
async-trait = { version = "0.1.63" }
uuid = { version = "1.3.0", features = ["v4"] }
async-trait = { version = "0.1.64" }
tracing = { version = "0.1.37" }
serde_json = { version = "1.0.91" }
serde = { version = "1.0.152", features = ["derive"] }
tokio = { version = "1.24.2", features = ["default"] }
futures-util = { version = "0.3.25"}
tokio = { version = "1.25.0", features = ["default"] }
futures-util = { version = "0.3.26"}

# Used only with feature mock
mockall = { version = "0.11.3", optional = true }
Expand Down
5 changes: 4 additions & 1 deletion env/src/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ pub struct Configs<T: DynamicConfig> {
pub health_readiness: HealthReadinessConfig,

pub dynamic: T,

///Default: 15000
pub multiple_message_timer: i32,
}

pub trait DynamicConfig: Default {
fn load(&self);
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, Copy)]
pub struct Empty;
impl DynamicConfig for Empty {
fn load(&self) {}
Expand Down
16 changes: 8 additions & 8 deletions env/src/configs_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crate::{
configs::{AppConfig, Configs, DynamicConfig},
def::{
AMQP_HOST_ENV_KEY, AMQP_PASSWORD_ENV_KEY, AMQP_PORT_ENV_KEY, AMQP_USER_ENV_KEY,
AMQP_VHOST_ENV_KEY, APP_NAME_ENV_KEY, APP_PORT_ENV_KEY, AWS_ACCESS_KEY_ID_ENV_KEY,
AWS_DEFAULT_REGION, AWS_REGION_ENV_KEY_ENV_KEY, AWS_SECRET_ACCESS_KEY,
DYNAMO_ENDPOINT_ENV_KEY, DYNAMO_TABLE_ENV_KEY, ENABLE_HEALTH_READINESS_ENV_KEY,
AMQP_VHOST_ENV_KEY, APP_NAME_ENV_KEY, APP_PORT_ENV_KEY, AWS_DEFAULT_REGION,
CUSTOM_AWS_ACCESS_KEY_ID_ENV_KEY, CUSTOM_AWS_SECRET_ACCESS_KEY, DYNAMO_ENDPOINT_ENV_KEY,
DYNAMO_REGION_ENV_KEY, DYNAMO_TABLE_ENV_KEY, ENABLE_HEALTH_READINESS_ENV_KEY,
ENABLE_METRICS_ENV_KEY, ENABLE_TRACES_ENV_KEY, HEALTH_READINESS_PORT_ENV_KEY,
HOST_NAME_ENV_KEY, LOG_LEVEL_ENV_KEY, MQTT_HOST_ENV_KEY, MQTT_PASSWORD_ENV_KEY,
MQTT_PORT_ENV_KEY, MQTT_USER_ENV_KEY, OTLP_ACCESS_KEY_ENV_KEY, OTLP_EXPORT_TIMEOUT_ENV_KEY,
Expand Down Expand Up @@ -117,7 +117,7 @@ impl ConfigBuilder {

let name = env::var(APP_NAME_ENV_KEY).unwrap_or_default();
let secret_key = env::var(SECRET_KEY_ENV_KEY).unwrap_or_default();
let host = env::var(APP_PORT_ENV_KEY).unwrap_or_default();
let host = env::var(HOST_NAME_ENV_KEY).unwrap_or_default();
let port = env::var(APP_PORT_ENV_KEY)
.unwrap_or("3000".to_owned())
.parse()
Expand Down Expand Up @@ -181,6 +181,7 @@ impl ConfigBuilder {
T: DynamicConfig,
{
let mut cfg = Configs::default();
cfg.app = self.app_cfg.clone();

for (key, value) in env::vars() {
match key.as_str() {
Expand Down Expand Up @@ -271,15 +272,14 @@ impl ConfigBuilder {
DYNAMO_TABLE_ENV_KEY if self.dynamo => {
cfg.dynamo.table = self.get_string_from_secret(value, "table".to_owned());
}
AWS_REGION_ENV_KEY_ENV_KEY => {
DYNAMO_REGION_ENV_KEY if self.dynamo => {
let region = self.get_string_from_secret(value, AWS_DEFAULT_REGION.to_owned());
cfg.dynamo.region = region.clone();
cfg.aws.region = region;
}
AWS_ACCESS_KEY_ID_ENV_KEY if self.aws => {
CUSTOM_AWS_ACCESS_KEY_ID_ENV_KEY if self.aws => {
cfg.aws.access_key_id = self.get_string_from_secret(value, "key".to_owned());
}
AWS_SECRET_ACCESS_KEY if self.aws => {
CUSTOM_AWS_SECRET_ACCESS_KEY if self.aws => {
cfg.aws.secret_access_key =
self.get_string_from_secret(value, "secret".to_owned());
}
Expand Down
6 changes: 3 additions & 3 deletions env/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ pub const POSTGRES_PASSWORD_ENV_KEY: &str = "POSTGRES_PASSWORD";
pub const POSTGRES_DB_ENV_KEY: &str = "POSTGRES_DB";
pub const DYNAMO_ENDPOINT_ENV_KEY: &str = "DYNAMO_ENDPOINT";
pub const DYNAMO_TABLE_ENV_KEY: &str = "DYNAMO_TABLE";
pub const AWS_ACCESS_KEY_ID_ENV_KEY: &str = "AWS_ACCESS_KEY_ID";
pub const AWS_SECRET_ACCESS_KEY: &str = "AWS_SECRET_ACCESS_KEY";
pub const AWS_REGION_ENV_KEY_ENV_KEY: &str = "AWS_REGION";
pub const DYNAMO_REGION_ENV_KEY: &str = "DYNAMO_REGION";
pub const CUSTOM_AWS_ACCESS_KEY_ID_ENV_KEY: &str = "CUSTOM_AWS_ACCESS_KEY_ID";
pub const CUSTOM_AWS_SECRET_ACCESS_KEY: &str = "CUSTOM_AWS_SECRET_ACCESS_KEY";
pub const HEALTH_READINESS_PORT_ENV_KEY: &str = "HEALTH_READINESS_PORT";
pub const ENABLE_HEALTH_READINESS_ENV_KEY: &str = "ENABLE_HEALTH_READINESS";
pub const SQLITE_FILE_NAME_ENV_KEY: &str = "SQLITE_FILE_NAME";
Expand Down
2 changes: 1 addition & 1 deletion env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pub use configs::{
MQTTConfig, OTLPConfig, PostgresConfig, SqliteConfig,
};
pub use configs_builder::ConfigBuilder;
pub use environment::Environment;
pub use environment::Environment;
2 changes: 1 addition & 1 deletion errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
thiserror = { version = "1.0.37" }
thiserror = { version = "1.0.38" }
6 changes: 3 additions & 3 deletions health_readiness/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ errors = { path = "../errors" }
httpw = { path = "../httpw" }
env = { path = "../env" }

async-trait = { version = "0.1.63" }
async-trait = { version = "0.1.64" }
tracing = { version = "0.1.37" }
deadpool-postgres = { version = "0.10.4" }
deadpool-postgres = { version = "0.10.5" }
lapin = { version = "2.1.1" }
paho-mqtt = { version = "0.12" }
paho-mqtt = { version = "0.12.0" }
actix-web = { version = "4.3.0" }

2 changes: 1 addition & 1 deletion metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ 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" }
tonic = { version = "0.8.3", features = ["tls"] }
tokio = { version = "1.24.2", features = ["default"] }
tokio = { version = "1.25.0", features = ["default"] }
2 changes: 1 addition & 1 deletion migrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env = { path = "../env" }
logging = { path = "../logging" }
errors = { path = "../errors" }

async-trait = { version = "0.1.63" }
async-trait = { version = "0.1.64" }
tracing = { version = "0.1.37" }

deadpool-postgres = { version = "0.10.2", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions mqtt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ env = { path = "../env" }
traces = { path = "../traces" }
opentelemetry = { version = "0.18.0" }
tracing = { version = "0.1.37" }
async-trait = { version = "0.1.63" }
async-trait = { version = "0.1.64" }
bytes = { version = "1.2.1", features = ["serde"] }
paho-mqtt = { version = "0.12" }
paho-mqtt = { version = "0.12.0" }
serde = { version = "1.0.152", features = ["derive"] }
serde_json = { version = "1.0.91" }
futures-util = { version = "0.3.25" }
Expand Down
4 changes: 2 additions & 2 deletions secrets_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mocks = ["dep:mockall"]
[dependencies]
errors = { path = "../errors" }

async-trait = { version = "0.1.63" }
async-trait = { version = "0.1.64" }
tracing = { version = "0.1.37" }
aws-config = { version = "0.51.0" }
aws-sdk-secretsmanager = { version = "0.21.0" }
Expand All @@ -20,4 +20,4 @@ mockall = { version = "0.11.3", optional = true }

[dev-dependencies]
mockall = { version = "0.11.3" }
tokio = { version = "1.24.2", features = ["macros"] }
tokio = { version = "1.25.0", features = ["macros"] }
1 change: 1 addition & 0 deletions sql_pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ errors = { path = "../errors" }
##
deadpool-postgres = { version = "0.10.2", 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" }
2 changes: 1 addition & 1 deletion traces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ opentelemetry-otlp = { version = "0.11.0", features = ["tonic", "tls", "tls-root
tracing = { version = "0.1.37" }
serde = { version = "1.0.152", features = ["derive"] }
tonic = { version = "0.8.1", features = ["tls"] }
tokio = { version = "1.24.2", features = ["default"] }
tokio = { version = "1.25.0", features = ["default"] }
93 changes: 0 additions & 93 deletions traces/src/amqp.rs

This file was deleted.

53 changes: 53 additions & 0 deletions traces/src/grpc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use opentelemetry::{
global::{self, BoxedSpan, BoxedTracer},
propagation::{Extractor, Injector},
trace::Tracer,
Context,
};

pub struct ExMetadataMap<'a>(&'a tonic::metadata::MetadataMap);

impl<'a> Extractor for ExMetadataMap<'a> {
/// Get a value for a key from the MetadataMap. If the value can't be converted to &str, returns None
fn get(&self, key: &str) -> Option<&str> {
self.0.get(key).and_then(|metadata| metadata.to_str().ok())
}

/// Collect all the keys from the MetadataMap.
fn keys(&self) -> Vec<&str> {
self.0
.keys()
.map(|key| match key {
tonic::metadata::KeyRef::Ascii(v) => v.as_str(),
tonic::metadata::KeyRef::Binary(v) => v.as_str(),
})
.collect::<Vec<_>>()
}
}

pub struct InjMetadataMap<'a>(&'a mut tonic::metadata::MetadataMap);

impl<'a> Injector for InjMetadataMap<'a> {
/// Set a key and value in the MetadataMap. Does nothing if the key or value are not valid inputs
fn set(&mut self, key: &str, value: String) {
if let Ok(key) = tonic::metadata::MetadataKey::from_bytes(key.as_bytes()) {
if let Ok(val) = tonic::metadata::MetadataValue::try_from(&value) {
self.0.insert(key, val);
}
}
}
}

pub fn span(meta: &tonic::metadata::MetadataMap, tracer: &BoxedTracer) -> (Context, BoxedSpan) {
let ctx = global::get_text_map_propagator(|prop| prop.extract(&ExMetadataMap(meta)));

let span = tracer.start_with_context("Processing reply", &ctx);

(ctx, span)
}

pub fn inject(ctx: &Context, meta: &mut tonic::metadata::MetadataMap) {
global::get_text_map_propagator(|propagator| {
propagator.inject_context(&ctx, &mut InjMetadataMap(meta))
});
}
4 changes: 1 addition & 3 deletions traces/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
///deprecated
pub mod amqp;

pub mod grpc;
pub mod jaeger;
pub mod otlp;

Expand Down

0 comments on commit b0b5775

Please sign in to comment.