Skip to content

Commit

Permalink
Merge branch 'main' into zz-tracing-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzIsGod1019 committed Aug 15, 2023
2 parents f049409 + 267c275 commit 7d7701a
Show file tree
Hide file tree
Showing 29 changed files with 622 additions and 91 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ jobs:
- 4369:4369
options: -e RABBITMQ_DEFAULT_USER=guest -e RABBITMQ_DEFAULT_PASS=guest
es:
image: elasticsearch:8.7.1
image: rapidfort/elasticsearch:7.17
ports:
- 9200:9200
options: -e ELASTIC_PASSWORD=123456 -e discovery.type=single-node
options: -e ELASTICSEARCH_HEAP_SIZE=128m
# https://github.com/minio/minio/issues/10745
minio:
image: minio/minio:edge-cicd
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ out
# Cargo
Cargo.lock
target
.cargo

# gh pages docs
util/gh-pages/lints.json
Expand All @@ -20,3 +21,5 @@ util/gh-pages/lints.json
*.iml
.vscode
.idea

.DS_Store
9 changes: 5 additions & 4 deletions examples/websocket/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ use std::collections::HashMap;

use serde::{Deserialize, Serialize};
use tardis::basic::result::TardisResult;
use tardis::tokio::sync::broadcast::Sender;
use tardis::web::poem::web::websocket::BoxWebSocketUpgraded;
use tardis::web::poem::web::{websocket::WebSocket, Path};
use tardis::web::poem::web::{websocket::WebSocket, Data, Path};
use tardis::web::poem_openapi::payload::Html;
use tardis::web::poem_openapi::{self};
use tardis::web::ws_processor::{ws_broadcast, ws_echo, TardisWebsocketResp};
use tardis::web::ws_processor::{ws_broadcast, ws_echo, TardisWebsocketMgrMessage, TardisWebsocketResp};
use tardis::TardisFuns;
#[derive(Debug, Clone)]
pub struct Page;
Expand Down Expand Up @@ -126,14 +127,14 @@ impl Page {
}

