Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove git repo deps #193

Merged
merged 5 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,463 changes: 873 additions & 590 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 7 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,13 @@ video-transcoder = { path = "video/transcoder" }
binary-helper = { path = "binary-helper" }
ffmpeg = { path = "ffmpeg" }

[patch."https://github.com/tokio-rs/tracing.git"]
tracing = { git = "https://github.com/ScuffleTV/tracing" }
tracing-subscriber = { git = "https://github.com/ScuffleTV/tracing" }
tracing-log = { git = "https://github.com/ScuffleTV/tracing" }

# These patches are pending PRs to the upstream crates
# TODO: Remove these once the PRs are merged
[patch.crates-io]
jwt = { git = "https://github.com/ScuffleTV/rust-jwt", branch = "troy/fixes" }

[patch."https://github.com/async-graphql/async-graphql.git"]
# https://github.com/async-graphql/async-graphql/pull/1424
async-graphql = { git = "https://github.com/ScuffleTV/async-graphql.git", branch = "troy/union-generics" }

[patch."https://github.com/aembke/fred.rs.git"]
fred = { git = "https://github.com/ScuffleTV/fred.rs.git", branch = "troy/rustls-bump" }

[patch."https://github.com/durch/rust-s3.git"]
rust-s3 = { git = "https://github.com/ScuffleTV/rust-s3.git", branch = "troy/rustls" }
# https://github.com/aembke/fred.rs/pull/199
fred = { version = "8.0.0", git = "https://github.com/aembke/fred.rs.git", branch = "feat/unix-sockets" }
# https://github.com/madonoharu/tsify/pull/32
tsify = { git = "https://github.com/ScuffleTV/tsify.git", branch = "sisou/comments" }
4 changes: 2 additions & 2 deletions binary-helper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.0.1"
edition = "2021"

[dependencies]
tracing = { version = "0.2", git = "https://github.com/tokio-rs/tracing.git" }
tracing = "0.1"
thiserror = "1.0"
tokio = { version = "1.35", features = ["full"] }
serde = { version = "1.0.1", features = ["derive"] }
Expand All @@ -19,7 +19,7 @@ async-stream = "0.3"
futures-util = "0.3"
rustls = "0.22"
rustls-pemfile = "2.0"
fred = { git = "https://github.com/aembke/fred.rs.git", features = ["enable-rustls", "sentinel-client", "dns"] }
fred = { version = "8.0.0", features = ["enable-rustls", "sentinel-client", "dns"] }

config = { workspace = true }
common = { workspace = true, features = ["default"] }
Expand Down
19 changes: 12 additions & 7 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,34 @@ signal = ["tokio/signal", "tokio/process"]
macros = []
database = ["dep:sqlx", "dep:sqlx-postgres", "dep:prost", "dep:uuid", "dep:ulid"]
dataloader = ["dep:fnv", "dep:futures-util", "dep:futures-channel"]
config = ["dep:config", "dep:serde", "logging", "dep:rust-s3"]
config = ["dep:config", "dep:serde", "logging"]
ratelimiter = ["dep:fred"]
global = ["context", "dep:fred", "dep:sqlx", "dep:async-nats"]
http = ["dep:hyper", "dep:serde_json", "dep:bytes", "dep:http-body-util", "dep:pin-project", "dep:path-tree"]
task = ["dep:tokio", "dep:thiserror"]
s3 = ["dep:aws-sdk-s3", "dep:aws-credential-types", "dep:aws-config", "dep:aws-smithy-types", "dep:http-body"]

default = ["logging", "grpc", "context", "prelude", "signal", "macros", "config", "dataloader", "database", "ratelimiter", "global", "http", "task"]
default = ["logging", "grpc", "context", "prelude", "signal", "macros", "config", "dataloader", "database", "ratelimiter", "global", "http", "task", "s3"]

