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

bump up dependency version #119

Merged
merged 2 commits into from
May 8, 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
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ codegen-units = 1
opt-level = "z"

[workspace.package]
version = "0.1.0-rc.12"
version = "0.1.0-rc.13"
authors = ["gudaoxuri <i@sunisle.org>"]
description = "Elegant, clean Rust development framework"
keywords = ["http", "database", "web", "redis", "mq"]
Expand All @@ -20,3 +20,7 @@ repository = "https://github.com/ideal-world/tardis"
edition = "2021"
license = "MIT/Apache-2.0"
rust-version = "1.72"


[workspace.dependencies]
tardis-macros = { path = "./tardis-macros" }
26 changes: 15 additions & 11 deletions tardis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ k8s = ["future", "kube", "k8s-openapi"]
fs = ["tokio/fs", "tokio/io-util"]
process = ["tokio/process"]
test = ["testcontainers", "testcontainers-modules"]
tracing = ["tracing-opentelemetry", "opentelemetry", "opentelemetry-otlp"]
tracing = ["tracing-opentelemetry", "opentelemetry", "opentelemetry-otlp", "opentelemetry_sdk"]
tokio-console = ["console-subscriber"]
tracing-appender = ["dep:tracing-appender"]
web-server-grpc = ["web-server", "dep:poem-grpc"]
Expand Down Expand Up @@ -90,19 +90,22 @@ tokio = { version = "1", features = [
] }
tokio-util = { version = "0.7.10" }
# Tardis Macros
tardis-macros = { version = "0.1.0-rc.1", path = "../tardis-macros", optional = true }
tardis-macros = { workspace = true, optional = true }
# Log
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-appender = { version = "0.2", optional = true }
console-subscriber = { version = "0.2", optional = true }
# Tracing
tracing-opentelemetry = { version = "0.21", optional = true }
opentelemetry = { version = "0.20", default-features = false, features = [
tracing-opentelemetry = { version = "0.23", optional = true }
opentelemetry = { version = "0.22", default-features = false, features = [
"trace",
], optional = true }
opentelemetry_sdk = { version = "0.22", default-features = false, features = [
"rt-tokio",
"trace",
], optional = true }
opentelemetry-otlp = { version = "0.13", features = [
opentelemetry-otlp = { version = "0.15", features = [
"reqwest-client",
"reqwest-rustls",
"http-proto",
Expand Down Expand Up @@ -160,12 +163,12 @@ sqlx = { version = "0.7", features = ["any"], optional = true }
sqlparser = { version = "0", optional = true }

# Web Server
poem-openapi = { version = "4", features = [
poem-openapi = { version = "5", features = [
"chrono",
"websocket",
], optional = true }
poem-openapi-derive = { version = "4", optional = true }
poem = { version = "2", features = [
poem-openapi-derive = { version = "5", optional = true }
poem = { version = "3", features = [
"csrf",
"opentelemetry",
"rustls",
Expand All @@ -175,10 +178,10 @@ poem = { version = "2", features = [
"tempfile",
"session",
], optional = true }
poem-grpc = { version = "0.3", optional = true }
poem-grpc = { version = "0.4", optional = true }

# Web Client
reqwest = { version = "0.11", features = [
reqwest = { version = "0.12", features = [
"json",
"multipart",
], optional = true }
Expand Down Expand Up @@ -219,6 +222,7 @@ json-patch = "=1.2.0"
k8s-openapi = { version = "^0.20", features = ["earliest"], optional = true }

# Test
# update this may cause break changes
testcontainers = { version = "0.15", optional = true }
testcontainers-modules = { version = "0.3", features = [
"minio",
Expand All @@ -238,7 +242,7 @@ tokio = { version = "1", features = [
"process",
] }
criterion = { version = "0.5" }
poem-grpc-build = "0.3"
poem-grpc-build = "0.4"
prost = "0.12"
strip-ansi-escapes = "0.2.0"
portpicker = "0.1.1"
Expand Down
20 changes: 8 additions & 12 deletions tardis/src/basic/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,41 +240,37 @@ impl TardisTracing<LogConfig> {
tracing::debug!("[Tardis.Tracing] Added fmt layer and env filter.");
#[cfg(feature = "tracing")]
let initializer = initializer.with_opentelemetry_layer();
#[cfg(feature = "console-subscriber")]
let initializer = initializer.with_console_layer();
#[cfg(feature = "tracing-appender")]
let initializer = initializer.with_appender_layer();
tracing::info!("[Tardis.Tracing] Initialize finished.");
initializer.init();
}

#[cfg(feature = "tracing")]
fn create_otlp_tracer() -> opentelemetry::sdk::trace::Tracer {
use opentelemetry_otlp::WithExportConfig;

fn create_otlp_tracer() -> opentelemetry_sdk::trace::Tracer {
use crate::config::config_dto::OtlpProtocol;
tracing::debug!("[Tardis.Tracing] Initializing otlp tracer");
let protocol = std::env::var(OTEL_EXPORTER_OTLP_PROTOCOL).ok().map(|s| s.parse::<OtlpProtocol>().unwrap_or_default()).unwrap_or_default();
let mut tracer = opentelemetry_otlp::new_pipeline().tracing();
match protocol {
let tracer = opentelemetry_otlp::new_pipeline().tracing();
let tracer = match protocol {
OtlpProtocol::Grpc => {
let mut exporter = opentelemetry_otlp::new_exporter().tonic().with_env();
let mut exporter = opentelemetry_otlp::new_exporter().tonic();
// Check if we need TLS
if let Ok(endpoint) = std::env::var(OTEL_EXPORTER_OTLP_ENDPOINT) {
if endpoint.to_lowercase().starts_with("https") {
exporter = exporter.with_tls_config(Default::default());
}
}
tracer = tracer.with_exporter(exporter);
tracer.with_exporter(exporter)
}
OtlpProtocol::HttpProtobuf => {
let headers = Self::parse_otlp_headers_from_env();
let exporter = opentelemetry_otlp::new_exporter().http().with_headers(headers.into_iter().collect()).with_env();
tracer = tracer.with_exporter(exporter);
let exporter = opentelemetry_otlp::new_exporter().http().with_headers(headers.into_iter().collect());
tracer.with_exporter(exporter)
}
};
tracing::debug!("[Tardis.Tracing] Batch installing tracer. If you are blocked here, try running tokio in multithread.");
let tracer = tracer.install_batch(opentelemetry::runtime::Tokio).expect("fail to install otlp tracer");
let tracer = tracer.install_batch(opentelemetry_sdk::runtime::Tokio).expect("fail to install otlp tracer");
tracing::debug!("[Tardis.Tracing] Initialized otlp tracer");
tracer
}
Expand Down
2 changes: 0 additions & 2 deletions tardis/src/web/cluster_id_mw.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::TardisFuns;
use async_trait::async_trait;
#[cfg(feature = "cluster")]
use poem::http::HeaderValue;
use poem::{Endpoint, IntoResponse, Middleware, Request, Response};
Expand All @@ -16,7 +15,6 @@ impl<E: Endpoint> Middleware<E> for AddClusterIdHeader {

pub struct UniformErrorImpl<E>(E);
pub const TARDIS_CLUSTER_ID_HEADER: &str = "Tardis-Cluster-Id";
#[async_trait]
impl<E: Endpoint> Endpoint for UniformErrorImpl<E> {
type Output = Response;

Expand Down
2 changes: 0 additions & 2 deletions tardis/src/web/uniform_error_mw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::basic::error::TardisError;
use crate::basic::result::TARDIS_RESULT_SUCCESS_CODE;
use crate::serde_json::json;
use crate::TardisFuns;
use async_trait::async_trait;
use poem::http::StatusCode;
use poem::{Endpoint, IntoResponse, Middleware, Request, Response};
use tracing::{trace, warn};
Expand All @@ -21,7 +20,6 @@ impl<E: Endpoint> Middleware<E> for UniformError {

pub struct UniformErrorImpl<E>(E);

#[async_trait]
impl<E: Endpoint> Endpoint for UniformErrorImpl<E> {
type Output = Response;

Expand Down
3 changes: 1 addition & 2 deletions tardis/tests/build_proto.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::io::Result;

use poem_grpc_build::compile_protos;

fn main() -> Result<()> {
std::env::set_var("OUT_DIR", "tests/grpc/rust");
compile_protos(&["./tests/grpc/proto/helloworld.proto"], &["./tests/grpc/proto/"])?;
compile_protos(&["./tests/grpc/proto/helloworld.proto"], &["./tests/grpc/proto/"]).expect("fail to build");
Ok(())
}
16 changes: 11 additions & 5 deletions tardis/tests/grpc/rust/helloworld.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// The request message containing the user's name.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down Expand Up @@ -45,7 +46,9 @@ impl GreeterClient {
pub fn with<M>(mut self, middleware: M) -> Self
where
M: ::poem::Middleware<
::std::sync::Arc<dyn ::poem::Endpoint<Output = ::poem::Response> + 'static>,
::std::sync::Arc<
dyn ::poem::endpoint::DynEndpoint<Output = ::poem::Response> + 'static,
>,
>,
M::Output: 'static,
{
Expand All @@ -65,12 +68,16 @@ impl GreeterClient {
}
}
#[allow(unused_imports)]
#[::poem::async_trait]
pub trait Greeter: Send + Sync + 'static {
async fn say_hello(
fn say_hello(
&self,
request: poem_grpc::Request<HelloRequest>,
) -> ::std::result::Result<poem_grpc::Response<HelloReply>, poem_grpc::Status>;
) -> impl ::std::future::Future<
Output = ::std::result::Result<
poem_grpc::Response<HelloReply>,
poem_grpc::Status,
>,
> + Send;
}
#[allow(unused_imports)]
#[derive(Clone)]
Expand All @@ -93,7 +100,6 @@ impl<T: Greeter> ::poem::IntoEndpoint for GreeterServer<T> {
let mut route = ::poem::Route::new();
#[allow(non_camel_case_types)]
struct Greetersay_helloService<T>(::std::sync::Arc<T>);
#[::poem::async_trait]
impl<T: Greeter> poem_grpc::service::UnaryService<HelloRequest>
for Greetersay_helloService<T> {
type Response = HelloReply;
Expand Down
10 changes: 3 additions & 7 deletions tardis/tests/test_web_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use std::env;
use std::str::FromStr;
use std::time::Duration;

use async_trait::async_trait;
use poem::endpoint::BoxEndpoint;
use poem::endpoint::{BoxEndpoint, ToDynEndpoint};
use poem::http::Method;
use poem::{IntoResponse, Middleware, Response};
use serde_json::json;
Expand Down Expand Up @@ -795,7 +794,6 @@ impl Middleware<BoxEndpoint<'static>> for TodosApiMiddleware1 {
fn transform(&self, ep: BoxEndpoint<'static>) -> Self::Output {
pub struct TodosApiMWImpl1<E>(E);

#[async_trait]
impl<E: Endpoint> Endpoint for TodosApiMWImpl1<E> {
type Output = Response;

Expand Down Expand Up @@ -855,7 +853,7 @@ impl Middleware<BoxEndpoint<'static>> for TodosApiMiddleware1 {
}
}

Box::new(TodosApiMWImpl1(ep))
Box::new(ToDynEndpoint(TodosApiMWImpl1(ep)))
}
}

Expand All @@ -868,7 +866,6 @@ impl Middleware<BoxEndpoint<'static>> for TodosApiMiddleware2 {
fn transform(&self, ep: BoxEndpoint<'static>) -> Self::Output {
pub struct TodosApiMWImpl2<E>(E);

#[async_trait]
impl<E: Endpoint> Endpoint for TodosApiMWImpl2<E> {
type Output = Response;

Expand Down Expand Up @@ -928,13 +925,12 @@ impl Middleware<BoxEndpoint<'static>> for TodosApiMiddleware2 {
}
}

Box::new(TodosApiMWImpl2(ep))
Box::new(ToDynEndpoint(TodosApiMWImpl2(ep)))
}
}

#[derive(Clone, Default)]
pub struct GreeterGrpcService;
#[poem::async_trait]
impl Greeter for GreeterGrpcService {
async fn say_hello(&self, request: GrpcRequest<HelloRequest>) -> Result<GrpcResponse<HelloReply>, GrpcStatus> {
info!("GreeterGrpcService say_hello {:?}", request);
Expand Down
Loading