Skip to content

Commit ebe820f

Browse files
committed
refactor: adjust pingap workspace member
1 parent beecaeb commit ebe820f

File tree

8 files changed

+73
-164
lines changed

8 files changed

+73
-164
lines changed

Cargo.lock

+3-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-14
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,23 @@ default-run = "pingap"
1919
ahash = { version = "0.8.11", default-features = false }
2020
arc-swap = "1.7.1"
2121
async-trait = "0.1.86"
22-
base64 = "0.22.1"
23-
bstr = "1.11.3"
2422
bytes = "1.9.0"
25-
bytesize = { version = "1.3.0", features = ["serde"] }
2623
cfg-if = "1.0.0"
27-
chrono = { version = "0.4.39", default-features = false, features = [
28-
"std",
29-
"clock",
30-
] }
3124
clap = { version = "4.5.28", features = [
3225
"derive",
3326
"std",
3427
"help",
3528
"usage",
3629
], default-features = false }
37-
cookie = "0.18.1"
3830
crc32fast = "1.4.2"
3931
crossbeam-channel = "0.5.14"
40-
fancy-regex = "0.14.0"
4132
flate2 = "1.0.35"
4233
glob = "0.3.2"
4334
hex = "0.4.3"
44-
hmac-sha256 = "1.1.8"
45-
hmac-sha512 = { version = "1.1.6", default-features = false }
4635
http = "1.2.0"
4736
humantime = "2.1.0"
4837
humantime-serde = "1.1.1"
4938
itoa = "1.0.14"
50-
mime_guess = "2.0.5"
5139
nanoid = "0.4.0"
5240
nix = { version = "0.29.0", features = ["signal"] }
5341
num_cpus = "1.16.0"
@@ -62,7 +50,6 @@ pingora = { git = "https://github.com/cloudflare/pingora", rev = "e6b823c5d89860
6250
"openssl",
6351
"cache",
6452
] }
65-
pingora-limits = "0.4.0"
6653
regex = { version = "1.11.1", default-features = false }
6754
rust-embed = { version = "8.5.0", features = [
6855
"mime-guess",
@@ -72,7 +59,6 @@ scopeguard = "1.2.0"
7259
serde = "1.0.217"
7360
serde_json = "1.0.138"
7461
sha2 = { version = "0.10.8", default-features = false }
75-
smallvec = "1.13.2"
7662
snafu = { version = "0.8.5", features = ["std"], default-features = false }
7763
substring = "1.4.5"
7864
tokio = { version = "1.43.0", default-features = false, features = ["fs"] }
@@ -103,6 +89,7 @@ pingap-plugin = { path = "pingap-plugin" }
10389
pingap-otel = { path = "pingap-otel", optional = true }
10490
pingap-sentry = { path = "pingap-sentry", optional = true }
10591
pingap-pyroscope = { path = "pingap-pyroscope", optional = true }
92+
ctor = "0.2.9"
10693

10794

10895
[features]

pingap-plugin/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ uuid = { version = "1.12.1", features = [
2626
"fast-rng",
2727
], default-features = false }
2828
bstr = "1.11.3"
29+
fancy-regex = "0.14.0"
2930
url = { workspace = true }
3031
urlencoding = { workspace = true }
3132
bytesize = { workspace = true }
@@ -57,6 +58,7 @@ pingap-http-extra = { path = "../pingap-http-extra" }
5758
pingap-state = { path = "../pingap-state" }
5859
pingap-config = { path = "../pingap-config" }
5960
pingap-util = { path = "../pingap-util" }
61+
pingap-cache = { path = "../pingap-cache" }
6062

6163

6264
[dev-dependencies]

src/plugin/cache.rs pingap-plugin/src/cache.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
// limitations under the License.
1414

1515
use super::{
16-
get_bool_conf, get_hash_key, get_str_conf, get_str_slice_conf, Error,
17-
Plugin, Result,
16+
get_bool_conf, get_hash_key, get_plugin_factory, get_str_conf,
17+
get_str_slice_conf, Error, Plugin,
1818
};
1919
use async_trait::async_trait;
2020
use bytes::{BufMut, Bytes, BytesMut};
2121
use bytesize::ByteSize;
22+
use ctor::ctor;
2223
use fancy_regex::Regex;
2324
use http::{Method, StatusCode};
2425
use humantime::parse_duration;
@@ -36,9 +37,12 @@ use pingora::cache::lock::{CacheKeyLock, CacheLock};
3637
use pingora::cache::predictor::{CacheablePredictor, Predictor};
3738
use pingora::proxy::Session;
3839
use std::str::FromStr;
40+
use std::sync::Arc;
3941
use std::time::Duration;
4042
use tracing::{debug, error};
4143

44+
type Result<T> = std::result::Result<T, Error>;
45+
4246
// Maximum memory size for cache (100MB) - default if not configured otherwise
4347
const MAX_MEMORY_SIZE: usize = 100 * 1024 * 1024;
4448

@@ -447,11 +451,16 @@ impl Plugin for Cache {
447451
}
448452
}
449453

454+
#[ctor]
455+
fn init() {
456+
get_plugin_factory()
457+
.register("cache", |params| Ok(Arc::new(Cache::new(params)?)));
458+
}
459+
450460
#[cfg(test)]
451461
mod tests {
452-
use super::Cache;
462+
use super::*;
453463
use pingap_config::{PluginConf, PluginStep};
454-
use pingap_plugin::Plugin;
455464
use pingap_state::Ctx;
456465
use pingora::proxy::Session;
457466
use pretty_assertions::assert_eq;

pingap-plugin/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ pub enum Error {
3333
max: isize,
3434
value: isize,
3535
},
36+
#[snafu(display("Plugin {category}, regex error {source}"))]
37+
Regex {
38+
category: String,
39+
source: Box<fancy_regex::Error>,
40+
},
41+
#[snafu(display("Plugin {category}, base64 decode error {source}"))]
42+
ParseDuration {
43+
category: String,
44+
source: humantime::DurationError,
45+
},
3646
}
3747

3848
/// Helper functions for accessing plugin configuration values
@@ -110,6 +120,7 @@ pub(crate) fn get_hash_key(conf: &PluginConf) -> String {
110120

111121
mod accept_encoding;
112122
mod basic_auth;
123+
mod cache;
113124
mod combined_auth;
114125
mod compression;
115126
mod cors;

src/plugin/admin.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
// limitations under the License.
1414

1515
use super::{
16-
get_hash_key, get_int_conf, get_str_conf, get_str_slice_conf, Error,
17-
Plugin, Result,
16+
get_hash_key, get_int_conf, get_str_conf, get_str_slice_conf, Plugin,
1817
};
1918
use crate::process::{get_start_time, restart_now};
2019
use async_trait::async_trait;
2120
use bytes::Bytes;
2221
use bytes::{BufMut, BytesMut};
22+
use ctor::ctor;
2323
use flate2::write::GzEncoder;
2424
use flate2::Compression;
2525
use hex::encode;
@@ -42,6 +42,7 @@ use pingap_http_extra::HttpResponse;
4242
use pingap_limit::TtlLruLimit;
4343
use pingap_performance::get_process_system_info;
4444
use pingap_performance::get_processing_accepted;
45+
use pingap_plugin::{get_plugin_factory, Error};
4546
use pingap_state::Ctx;
4647
use pingap_util::base64_decode;
4748
use pingora::http::RequestHeader;
@@ -53,11 +54,14 @@ use serde::{Deserialize, Serialize};
5354
use sha2::{Digest, Sha256};
5455
use std::collections::HashMap;
5556
use std::io::Write;
57+
use std::sync::Arc;
5658
use std::time::Duration;
5759
use substring::Substring;
5860
use tracing::{debug, error};
5961
use urlencoding::decode;
6062

63+
type Result<T> = std::result::Result<T, Error>;
64+
6165
#[derive(RustEmbed)]
6266
#[folder = "dist/"]
6367
struct AdminAsset;
@@ -671,6 +675,12 @@ impl Plugin for AdminServe {
671675
}
672676
}
673677

678+
#[ctor]
679+
fn init() {
680+
get_plugin_factory()
681+
.register("admin", |params| Ok(Arc::new(AdminServe::new(params)?)));
682+
}
683+
674684
#[cfg(test)]
675685
mod tests {
676686
use super::{AdminAsset, AdminServe, EmbeddedStaticFile};

0 commit comments

Comments
 (0)