Skip to content

Commit

Permalink
Merge pull request #144 from ideal-world/update-dependencies
Browse files Browse the repository at this point in the history
update test-container's version
  • Loading branch information
4t145 authored Oct 18, 2024
2 parents 4cae0aa + 56902e4 commit 69327a3
Show file tree
Hide file tree
Showing 17 changed files with 200 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"rust-lang.rust-analyzer",
"tamasfe.even-better-toml",
"jscearcy.rust-doc-viewer",
"serayuzgur.crates",
"fill-labs.dependi",
"belfz.search-crates-io",
"vadimcn.vscode-lldb",
"swellaby.vscode-rust-test-adapter",
Expand Down
6 changes: 2 additions & 4 deletions examples/cache/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ use std::env;
use std::time::Duration;
use tardis::basic::result::TardisResult;
use tardis::test::test_container::TardisTestContainer;
use tardis::testcontainers::clients;
use tardis::tokio;
use tardis::tokio::time::sleep;
use tardis::TardisFuns;

#[tokio::main]
async fn main() -> TardisResult<()> {
// Here is a demonstration of using docker to start a mysql simulation scenario.
let docker = clients::Cli::default();
let redis_container = TardisTestContainer::redis_custom(&docker);
let port = redis_container.get_host_port_ipv4(6379);
let redis_container = TardisTestContainer::redis_custom().await?;
let port = redis_container.get_host_port_ipv4(6379).await?;
let url = format!("redis://127.0.0.1:{port}/0");
env::set_var("TARDIS_FW.CACHE.URL", url.clone());
env::set_var("TARDIS_FW.CACHE.MODULES.M1.URL", url.clone());
Expand Down
6 changes: 2 additions & 4 deletions examples/mq/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ use tokio::time::sleep;

use tardis::basic::result::TardisResult;
use tardis::test::test_container::TardisTestContainer;
use tardis::testcontainers::clients;
use tardis::tokio;
use tardis::TardisFuns;

#[tokio::main]
async fn main() -> TardisResult<()> {
// Here is a demonstration of using docker to start a mysql simulation scenario.
let docker = clients::Cli::default();
let rabbit_container = TardisTestContainer::rabbit_custom(&docker);
let port = rabbit_container.get_host_port_ipv4(5672);
let rabbit_container = TardisTestContainer::rabbit_custom().await?;
let port = rabbit_container.get_host_port_ipv4(5672).await?;
let url = format!("amqp://guest:[email protected]:{port}/%2f");
env::set_var("TARDIS_FW.MQ.URL", url);

Expand Down
6 changes: 2 additions & 4 deletions examples/multi-apps/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::env;

use tardis::basic::result::TardisResult;
use tardis::test::test_container::TardisTestContainer;
use tardis::testcontainers::clients;
use tardis::tokio;
use tardis::TardisFuns;

Expand All @@ -26,9 +25,8 @@ mod initializer;
#[tokio::main]
async fn main() -> TardisResult<()> {
// Here is a demonstration of using docker to start a mysql simulation scenario.
let docker = clients::Cli::default();
let mysql_container = TardisTestContainer::mysql_custom(None, &docker);
let port = mysql_container.get_host_port_ipv4(3306);
let mysql_container = TardisTestContainer::mysql_custom(None).await?;
let port = mysql_container.get_host_port_ipv4(3306).await?;
let url = format!("mysql://root:123456@localhost:{port}/test");
env::set_var("TARDIS_FW.DB.URL", url.clone());
env::set_var("TARDIS_FW.DB.MODULES.TAG.URL", url);
Expand Down
6 changes: 2 additions & 4 deletions examples/pg-graph-search/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ use std::vec;

use tardis::basic::result::TardisResult;
use tardis::test::test_container::TardisTestContainer;
use tardis::testcontainers::clients;
use tardis::tokio;
use tardis::TardisFuns;

#[tokio::main]
async fn main() -> TardisResult<()> {
// Here is a demonstration of using docker to start a mysql simulation scenario.
let docker = clients::Cli::default();
let mysql_container = TardisTestContainer::postgres_custom(None, &docker);
let port = mysql_container.get_host_port_ipv4(5432);
let mysql_container = TardisTestContainer::postgres_custom(None).await?;
let port = mysql_container.get_host_port_ipv4(5432).await?;
let url = format!("postgres://postgres:123456@localhost:{port}/test");
env::set_var("TARDIS_FW.DB.URL", url);

Expand Down
6 changes: 2 additions & 4 deletions examples/reldb/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use tardis::basic::result::TardisResult;
use tardis::db::sea_orm::*;
use tardis::log::info;
use tardis::test::test_container::TardisTestContainer;
use tardis::testcontainers::clients;
use tardis::tokio;
use tardis::TardisFuns;

Expand All @@ -14,9 +13,8 @@ mod domain;
#[tokio::main]
async fn main() -> TardisResult<()> {
// Here is a demonstration of using docker to start a mysql simulation scenario.
let docker = clients::Cli::default();
let mysql_container = TardisTestContainer::mysql_custom(None, &docker);
let port = mysql_container.get_host_port_ipv4(3306);
let mysql_container = TardisTestContainer::mysql_custom(None).await?;
let port = mysql_container.get_host_port_ipv4(3306).await?;
let url = format!("mysql://root:123456@localhost:{port}/test");
env::set_var("TARDIS_FW.DB.URL", url);

Expand Down
6 changes: 2 additions & 4 deletions examples/todos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::env;

use tardis::basic::result::TardisResult;
use tardis::test::test_container::TardisTestContainer;
use tardis::testcontainers::clients;
use tardis::tokio;
use tardis::TardisFuns;

Expand All @@ -18,9 +17,8 @@ mod processor;
#[tokio::main]
async fn main() -> TardisResult<()> {
// Here is a demonstration of using docker to start a mysql simulation scenario.
let docker = clients::Cli::default();
let mysql_container = TardisTestContainer::mysql_custom(None, &docker);
let port = mysql_container.get_host_port_ipv4(3306);
let mysql_container = TardisTestContainer::mysql_custom(None).await?;
let port = mysql_container.get_host_port_ipv4(3306).await?;
let url = format!("mysql://root:123456@localhost:{port}/test");
env::set_var("TARDIS_FW.DB.URL", url);

Expand Down
13 changes: 9 additions & 4 deletions tardis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ tokio = { version = "1", features = [
] }
tokio-util = { version = "0.7.12" }
# Tardis Macros
tardis-macros = { workspace = true, optional = true }
tardis-macros = { version = "0.1.0-rc.17", workspace = true, optional = true }
# Log
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
Expand Down Expand Up @@ -169,7 +169,7 @@ sea-orm = { version = "1", features = [
"with-json",
"debug-print",
], optional = true }
sqlx = { version = "0.7", features = ["any"], optional = true }
sqlx = { version = "0.8", features = ["any"], optional = true }
sqlparser = { version = "0", optional = true }

# Web Server
Expand Down Expand Up @@ -232,10 +232,15 @@ anyhow = { version = "1.0", optional = true }

# Test
# update this may cause break changes
testcontainers = { version = "0.15", optional = true }
testcontainers-modules = { version = "0.3", features = [
testcontainers = { version = "0.23", optional = true }
testcontainers-modules = { version = "0.11", features = [
"minio",
"redis",
"rabbitmq",
"mysql",
"postgres",
"elastic_search",

], optional = true }

# Debug
Expand Down
36 changes: 23 additions & 13 deletions tardis/src/basic/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,22 @@ where
self.with_configurable_layer(
tracing_opentelemetry::layer().with_tracer(TardisTracing::<LogConfig>::create_otlp_tracer()).boxed(),
|conf: &LogConfig| {
if std::env::var_os(OTEL_EXPORTER_OTLP_ENDPOINT).is_none() {
std::env::set_var(OTEL_EXPORTER_OTLP_ENDPOINT, conf.tracing.endpoint.as_str());
}
if std::env::var_os(OTEL_EXPORTER_OTLP_PROTOCOL).is_none() {
std::env::set_var(OTEL_EXPORTER_OTLP_PROTOCOL, conf.tracing.protocol.to_string());
}
if std::env::var_os(OTEL_SERVICE_NAME).is_none() {
std::env::set_var(OTEL_SERVICE_NAME, conf.tracing.server_name.as_str());
}
Ok(tracing_opentelemetry::layer().with_tracer(TardisTracing::<LogConfig>::create_otlp_tracer()).boxed())
let layer = if let Some(tracing) = &conf.tracing {
if std::env::var_os(OTEL_EXPORTER_OTLP_ENDPOINT).is_none() {
std::env::set_var(OTEL_EXPORTER_OTLP_ENDPOINT, tracing.endpoint.as_str());
}
if std::env::var_os(OTEL_EXPORTER_OTLP_PROTOCOL).is_none() {
std::env::set_var(OTEL_EXPORTER_OTLP_PROTOCOL, tracing.protocol.to_string());
}
if std::env::var_os(OTEL_SERVICE_NAME).is_none() {
std::env::set_var(OTEL_SERVICE_NAME, tracing.server_name.as_str());
}
tracing_opentelemetry::layer().with_tracer(TardisTracing::<LogConfig>::create_otlp_tracer()).boxed()
} else {
tracing_opentelemetry::layer().boxed()
};
tracing::debug!("[Tardis.Tracing] OpenTelemetry layer created.");
Ok(layer)
},
)
}
Expand All @@ -178,6 +184,7 @@ where
{
use crate::config::config_dto::log::TracingAppenderConfig;
let config_file_layer = |cfg: Option<&TracingAppenderConfig>| {
tracing::debug!("Configuring appender layer.");
if let Some(cfg) = &cfg {
let file_appender = tracing_appender::rolling::RollingFileAppender::new(cfg.rotation.into(), &cfg.dir, &cfg.filename);
FmtLayer::default().with_writer(file_appender).boxed()
Expand Down Expand Up @@ -280,11 +287,14 @@ impl TardisTracing<LogConfig> {
)
.install_batch(opentelemetry_sdk::runtime::Tokio)
.expect("fail to install otlp tracer");
tracing::debug!("[Tardis.Tracing] Initialized otlp tracer");
opentelemetry::global::set_text_map_propagator(opentelemetry_sdk::propagation::TraceContextPropagator::new());
opentelemetry::global::shutdown_tracer_provider();
opentelemetry::global::set_text_map_propagator(opentelemetry_sdk::propagation::TraceContextPropagator::new());
opentelemetry::global::set_tracer_provider(provider.clone());
provider.tracer(tracing_service_name())
tracing::debug!("[Tardis.Tracing] Initialized otlp tracer");
let new_tracer = provider.tracer(tracing_service_name());
tracing::debug!(?new_tracer, "[Tardis.Tracing] new tracer created");

new_tracer
}

#[cfg(feature = "tracing")]
Expand Down
2 changes: 1 addition & 1 deletion tardis/src/config/config_dto/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct LogConfig {
#[cfg(feature = "tracing")]
#[builder(default)]
/// open telemetry tracing config
pub tracing: TracingConfig,
pub tracing: Option<TracingConfig>,
#[cfg(feature = "tracing-appender")]
#[builder(default)]
/// tracing appender config
Expand Down
1 change: 1 addition & 0 deletions tardis/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub use sea_orm;
pub mod domain;
pub mod reldb_client;
pub use sqlx;
1 change: 1 addition & 0 deletions tardis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ impl TardisFuns {
#[cfg(feature = "web-server")]
{
if let Some(_web_server_config) = &fw_conf.web_server {
tracing::info!("initialize web server");
let web_server = TardisWebServer::init_by_conf(&fw_conf)?;
// take out previous webserver first, because TARDIS_INST is not send and can't live cross an `await` point
let inherit = tardis_instance().web_server.get();
Expand Down
Loading

0 comments on commit 69327a3

Please sign in to comment.