#[oai(path = "/ws/broadcast/:name", method = "get")]
async fn ws_broadcast(&self, name: Path<String>, websocket: WebSocket) -> BoxWebSocketUpgraded {
async fn ws_broadcast(&self, name: Path<String>, websocket: WebSocket, sender: Data<&Sender<TardisWebsocketMgrMessage>>) -> BoxWebSocketUpgraded {
ws_broadcast(
"/ws/broadcast/:name",
vec![name.0],
false,
false,
HashMap::from([("some_key".to_string(), "ext_value".to_string())]),
websocket,
sender.clone(),
|req_msg, ext| async move {
let example_msg = TardisFuns::json.json_to_obj::<WebsocketExample>(req_msg.msg).unwrap();
Some(TardisWebsocketResp {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ error[E0277]: the trait bound `tardis::db::sea_orm::Value: From<KeyValue>` is no
| ^^^^^^^^^^^^^^^^^ the trait `From<KeyValue>` is not implemented for `tardis::db::sea_orm::Value`
|
= help: the following other types implement trait `From<T>`:
<tardis::db::sea_orm::Value as From<&'a [u8]>>
<tardis::db::sea_orm::Value as From<&[u8]>>
<tardis::db::sea_orm::Value as From<&std::string::String>>
<tardis::db::sea_orm::Value as From<&str>>
<tardis::db::sea_orm::Value as From<Cow<'_, str>>>
Expand All @@ -16,8 +16,11 @@ error[E0277]: the trait bound `tardis::db::sea_orm::Value: From<KeyValue>` is no
and $N others
= note: required for `KeyValue` to implement `Into<tardis::db::sea_orm::Value>`
note: required by a bound in `ActiveValue`
--> $CARGO/sea-orm-0.11.3/src/entity/active_model.rs
--> $CARGO/sea-orm-0.12.2/src/entity/active_model.rs
|
| pub enum ActiveValue<V>
| ----------- required by a bound in this enum
| where
| V: Into<Value>,
| ^^^^^^^^^^^ required by this bound in `ActiveValue`
= note: this error originates in the derive macro `DeriveEntityModel` (in Nightly builds, run with -Z macro-backtrace for more info)
Expand All @@ -29,7 +32,7 @@ error[E0277]: the trait bound `KeyValue: Nullable` is not satisfied
| ^^^^^^^^^^^^^^^^^ the trait `Nullable` is not implemented for `KeyValue`
|
= help: the following other types implement trait `Nullable`:
&'a str
&str
JsonValue
NaiveDate
NaiveDateTime
Expand All @@ -41,8 +44,11 @@ error[E0277]: the trait bound `KeyValue: Nullable` is not satisfied
= note: required for `tardis::db::sea_orm::Value` to implement `From<std::option::Option<KeyValue>>`
= note: required for `std::option::Option<KeyValue>` to implement `Into<tardis::db::sea_orm::Value>`
note: required by a bound in `ActiveValue`
--> $CARGO/sea-orm-0.11.3/src/entity/active_model.rs
--> $CARGO/sea-orm-0.12.2/src/entity/active_model.rs
|
| pub enum ActiveValue<V>
| ----------- required by a bound in this enum
| where
| V: Into<Value>,
| ^^^^^^^^^^^ required by this bound in `ActiveValue`
= note: this error originates in the derive macro `DeriveEntityModel` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() {

let table_name: Option<_> = create_table_statement.get_table_name();
assert!(table_name.is_some());
assert_eq!(format!("{:?}", table_name.unwrap()), "Table(tests)".to_string());
assert_eq!(format!("{:?}", table_name.unwrap()), "Table(SeaRc(tests))".to_string());

let table_cols: &Vec<_> = create_table_statement.get_columns();
assert_eq!(table_cols.len(), 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn main() {

let table_name: Option<_> = create_table_statement.get_table_name();
assert!(table_name.is_some());
assert_eq!(format!("{:?}", table_name.unwrap()), "Table(tests)".to_string());
assert_eq!(format!("{:?}", table_name.unwrap()), "Table(SeaRc(tests))".to_string());

let table_cols: &Vec<_> = create_table_statement.get_columns();
assert_eq!(table_cols.len(), 24);
Expand All @@ -96,17 +96,17 @@ fn main() {
assert_eq!(find_id.len(), 1);
let find_id: Vec<_> = table_cols
.iter()
.filter(|col| col.get_column_name() == "be_custom_array_string" && col.get_column_type() == Some(&ColumnType::Array(sea_query::SeaRc::new(ColumnType::String(Some(50))))))
.filter(|col| col.get_column_name() == "be_custom_array_string" && col.get_column_type() == Some(&ColumnType::Array(std::sync::Arc::new(ColumnType::String(Some(50))))))
.collect();
assert_eq!(find_id.len(), 1);
let find_id: Vec<_> = table_cols
.iter()
.filter(|col| col.get_column_name() == "be_vec_text" && col.get_column_type() == Some(&ColumnType::Array(sea_query::SeaRc::new(ColumnType::String(None)))))
.filter(|col| col.get_column_name() == "be_vec_text" && col.get_column_type() == Some(&ColumnType::Array(std::sync::Arc::new(ColumnType::String(None)))))
.collect();
assert_eq!(find_id.len(), 1);
let find_id: Vec<_> = table_cols
.iter()
.filter(|col| col.get_column_name() == "be_option_vec_text" && col.get_column_type() == Some(&ColumnType::Array(sea_query::SeaRc::new(ColumnType::String(Some(50))))))
.filter(|col| col.get_column_name() == "be_option_vec_text" && col.get_column_type() == Some(&ColumnType::Array(std::sync::Arc::new(ColumnType::String(Some(50))))))
.collect();
assert_eq!(find_id.len(), 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {

let table_name: Option<_> = create_table_statement.get_table_name();
assert!(table_name.is_some());
assert_eq!(format!("{:?}", table_name.unwrap()), "Table(tests)".to_string());
assert_eq!(format!("{:?}", table_name.unwrap()), "Table(SeaRc(tests))".to_string());

let table_cols: &Vec<_> = create_table_statement.get_columns();
assert_eq!(table_cols.len(), 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() {

let table_name: Option<_> = create_table_statement.get_table_name();
assert!(table_name.is_some());
assert_eq!(format!("{:?}", table_name.unwrap()), "Table(tests)".to_string());
assert_eq!(format!("{:?}", table_name.unwrap()), "Table(SeaRc(tests))".to_string());

let table_cols: &Vec<_> = create_table_statement.get_columns();
assert_eq!(table_cols.len(), 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {

let table_name: Option<_> = create_table_statement.get_table_name();
assert!(table_name.is_some());
assert_eq!(format!("{:?}", table_name.unwrap()), "Table(tests)".to_string());
assert_eq!(format!("{:?}", table_name.unwrap()), "Table(SeaRc(tests))".to_string());

let table_cols: &Vec<_> = create_table_statement.get_columns();
assert_eq!(table_cols.len(), 3);
Expand Down
19 changes: 9 additions & 10 deletions tardis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ crypto-with-sm = ["crypto", "libsm", "num-bigint"]
future = ["futures", "async-stream", "futures-util", "async-trait"]
tls = ["native-tls"]
reldb-core = ["future", "sqlparser", "sea-orm", "sqlx"]
reldb-postgres = [
"reldb-core",
"sea-orm/postgres-array",
"sea-orm/sqlx-postgres",
"tardis-macros/reldb-postgres",
]
reldb-postgres = ["reldb-core", "sea-orm/postgres-array", "sea-orm/sqlx-postgres", "tardis-macros/reldb-postgres"]
reldb-mysql = ["reldb-core", "sea-orm/sqlx-mysql", "tardis-macros/reldb-mysql"]
reldb-sqlite = ["reldb-core", "sea-orm/sqlx-sqlite"]
reldb = ["reldb-core", "reldb-postgres", "reldb-mysql", "reldb-sqlite"]
Expand All @@ -44,6 +39,7 @@ fs = ["tokio/fs"]
process = ["tokio/process"]
test = ["testcontainers"]
tracing = ["tracing-opentelemetry", "opentelemetry"]
web-server-grpc = ["web-server", "dep:poem-grpc"]

[dependencies]
# Basic
Expand Down Expand Up @@ -123,7 +119,7 @@ poem = { version = "1.3", features = [
"multipart",
"tempfile",
], optional = true }

poem-grpc = { version = "0.2", optional = true }
# Web Client
reqwest = { version = "0.11", features = [
"json",
Expand All @@ -143,9 +139,9 @@ redis = { version = "0.23", features = [
deadpool-redis = { version = "0.12", optional = true }

# Rabbit
lapin = { version = "2.0", optional = true }
lapin = { version = "2", optional = true }
amq-protocol-types = { version = "7.0", optional = true }
async-global-executor = { version = "2.0", optional = true }
async-global-executor = { version = "2", optional = true, features = ["tokio"] }

# Mail
lettre = { version = "0.10.4", features = [
Expand All @@ -166,6 +162,9 @@ testcontainers = { version = "0.14", optional = true }
# Common
tokio = { version = "1", features = ["time", "rt", "macros", "sync"] }
criterion = { version = "0.5" }
console-subscriber = "0.1.10"
poem-grpc-build = "0.2.21"
prost = "0.11.9"

[[test]]
name = "test_config"
Expand Down Expand Up @@ -193,7 +192,7 @@ required-features = ["test", "reldb"]

[[test]]
name = "test_web_server"
required-features = ["test", "web-server", "cache", "web-client", "crypto"]
required-features = ["test", "web-server", "cache", "web-client", "crypto", "web-server-grpc"]

[[test]]
name = "test_web_client"
Expand Down
35 changes: 33 additions & 2 deletions tardis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,37 @@ async fn main() -> TardisResult<()> {
}
```

### Dependencies

In order to use gRPC features, you need the `protoc` Protocol Buffers compiler, along with Protocol Buffers resource files.

#### Ubuntu

```bash
sudo apt update && sudo apt upgrade -y
sudo apt install -y protobuf-compiler libprotobuf-dev
```

#### Alpine Linux

```sh
sudo apk add protoc protobuf-dev
```

#### macOS

Assuming [Homebrew](https://brew.sh/) is already installed. (If not, see instructions for installing Homebrew on [the Homebrew website](https://brew.sh/).)

```zsh
brew install protobuf
```

#### Windows

- Download the latest version of `protoc-xx.y-win64.zip` from [HERE](https://github.com/protocolbuffers/protobuf/releases/latest)
- Extract the file `bin\protoc.exe` and put it somewhere in the `PATH`
- Verify installation by opening a command prompt and enter `protoc --version`

### More examples

```
Expand Down Expand Up @@ -156,11 +187,11 @@ async fn main() -> TardisResult<()> {
./vcpkg integrate install
./vcpkg install openssl
```
* An `` failed to run custom build command for `opentelemetry-proto`` error occurs when running under Linux:
* An `` failed to run custom build command for opentelemetry-proto`` error occurs when running under Linux:
```shell
apt install protobuf-compiler
```
* An `` failed to run custom build command for `opentelemetry-proto`` error occurs when running under MacOS:
* An `` failed to run custom build command for opentelemetry-proto`` error occurs when running under MacOS:
```shell
brew install protobuf
```
Expand Down
1 change: 0 additions & 1 deletion tardis/src/basic/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub struct TardisTracing;
pub static mut GLOBAL_RELOAD_HANDLE: Option<Handle<EnvFilter, Layered<Layer<Registry>, Registry>>> = None;

impl TardisTracing {
#[cfg(not(feature = "tracing"))]
pub(crate) fn init_log() -> TardisResult<()> {
if INITIALIZED.swap(true, Ordering::SeqCst) {
return Ok(());
Expand Down
12 changes: 6 additions & 6 deletions tardis/src/crypto/crypto_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@ pub struct TardisCryptoKey;
impl TardisCryptoKey {
pub fn rand_8_hex(&self) -> TardisResult<String> {
let mut key: [u8; 4] = [0; 4];
rand::rngs::OsRng::default().fill_bytes(&mut key);
rand::rngs::OsRng.fill_bytes(&mut key);
Ok(hex::encode(key))
}

pub fn rand_16_hex(&self) -> TardisResult<String> {
let mut key: [u8; 8] = [0; 8];
rand::rngs::OsRng::default().fill_bytes(&mut key);
rand::rngs::OsRng.fill_bytes(&mut key);
Ok(hex::encode(key))
}

pub fn rand_32_hex(&self) -> TardisResult<String> {
let mut key: [u8; 16] = [0; 16];
rand::rngs::OsRng::default().fill_bytes(&mut key);
rand::rngs::OsRng.fill_bytes(&mut key);
Ok(hex::encode(key))
}

pub fn rand_64_hex(&self) -> TardisResult<String> {
let mut key: [u8; 32] = [0; 32];
rand::rngs::OsRng::default().fill_bytes(&mut key);
rand::rngs::OsRng.fill_bytes(&mut key);
Ok(hex::encode(key))
}

pub fn rand_128_hex(&self) -> TardisResult<String> {
let mut key: [u8; 64] = [0; 64];
rand::rngs::OsRng::default().fill_bytes(&mut key);
rand::rngs::OsRng.fill_bytes(&mut key);
Ok(hex::encode(key))
}

pub fn rand_256_hex(&self) -> TardisResult<String> {
let mut key: [u8; 128] = [0; 128];
rand::rngs::OsRng::default().fill_bytes(&mut key);
rand::rngs::OsRng.fill_bytes(&mut key);
Ok(hex::encode(key))
}

Expand Down
8 changes: 7 additions & 1 deletion tardis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ pub use futures;
#[cfg(feature = "future")]
pub use futures_util;
pub use lru;
#[cfg(feature = "web-server-grpc")]
pub use poem_grpc;
pub use rand;
pub use regex;
pub use serde;
Expand Down Expand Up @@ -350,7 +352,6 @@ impl TardisFuns {
///
/// [init](Self::init) 函数时会自动调用此函数
pub fn init_log() -> TardisResult<()> {
#[cfg(not(feature = "tracing"))]
TardisTracing::init_log()?;
Ok(())
}
Expand Down Expand Up @@ -584,6 +585,10 @@ impl TardisFuns {
}
}

pub fn fw_config_opt() -> &'static Option<FrameworkConfig> {
unsafe { &TARDIS_INST.framework_config }
}

/// Using the field feature / 使用字段功能
///
/// # Examples
Expand Down Expand Up @@ -1198,6 +1203,7 @@ impl TardisFuns {
TardisConfig { cs, fw }
};

#[allow(unused_variables)]
let fw_config = TardisFuns::fw_config();

#[cfg(feature = "tracing")]
Expand Down
Loading

0 comments on commit 7d7701a

Please sign in to comment.