mirror of
https://github.com/sadoyan/aralez.git
synced 2026-07-01 03:42:21 +08:00
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -136,7 +136,6 @@ dependencies = [
|
|||||||
"base16ct 1.0.0",
|
"base16ct 1.0.0",
|
||||||
"base64",
|
"base64",
|
||||||
"dashmap",
|
"dashmap",
|
||||||
"futures",
|
|
||||||
"instant-acme",
|
"instant-acme",
|
||||||
"jsonwebtoken",
|
"jsonwebtoken",
|
||||||
"libc",
|
"libc",
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ pingora-limits = "0.8.1"
|
|||||||
dashmap = "7.0.0-rc2"
|
dashmap = "7.0.0-rc2"
|
||||||
async-trait = "0.1.89"
|
async-trait = "0.1.89"
|
||||||
log = "0.4.30"
|
log = "0.4.30"
|
||||||
futures = "0.3.32"
|
|
||||||
notify = "9.0.0-rc.4"
|
notify = "9.0.0-rc.4"
|
||||||
axum = { version = "0.8.9" }
|
axum = { version = "0.8.9" }
|
||||||
reqwest = { version = "0.13.4", features = ["json", "stream", "blocking"] }
|
reqwest = { version = "0.13.4", features = ["json", "stream", "blocking"] }
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ use crate::utils::kuberconsul::{ConsulDiscovery, KubernetesDiscovery, ServiceDis
|
|||||||
use crate::utils::structs::{Configuration, UpstreamsDashMap};
|
use crate::utils::structs::{Configuration, UpstreamsDashMap};
|
||||||
use crate::web::webserver;
|
use crate::web::webserver;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use futures::channel::mpsc::Sender;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use tokio::sync::mpsc::Sender;
|
||||||
|
|
||||||
pub struct APIUpstreamProvider {
|
pub struct APIUpstreamProvider {
|
||||||
pub config_api_enabled: bool,
|
pub config_api_enabled: bool,
|
||||||
@@ -46,7 +46,7 @@ impl Discovery for APIUpstreamProvider {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Discovery for FromFileProvider {
|
impl Discovery for FromFileProvider {
|
||||||
async fn start(&self, tx: Sender<Configuration>) {
|
async fn start(&self, tx: Sender<Configuration>) {
|
||||||
tokio::spawn(filewatch::start(self.path.clone(), tx.clone()));
|
tokio::spawn(filewatch::start(self.path.clone(), tx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
use crate::utils::parceyaml::load_configuration;
|
use crate::utils::parceyaml::load_configuration;
|
||||||
use crate::utils::structs::Configuration;
|
use crate::utils::structs::Configuration;
|
||||||
use futures::channel::mpsc::Sender;
|
|
||||||
use futures::SinkExt;
|
|
||||||
use log::error;
|
use log::error;
|
||||||
use notify::event::ModifyKind;
|
use notify::event::ModifyKind;
|
||||||
use notify::{Config, Event, EventKind, RecommendedWatcher, RecursiveMode, Watcher};
|
use notify::{Config, Event, EventKind, RecommendedWatcher, RecursiveMode, Watcher};
|
||||||
use pingora::prelude::sleep;
|
use pingora::prelude::sleep;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
use tokio::sync::mpsc::Sender;
|
||||||
use tokio::task;
|
use tokio::task;
|
||||||
|
|
||||||
pub async fn start(fp: String, mut toreturn: Sender<Configuration>) {
|
pub async fn start(fp: String, toreturn: Sender<Configuration>) {
|
||||||
sleep(Duration::from_millis(50)).await; // For having nice logs :-)
|
sleep(Duration::from_millis(50)).await; // For having nice logs :-)
|
||||||
let file_path = fp.as_str();
|
let file_path = fp.as_str();
|
||||||
let parent_dir = Path::new(file_path).parent().unwrap();
|
let parent_dir = Path::new(file_path).parent().unwrap();
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ use crate::utils::structs::{Configuration, GlobalServiceMapping, InnerMap, Upstr
|
|||||||
use crate::utils::tools::{clone_dashmap_into, compare_dashmaps, print_upstreams};
|
use crate::utils::tools::{clone_dashmap_into, compare_dashmaps, print_upstreams};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use futures::channel::mpsc::Sender;
|
|
||||||
use futures::SinkExt;
|
|
||||||
use pingora::prelude::sleep;
|
use pingora::prelude::sleep;
|
||||||
use rand::RngExt;
|
use rand::RngExt;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@@ -18,6 +16,7 @@ use std::sync::Arc;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
use tokio::io::AsyncReadExt;
|
use tokio::io::AsyncReadExt;
|
||||||
|
use tokio::sync::mpsc::Sender;
|
||||||
|
|
||||||
#[derive(Debug, serde::Deserialize)]
|
#[derive(Debug, serde::Deserialize)]
|
||||||
pub struct KubeEndpoints {
|
pub struct KubeEndpoints {
|
||||||
@@ -95,7 +94,7 @@ pub struct ConsulDiscovery;
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ServiceDiscovery for KubernetesDiscovery {
|
impl ServiceDiscovery for KubernetesDiscovery {
|
||||||
async fn fetch_upstreams(&self, config: Arc<Configuration>, mut toreturn: Sender<Configuration>) {
|
async fn fetch_upstreams(&self, config: Arc<Configuration>, toreturn: Sender<Configuration>) {
|
||||||
let prev_upstreams = UpstreamsDashMap::new();
|
let prev_upstreams = UpstreamsDashMap::new();
|
||||||
|
|
||||||
if let Some(kuber) = config.kubernetes.clone() {
|
if let Some(kuber) = config.kubernetes.clone() {
|
||||||
@@ -162,7 +161,7 @@ fn get_current_namespace() -> Option<String> {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ServiceDiscovery for ConsulDiscovery {
|
impl ServiceDiscovery for ConsulDiscovery {
|
||||||
async fn fetch_upstreams(&self, config: Arc<Configuration>, mut toreturn: Sender<Configuration>) {
|
async fn fetch_upstreams(&self, config: Arc<Configuration>, toreturn: Sender<Configuration>) {
|
||||||
let prev_upstreams = UpstreamsDashMap::new();
|
let prev_upstreams = UpstreamsDashMap::new();
|
||||||
loop {
|
loop {
|
||||||
let upstreams = UpstreamsDashMap::new();
|
let upstreams = UpstreamsDashMap::new();
|
||||||
|
|||||||
@@ -23,15 +23,6 @@ pub static REQUEST_COUNT: LazyLock<IntCounter> = LazyLock::new(|| register_int_c
|
|||||||
pub static RESPONSE_CODES: LazyLock<IntCounterVec> =
|
pub static RESPONSE_CODES: LazyLock<IntCounterVec> =
|
||||||
LazyLock::new(|| register_int_counter_vec!("aralez_responses_total", "Responses grouped by status code", &["status"]).unwrap());
|
LazyLock::new(|| register_int_counter_vec!("aralez_responses_total", "Responses grouped by status code", &["status"]).unwrap());
|
||||||
|
|
||||||
// pub static RESPONSE_LATENCY: LazyLock<Histogram> = LazyLock::new(|| {
|
|
||||||
// register_histogram!(
|
|
||||||
// "aralez_response_latency_seconds",
|
|
||||||
// "Response latency in seconds",
|
|
||||||
// vec![0.01, 0.05, 0.1, 0.25, 0.5, 1.0, 2.0, 5.0]
|
|
||||||
// )
|
|
||||||
// .unwrap()
|
|
||||||
// });
|
|
||||||
|
|
||||||
pub static RESPONSE_LATENCY: LazyLock<Histogram> = LazyLock::new(|| {
|
pub static RESPONSE_LATENCY: LazyLock<Histogram> = LazyLock::new(|| {
|
||||||
register_histogram!(
|
register_histogram!(
|
||||||
"aralez_response_latency_seconds",
|
"aralez_response_latency_seconds",
|
||||||
|
|||||||
@@ -8,18 +8,17 @@ use crate::web::logging::init_logging;
|
|||||||
use crate::web::proxyhttp::LB;
|
use crate::web::proxyhttp::LB;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use futures::channel::mpsc;
|
|
||||||
use futures::{SinkExt, StreamExt};
|
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use pingora_core::server::ShutdownWatch;
|
use pingora_core::server::ShutdownWatch;
|
||||||
use pingora_core::services::background::BackgroundService;
|
use pingora_core::services::background::BackgroundService;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl BackgroundService for LB {
|
impl BackgroundService for LB {
|
||||||
async fn start(&self, mut shutdown: ShutdownWatch) {
|
async fn start(&self, mut shutdown: ShutdownWatch) {
|
||||||
info!("Starting background service"); // tx: Sender<Configuration>
|
info!("Starting background service"); // tx: Sender<Configuration>
|
||||||
let (mut tx, mut rx) = mpsc::channel::<Configuration>(1);
|
let (tx, mut rx) = mpsc::channel::<Configuration>(1);
|
||||||
let tx_api = tx.clone();
|
let tx_api = tx.clone();
|
||||||
let config = load_configuration(self.config.upstreams_conf.clone().as_str(), "filepath")
|
let config = load_configuration(self.config.upstreams_conf.clone().as_str(), "filepath")
|
||||||
.await
|
.await
|
||||||
@@ -84,7 +83,7 @@ impl BackgroundService for LB {
|
|||||||
_ = shutdown.changed() => {
|
_ = shutdown.changed() => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
val = rx.next() => {
|
val = rx.recv() => {
|
||||||
if let Some(ss) = val {
|
if let Some(ss) = val {
|
||||||
clone_dashmap_into(&ss.upstreams, &self.ump_full);
|
clone_dashmap_into(&ss.upstreams, &self.ump_full);
|
||||||
clone_dashmap_into(&ss.upstreams, &self.ump_upst);
|
clone_dashmap_into(&ss.upstreams, &self.ump_upst);
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ use axum::http::{Response, StatusCode};
|
|||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
use axum::routing::{any, get, post};
|
use axum::routing::{any, get, post};
|
||||||
use axum::{Json, Router};
|
use axum::{Json, Router};
|
||||||
use futures::channel::mpsc::Sender;
|
|
||||||
use futures::SinkExt;
|
|
||||||
use jsonwebtoken::{encode, EncodingKey, Header};
|
use jsonwebtoken::{encode, EncodingKey, Header};
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use prometheus::{gather, Encoder, TextEncoder};
|
use prometheus::{gather, Encoder, TextEncoder};
|
||||||
@@ -37,14 +35,14 @@ pub(crate) struct AppState {
|
|||||||
pub(crate) cert_creds: String,
|
pub(crate) cert_creds: String,
|
||||||
pub(crate) certs_dir: String,
|
pub(crate) certs_dir: String,
|
||||||
upstreams_file: String,
|
upstreams_file: String,
|
||||||
config_sender: Sender<Configuration>,
|
config_sender: mpsc::Sender<Configuration>,
|
||||||
config_api_enabled: bool,
|
config_api_enabled: bool,
|
||||||
current_upstreams: Arc<UpstreamsDashMap>,
|
current_upstreams: Arc<UpstreamsDashMap>,
|
||||||
full_upstreams: Arc<UpstreamsDashMap>,
|
full_upstreams: Arc<UpstreamsDashMap>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
pub async fn run_server(config: &APIUpstreamProvider, mut to_return: Sender<Configuration>, upstreams_curr: Arc<UpstreamsDashMap>, upstreams_full: Arc<UpstreamsDashMap>) {
|
pub async fn run_server(config: &APIUpstreamProvider, mut to_return: mpsc::Sender<Configuration>, upstreams_curr: Arc<UpstreamsDashMap>, upstreams_full: Arc<UpstreamsDashMap>) {
|
||||||
let credsfile = config.config_dir.clone() + "/acme_credentials.json";
|
let credsfile = config.config_dir.clone() + "/acme_credentials.json";
|
||||||
let app_state = AppState {
|
let app_state = AppState {
|
||||||
master_key: config.masterkey.clone(),
|
master_key: config.masterkey.clone(),
|
||||||
@@ -119,7 +117,7 @@ async fn conf(State(st): State<AppState>, Query(params): Query<HashMap<String, S
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn apply_config(content: &str, mut st: AppState, save: bool) {
|
async fn apply_config(content: &str, st: AppState, save: bool) {
|
||||||
let sl = crate::utils::parceyaml::load_configuration(content, "content").await;
|
let sl = crate::utils::parceyaml::load_configuration(content, "content").await;
|
||||||
if let Some(serverlist) = sl.0 {
|
if let Some(serverlist) = sl.0 {
|
||||||
if save {
|
if save {
|
||||||
|
|||||||
Reference in New Issue
Block a user