Skip to content

Commit

Permalink
update event client module
Browse files Browse the repository at this point in the history
  • Loading branch information
4t145 committed Feb 6, 2025
1 parent cbca3c0 commit cf0b403
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 36 deletions.
29 changes: 29 additions & 0 deletions backend/middlewares/event-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "bios-mw-event-client"
version.workspace = true
authors.workspace = true
homepage.workspace = true
documentation.workspace = true
repository.workspace = true
license.workspace = true
edition.workspace = true
readme.workspace = true
publish.workspace = true

[lib]
name = "bios_mw_event_client"
path = "src/lib.rs"

[dependencies]
serde.workspace = true

tardis = { workspace = true, features = [
"reldb-postgres",
"web-server",
"ws-client",
] }

bios-sdk-invoke = { version = "0.2.0", path = "../../../frontend/sdks/invoke", features = [
"spi_log",
"event",
], default-features = false }
22 changes: 22 additions & 0 deletions backend/middlewares/event-client/src/event_client_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use bios_sdk_invoke::invoke_config::InvokeConfig;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct EventClientConfig {
pub max_retry_times: Option<usize>,
pub enable: bool,
pub retry_duration_ms: u32,
pub invoke: InvokeConfig,
}

impl Default for EventClientConfig {
fn default() -> Self {
Self {
max_retry_times: None,
enable: false,
retry_duration_ms: 5000,
invoke: InvokeConfig::default(),
}
}
}
30 changes: 30 additions & 0 deletions backend/middlewares/event-client/src/event_client_initializer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crate::event_client_config::EventClientConfig;
use bios_sdk_invoke::clients::event_client::init_client_node;
use bios_sdk_invoke::invoke_initializer;
use std::time::Duration;
use tardis::tracing::{self, instrument};
use tardis::{
basic::{dto::TardisContext, result::TardisResult},
TardisFuns,
};
const CODE: &str = "event-client";
#[instrument(name = "event-client-init")]
pub async fn init() -> TardisResult<()> {
let funs = TardisFuns::inst(CODE, None);
let config = funs.conf::<EventClientConfig>();
let invoke_config = &config.invoke;
invoke_initializer::init(funs.module_code(), invoke_config.clone())?;

if config.enable {
tracing::info!(?config, "initialize event client");
let context = TardisContext {
ak: invoke_config.spi_app_id.to_string(),
own_paths: invoke_config.spi_app_id.to_string(),
..Default::default()
};
init_client_node(config.max_retry_times, Duration::from_millis(config.retry_duration_ms as u64), &context, &funs).await;
} else {
tardis::tracing::info!("event client no enabled");
}
Ok(())
}
2 changes: 2 additions & 0 deletions backend/middlewares/event-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod event_client_config;
pub mod event_client_initializer;
2 changes: 2 additions & 0 deletions backend/services/bios-all/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ bios-spi-stats = { version = "0.2.0", path = "../../spi/spi-stats" }
bios-mw-schedule = { version = "0.2.0", path = "../../middlewares/schedule" }
bios-mw-flow = { version = "0.2.0", path = "../../middlewares/flow" }
# bios-mw-event = { version = "0.2.0", path = "../../middlewares/event" }
bios-mw-event-client = { version = "0.2.0", path = "../../middlewares/event-client"}

# clients

bios-client-hwsms = { version = "0.2.0", path = "../../../frontend/clients/hwsms", features = [
"reach",
] }
Expand Down
3 changes: 1 addition & 2 deletions backend/services/bios-all/src/initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use tardis::basic::result::TardisResult;
use tardis::web::web_server::TardisWebServer;

pub async fn init(web_server: &TardisWebServer) -> TardisResult<()> {
// bios_mw_event::event_initializer::init(web_server).await?;

bios_mw_event_client::event_client_initializer::init().await?;
bios_auth::auth_initializer::init(web_server).await?;
bios_iam::iam_initializer::init(web_server).await?;
bios_reach::reach_initializer::init(
Expand Down
1 change: 1 addition & 0 deletions backend/services/bios-event/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bios-event
64 changes: 32 additions & 32 deletions backend/services/bios-event/bios-event-resource.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
apiVersion: v1
kind: Service
metadata:
name: bios-event
spec:
clusterIP: None
selector:
app: bios-event
ports:
- name: http
port: 8080
targetPort: 8080
nodePort: 30080
- name: mq
port: 9559
targetPort: 9559
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: sa-bios-event
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
Expand All @@ -22,49 +44,27 @@ spec:
- containerPort: 8080
- containerPort: 9559
---
apiVersion: v1
kind: Service
metadata:
name: bios-event
spec:
clusterIP: None
selector:
app: bios-event
ports:
- name: http
port: 8080
targetPort: 8080
nodePort: 30080
- name: mq
port: 9559
targetPort: 9559
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: sa-bios-event
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: cr-bios-event
rules:
- apiGroups: [""]
resources: ["services", "endpoints", "pods"]
verbs: ["get", "list", "watch"]
- apiGroups: ["apps"]
resources: ["statefulsets"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["services", "endpoints", "pods"]
verbs: ["get", "list", "watch"]
- apiGroups: ["apps"]
resources: ["statefulsets"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: rb-bios-event
subjects:
- kind: ServiceAccount
name: sa-bios-event
namespace: default
- kind: ServiceAccount
name: sa-bios-event
namespace: default
roleRef:
kind: ClusterRole
name: cr-bios-event
apiGroup: rbac.authorization.k8s.io
apiGroup: rbac.authorization.k8s.io
1 change: 0 additions & 1 deletion frontend/sdks/invoke/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ tardis = { workspace = true, features = [
] }
simple-invoke-client-macro = { version = "0.2.0", path = "../simple-invoke-client-macro", optional = true }
crossbeam = "0.8"
asteroid-mq = { workspace = true, features = ["cluster-k8s"], optional = true }
asteroid-mq-sdk = { workspace = true, optional = true }
[dev-dependencies]
tardis = { workspace = true, features = ["test"] }
Expand Down
2 changes: 1 addition & 1 deletion frontend/sdks/invoke/src/invoke_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Default for InvokeConfig {
(InvokeModuleKind::Schedule.to_string(), "http://127.0.0.1:8080/schedule".to_string()),
(InvokeModuleKind::Iam.to_string(), "http://127.0.0.1:8080/iam".to_string()),
(InvokeModuleKind::Stats.to_string(), "http://127.0.0.1:8080/spi-stats".to_string()),
(InvokeModuleKind::Event.to_string(), "http://127.0.0.1:8080/event".to_string()),
(InvokeModuleKind::Event.to_string(), "http://bios-event:8080/event".to_string()),
(InvokeModuleKind::Reach.to_string(), "http://127.0.0.1:8080/reach".to_string()),
]),
module_configs: HashMap::from([
Expand Down

0 comments on commit cf0b403

Please sign in to comment.