Skip to content

Commit

Permalink
server side engines
Browse files Browse the repository at this point in the history
  • Loading branch information
livingshade committed Dec 1, 2023
1 parent f4a3af4 commit e0370c1
Show file tree
Hide file tree
Showing 50 changed files with 2,438 additions and 1 deletion.
42 changes: 42 additions & 0 deletions experimental/mrpc/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion experimental/mrpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ members = [
"phoenix-api/policy/admission-control",
"phoenix-api/policy/metrics",
"phoenix-api/policy/mutation",
# the pheonix plugins
"phoenix-api/policy/fault-server",
"phoenix-api/policy/logging-server",
"phoenix-api/policy/metrics-server",
"phoenix-api/policy/mutation-server",
"phoenix-api/policy/ratelimit-drop-server",
# the phoenix plugins
"plugin/mrpc",
"plugin/mrpclb",
"plugin/rpc_adapter",
Expand All @@ -88,6 +93,11 @@ members = [
"plugin/policy/admission-control",
"plugin/policy/metrics",
"plugin/policy/mutation",
"plugin/policy/fault-server",
"plugin/policy/logging-server",
"plugin/policy/metrics-server",
"plugin/policy/mutation-server",
"plugin/policy/ratelimit-drop-server",
# examples
"examples/rpc_echo",
"examples/rpc_bench",
Expand Down Expand Up @@ -123,6 +133,12 @@ phoenix-api-policy-delay = { path = "phoenix-api/policy/delay" }
phoenix-api-policy-admission-control = { path = "phoenix-api/policy/admission-control" }
phoenix-api-policy-metrics = { path = "phoenix-api/policy/metrics" }
phoenix-api-policy-mutation = { path = "phoenix-api/policy/mutation" }
phoenix-api-policy-fault-server = { path = "phoenix-api/policy/fault-server" }
phoenix-api-policy-logging-server = { path = "phoenix-api/policy/logging-server" }
phoenix-api-policy-metrics-server = { path = "phoenix-api/policy/metrics-server" }
phoenix-api-policy-mutation-server = { path = "phoenix-api/policy/mutation-server" }
phoenix-api-policy-ratelimit-drop-server = { path = "phoenix-api/policy/ratelimit-drop-server" }


mrpc-build = { path = "mrpc-build" }
mrpc-derive = { path = "mrpc-derive" }
Expand Down
32 changes: 32 additions & 0 deletions experimental/mrpc/load-mrpc-plugins.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,35 @@ config_string = '''
requests_per_sec = 4
bucket_size = 1000
'''

[[addons]]
name = "FaultServer"
lib_path = "plugins/libphoenix_fault_server.rlib"
config_string = '''
'''

[[addons]]
name = "LoggingServer"
lib_path = "plugins/libphoenix_logging_server.rlib"
config_string = '''
'''

[[addons]]
name = "MutationServer"
lib_path = "plugins/libphoenix_mutation_server.rlib"
config_string = '''
'''

[[addons]]
name = "MetricsServer"
lib_path = "plugins/libphoenix_metrics_server.rlib"
config_string = '''
'''

[[addons]]
name = "RateLimitDropServer"
lib_path = "plugins/libphoenix_ratelimit_drop_server.rlib"
config_string = '''
requests_per_sec = 4
bucket_size = 1000
'''
14 changes: 14 additions & 0 deletions experimental/mrpc/phoenix-api/policy/fault-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

[package]
name = "phoenix-api-policy-fault-server"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
phoenix-api.workspace = true

serde.workspace = true
itertools.workspace = true
rand.workspace = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "phoenix-api-policy-logging"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
phoenix-api.workspace = true

serde.workspace = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use serde::{Deserialize, Serialize};

type IResult<T> = Result<T, phoenix_api::Error>;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Request {
NewConfig(),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ResponseKind {}

#[derive(Debug, Serialize, Deserialize)]
pub struct Response(pub IResult<ResponseKind>);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod control_plane;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use serde::{Deserialize, Serialize};

type IResult<T> = Result<T, phoenix_api::Error>;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Request {
NewConfig(),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ResponseKind {}

#[derive(Debug, Serialize, Deserialize)]
pub struct Response(pub IResult<ResponseKind>);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod control_plane;
11 changes: 11 additions & 0 deletions experimental/mrpc/phoenix-api/policy/logging-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "phoenix-api-policy-logging-server"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
phoenix-api.workspace = true

serde.workspace = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use serde::{Deserialize, Serialize};

type IResult<T> = Result<T, phoenix_api::Error>;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Request {
NewConfig(),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ResponseKind {}

#[derive(Debug, Serialize, Deserialize)]
pub struct Response(pub IResult<ResponseKind>);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod control_plane;
11 changes: 11 additions & 0 deletions experimental/mrpc/phoenix-api/policy/metrics-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "phoenix-api-policy-metrics-server"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
phoenix-api.workspace = true

serde.workspace = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use serde::{Deserialize, Serialize};

type IResult<T> = Result<T, phoenix_api::Error>;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Request {
NewConfig(),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ResponseKind {}

#[derive(Debug, Serialize, Deserialize)]
pub struct Response(pub IResult<ResponseKind>);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod control_plane;
11 changes: 11 additions & 0 deletions experimental/mrpc/phoenix-api/policy/mutation-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "phoenix-api-policy-mutation-server"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
phoenix-api.workspace = true

serde.workspace = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use serde::{Deserialize, Serialize};

type IResult<T> = Result<T, phoenix_api::Error>;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Request {
NewConfig(),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ResponseKind {}

#[derive(Debug, Serialize, Deserialize)]
pub struct Response(pub IResult<ResponseKind>);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod control_plane;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "phoenix-api-policy-ratelimit-drop-server"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
phoenix-api.workspace = true

serde.workspace = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use serde::{Deserialize, Serialize};

type IResult<T> = Result<T, String>;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Request {
NewConfig(u64, u64),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ResponseKind {}

#[derive(Debug, Serialize, Deserialize)]
pub struct Response(pub IResult<ResponseKind>);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod control_plane;
28 changes: 28 additions & 0 deletions experimental/mrpc/plugin/policy/fault-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

[package]
name = "phoenix-FaultServer-server"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
phoenix_common.workspace = true
phoenix-api-policy-FaultServer.workspace = true
mrpc-marshal.workspace = true
mrpc-derive.workspace = true
shm.workspace = true
phoenix-api = { workspace = true, features = ["mrpc"] }

futures.workspace = true
minstant.workspace = true
thiserror.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
anyhow.workspace = true
nix.workspace = true
toml = { workspace = true, features = ["preserve_order"] }
bincode.workspace = true
chrono.workspace = true
itertools.workspace = true
rand.workspace = true
37 changes: 37 additions & 0 deletions experimental/mrpc/plugin/policy/fault-server/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use chrono::{Datelike, Timelike, Utc};
use phoenix_common::log;
use serde::{Deserialize, Serialize};

use chrono::prelude::*;
use itertools::iproduct;
use rand::Rng;

#[derive(Debug, Clone, Copy, DeFaultServer, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct FaultServerConfig {}

impl FaultServerConfig {
/// Get config from toml file
pub fn new(config: Option<&str>) -> anyhow::Result<Self> {
let config = toml::from_str(config.unwrap_or(""))?;
Ok(config)
}
}

pub fn create_log_file() -> std::fs::File {
std::fs::create_dir_all("/tmp/phoenix/log").expect("mkdir failed");
let now = Utc::now();
let date_string = format!(
"{}-{}-{}-{}-{}-{}",
now.year(),
now.month(),
now.day(),
now.hour(),
now.minute(),
now.second()
);
let file_name = format!("/tmp/phoenix/log/logging_engine_{}.log", date_string);
///log::info!("create log file {}", file_name);
let log_file = std::fs::File::create(file_name).expect("create file failed");
log_file
}
Loading

0 comments on commit e0370c1

Please sign in to comment.