[dependencies]
log = { version = "0.4", optional = true }
http = { version = "1.0", optional = true }
tower = { version = "0.4", optional = true }
config = { workspace = true, optional = true }
futures = { version = "0.3", optional = true }
tracing = { version = "0.2", optional = true, git = "https://github.com/tokio-rs/tracing.git" }
tracing = { version = "0.1", optional = true }
arc-swap = { version = "1.6", optional = true }
tokio-util = { version = "0.7", optional = true }
async-trait = { version = "0.1", optional = true }
tonic = { version = "0.10", features = ["tls"], optional = true }
tokio = { version = "1.35", features = ["sync", "rt"], optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
tracing-log = { version = "0.2", features = ["env_logger"], optional = true, git = "https://github.com/tokio-rs/tracing.git" }
tracing-log = { version = "0.2", optional = true }
once_cell = { version = "1.19", optional = true }
trust-dns-resolver = { version = "0.23", features = ["tokio-runtime"], optional = true }
tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter", "json"], optional = true, git = "https://github.com/tokio-rs/tracing.git" }
tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter", "json"], optional = true }
thiserror = { version = "1.0", optional = true }
fred = { git = "https://github.com/aembke/fred.rs.git", optional = true }
fred = { version = "8.0.0", optional = true }
async-nats = { version = "0.33", optional = true }
hyper = { version = "1.1", optional = true }
serde_json = { version = "1.0", optional = true }
Expand All @@ -61,7 +62,11 @@ prost = { version = "0.12", optional = true }
uuid = { version = "1.6", features = ["v4"], optional = true }
ulid = { version = "1.1", features = ["uuid"], optional = true}

rust-s3 = { git = "https://github.com/durch/rust-s3.git", default-features = false, features = ["tags", "tokio-rustls-tls", "fail-on-err"], optional = true }
aws-config = { version = "1.1", optional = true }
aws-sdk-s3 = { version = "1.12", optional = true }
aws-credential-types = { version = "1.1", optional = true, features = ["hardcoded-credentials"] }
aws-smithy-types = { version = "1.1", features = ["http-body-1-x"], optional = true }
http-body = { version = "1.0.0", optional = true }

[dev-dependencies]
ulid = "1.1"
Expand Down
34 changes: 1 addition & 33 deletions common/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::net::SocketAddr;
use std::sync::Arc;

use s3::Region;

use crate::logging;

#[derive(Debug, Clone, Default, PartialEq, config::Config, serde::Deserialize)]
Expand Down Expand Up @@ -174,18 +172,6 @@ pub struct S3CredentialsConfig {
pub secret_key: Option<String>,
}

impl From<S3CredentialsConfig> for s3::creds::Credentials {
fn from(value: S3CredentialsConfig) -> Self {
Self {
access_key: value.access_key,
secret_key: value.secret_key,
security_token: None,
session_token: None,
expiration: None,
}
}
}

#[derive(Debug, Clone, PartialEq, config::Config, serde::Deserialize)]
#[serde(default)]
pub struct S3BucketConfig {
Expand All @@ -206,31 +192,13 @@ impl Default for S3BucketConfig {
fn default() -> Self {
Self {
name: "scuffle-image-processor".to_owned(),
region: Region::UsEast1.to_string(),
region: "us-east-1".to_owned(),
endpoint: Some("http://localhost:9000".to_string()),
credentials: S3CredentialsConfig::default(),
}
}
}

impl S3BucketConfig {
pub fn setup(&self) -> Option<s3::Bucket> {
let region = if let Some(endpoint) = &self.endpoint {
s3::Region::Custom {
region: self.region.clone(),
endpoint: endpoint.to_string(),
}
} else {
self.region.parse().ok()?
};
Some(
s3::Bucket::new(&self.name, region, self.credentials.clone().into())
.expect("failed to create s3 bucket")
.with_path_style(),
)
}
}

pub fn parse<'de, C: config::Config + serde::Deserialize<'de> + 'static>(
enable_cli: bool,
config_file: Option<String>,
Expand Down
8 changes: 4 additions & 4 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ pub mod signal;
pub mod macros;
#[cfg(feature = "global")]
pub mod global;
#[cfg(feature = "ratelimiter")]
pub mod ratelimiter;

#[cfg(feature = "http")]
pub mod http;

#[cfg(feature = "ratelimiter")]
pub mod ratelimiter;
#[cfg(feature = "s3")]
pub mod s3;
#[cfg(feature = "task")]
pub mod task;

Expand Down
93 changes: 76 additions & 17 deletions common/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use std::str::FromStr;

use once_cell::sync::OnceCell;
use tracing_subscriber::prelude::*;
use tracing_subscriber::reload::Handle;
use tracing_subscriber::EnvFilter;

static RELOAD_HANDLE: OnceCell<Handle<EnvFilter>> = OnceCell::new();
type ReloadHandle = Box<dyn Fn(&str) -> Result<(), LoggingError> + Sync + Send>;

static RELOAD_HANDLE: OnceCell<ReloadHandle> = OnceCell::new();

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
Expand All @@ -20,7 +21,7 @@ pub enum Mode {
#[derive(Debug, thiserror::Error)]
pub enum LoggingError {
#[error("invalid logging mode: {0}")]
InvalidMode(String),
InvalidMode(#[from] tracing_subscriber::filter::ParseError),
#[error("failed to init logger: {0}")]
Init(#[from] tracing_subscriber::util::TryInitError),
#[error("failed to reload logger: {0}")]
Expand All @@ -29,26 +30,84 @@ pub enum LoggingError {

pub fn init(level: &str, mode: Mode) -> Result<(), LoggingError> {
let reload = RELOAD_HANDLE.get_or_try_init(|| {
let env_filter = EnvFilter::from_str(level).expect("failed to parse log level");
let env_filter = EnvFilter::from_str(level)?;

match mode {
Mode::Default => {
let filter = tracing_subscriber::fmt()
.with_line_number(true)
.with_file(true)
.with_env_filter(env_filter)
.with_filter_reloading();

let filter = tracing_subscriber::fmt()
.with_line_number(true)
.with_file(true)
.with_env_filter(env_filter)
.with_filter_reloading();
let handle = filter.reload_handle();

let handle = filter.reload_handle();
filter.finish().try_init()?;

match mode {
Mode::Default => filter.finish().try_init(),
Mode::Json => filter.json().finish().try_init(),
Mode::Pretty => filter.pretty().finish().try_init(),
Mode::Compact => filter.compact().finish().try_init(),
Ok::<_, LoggingError>(Box::new(move |level: &str| {
let level = EnvFilter::from_str(level)?;
handle.reload(level)?;
Ok(())
}) as ReloadHandle)
}
Mode::Json => {
let filter = tracing_subscriber::fmt()
.json()
.with_line_number(true)
.with_file(true)
.with_env_filter(env_filter)
.with_filter_reloading();

let handle = filter.reload_handle();

filter.finish().try_init()?;

Ok(Box::new(move |level: &str| {
let level = EnvFilter::from_str(level)?;
handle.reload(level)?;
Ok(())
}) as ReloadHandle)
}
Mode::Pretty => {
let filter = tracing_subscriber::fmt()
.pretty()
.with_line_number(true)
.with_file(true)
.with_env_filter(env_filter)
.with_filter_reloading();

let handle = filter.reload_handle();

filter.finish().try_init()?;

Ok(Box::new(move |level: &str| {
let level = EnvFilter::from_str(level)?;
handle.reload(level)?;
Ok(())
}) as ReloadHandle)
}
Mode::Compact => {
let filter = tracing_subscriber::fmt()
.compact()
.with_line_number(true)
.with_file(true)
.with_env_filter(env_filter)
.with_filter_reloading();

let handle = filter.reload_handle();

filter.finish().try_init()?;

Ok(Box::new(move |level: &str| {
let level = EnvFilter::from_str(level)?;
handle.reload(level)?;
Ok(())
}) as ReloadHandle)
}
}
lennartkloock marked this conversation as resolved.
Show resolved Hide resolved
.map(|_| handle)
})?;

reload.reload(level)?;
reload(level)?;

Ok(())
}
Loading
Loading