Skip to content

Commit

Permalink
refactor: adjust pingap workspace member
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Feb 8, 2025
1 parent d31293b commit d372af3
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 79 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions pingap-state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ itoa = { workspace = true }
opentelemetry = { version = "0.27.1", default-features = false, features = [
"trace",
], optional = true }
tokio = { workspace = true }
pingap-location = { path = "../pingap-location" }
pingap-upstream = { path = "../pingap-upstream" }
pingap-util = { path = "../pingap-util" }
Expand Down
22 changes: 2 additions & 20 deletions src/http_extra/http_header.rs → pingap-state/src/http_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use super::Ctx;
use bytes::BytesMut;
use http::HeaderValue;
use pingap_state::Ctx;
use pingap_util::get_hostname;
use pingora::proxy::Session;

Expand Down Expand Up @@ -162,29 +162,11 @@ fn handle_context_value(buf: &[u8], ctx: &Ctx) -> Option<HeaderValue> {

#[cfg(test)]
mod tests {
use super::convert_header_value;
use super::*;
use http::HeaderValue;
use pingap_http_extra::convert_headers;
use pingap_state::Ctx;
use pingora::proxy::Session;
use pretty_assertions::assert_eq;
use tokio_test::io::Builder;
#[test]
fn test_convert_headers() {
let headers = convert_headers(&[
"Content-Type: application/octet-stream".to_string(),
"X-Server: $hostname".to_string(),
"X-User: $USER".to_string(),
])
.unwrap();
assert_eq!(3, headers.len());
assert_eq!("content-type", headers[0].0.to_string());
assert_eq!("application/octet-stream", headers[0].1.to_str().unwrap());
assert_eq!("x-server", headers[1].0.to_string());
assert_eq!(false, headers[1].1.to_str().unwrap().is_empty());
assert_eq!("x-user", headers[2].0.to_string());
assert_eq!(false, headers[2].1.to_str().unwrap().is_empty());
}

#[tokio::test]
async fn test_convert_header_value() {
Expand Down
2 changes: 2 additions & 0 deletions pingap-state/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
// limitations under the License.

mod ctx;
mod http_header;

pub use ctx::*;
pub use http_header::*;
17 changes: 0 additions & 17 deletions src/http_extra/mod.rs

This file was deleted.

4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod http_extra;
pub mod plugin;
pub mod process;
pub mod proxy;
pub mod service;
pub mod state;
15 changes: 7 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ use pingap_upstream::{new_upstream_health_check_task, try_init_upstreams};
use pingora::server;
use pingora::server::configuration::Opt;
use pingora::services::background::background_service;
use process::{
get_admin_addr, get_start_time, new_auto_restart_service,
new_observer_service, set_admin_addr,
};
use proxy::{Server, ServerConf};
use service::{new_auto_restart_service, new_observer_service};
use state::{get_admin_addr, get_start_time, set_admin_addr};
use std::collections::HashMap;
use std::error::Error;
use std::ffi::OsString;
Expand All @@ -42,12 +44,9 @@ use std::sync::Arc;
use std::time::Duration;
use tracing::{error, info};

mod http_extra;

mod plugin;
mod process;
mod proxy;
mod service;
mod state;

static TEMPLATE_CONFIG: &str = r###"
[basic]
Expand Down Expand Up @@ -379,7 +378,7 @@ fn run() -> Result<(), Box<dyn Error>> {
info!("Enable feature perf");

if let Ok(exec_path) = std::env::current_exe() {
let mut cmd = state::RestartProcessCommand {
let mut cmd = process::RestartProcessCommand {
exec_path,
..Default::default()
};
Expand Down Expand Up @@ -407,7 +406,7 @@ fn run() -> Result<(), Box<dyn Error>> {
new_args.push("--autorestart".to_string());
}
cmd.args = new_args;
state::set_restart_process_command(cmd);
process::set_restart_process_command(cmd);
}

try_init_upstreams(&conf.upstreams)?;
Expand Down
3 changes: 1 addition & 2 deletions src/plugin/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use super::{
get_hash_key, get_int_conf, get_str_conf, get_str_slice_conf, Error,
Plugin, Result,
};
use crate::state::get_start_time;
use crate::state::restart_now;
use crate::process::{get_start_time, restart_now};
use async_trait::async_trait;
use bytes::Bytes;
use bytes::{BufMut, BytesMut};
Expand Down
3 changes: 1 addition & 2 deletions src/plugin/cors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
// limitations under the License.

use super::{get_bool_conf, get_hash_key, get_str_conf, Error, Plugin, Result};
use crate::http_extra::convert_header_value;
use async_trait::async_trait;
use http::{header, HeaderValue};
use humantime::parse_duration;
use pingap_config::{PluginCategory, PluginConf, PluginStep};
use pingap_http_extra::{HttpHeader, HttpResponse};
use pingap_state::Ctx;
use pingap_state::{convert_header_value, Ctx};
use pingora::http::ResponseHeader;
use pingora::proxy::Session;
use regex::Regex;
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::process::get_admin_addr;
use crate::proxy::ServerConf;
use crate::state::get_admin_addr;
use ahash::AHashMap;
use arc_swap::ArcSwap;
use async_trait::async_trait;
Expand Down
3 changes: 1 addition & 2 deletions src/plugin/response_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use super::{get_hash_key, get_str_slice_conf, Error, Plugin, Result};
use crate::http_extra::convert_header_value;
use async_trait::async_trait;
use http::header::HeaderName;
use pingap_config::{PluginCategory, PluginConf, PluginStep};
use pingap_http_extra::{convert_header, HttpHeader};
use pingap_state::Ctx;
use pingap_state::{convert_header_value, Ctx};
use pingora::http::ResponseHeader;
use pingora::proxy::Session;
use std::str::FromStr;
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

use super::{get_hash_key, get_step_conf, get_str_conf, Error, Plugin, Result};
use crate::state::get_start_time;
use crate::process::get_start_time;
use async_trait::async_trait;
use bytes::Bytes;
use pingap_config::{PluginCategory, PluginConf, PluginStep};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::state::restart;
use crate::process::restart;
use crate::{plugin, proxy};
use async_trait::async_trait;
use pingap_config::{
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions src/process/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mod auto_restart;
mod common;

pub const LOG_CATEGORY: &str = "process";

pub use auto_restart::*;
pub use common::*;
2 changes: 1 addition & 1 deletion src/proxy/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

use super::{ServerConf, LOG_CATEGORY};
use crate::http_extra::convert_header_value;
use crate::plugin::{get_plugin, ADMIN_SERVER_PLUGIN};
use ahash::AHashMap;
use arc_swap::ArcSwap;
Expand Down Expand Up @@ -44,6 +43,7 @@ use pingap_performance::{
new_prometheus, new_prometheus_push_service, Prometheus,
};
use pingap_service::SimpleServiceTaskFuture;
use pingap_state::convert_header_value;
#[cfg(feature = "full")]
use pingap_state::OtelTracer;
use pingap_state::{get_cache_key, CompressionStat, Ctx};
Expand Down
3 changes: 0 additions & 3 deletions src/service/mod.rs

This file was deleted.

18 changes: 0 additions & 18 deletions src/state/mod.rs

This file was deleted.

0 comments on commit d372af3

Please sign in to comment.