File watcher improvements

This commit is contained in:
Ara Sadoyan
2025-05-08 17:43:41 +02:00
parent a53e26a5db
commit 1be09d21fc
4 changed files with 8 additions and 8 deletions

View File

@@ -30,7 +30,6 @@ struct TaggedAddress {
pub async fn start(fp: String, mut toreturn: Sender<Configuration>) { pub async fn start(fp: String, mut toreturn: Sender<Configuration>) {
let config = load_configuration(fp.as_str(), "filepath"); let config = load_configuration(fp.as_str(), "filepath");
let headers = DashMap::new(); let headers = DashMap::new();
match config { match config {
Some(config) => { Some(config) => {
if config.typecfg.to_string() != "consul" { if config.typecfg.to_string() != "consul" {
@@ -55,7 +54,6 @@ pub async fn start(fp: String, mut toreturn: Sender<Configuration>) {
} }
let consul_data = servers.get(num).unwrap().to_string(); let consul_data = servers.get(num).unwrap().to_string();
let upstreams = consul_request(consul_data, consul.services.clone(), consul.token.clone()); let upstreams = consul_request(consul_data, consul.services.clone(), consul.token.clone());
match upstreams.await { match upstreams.await {
Some(upstreams) => { Some(upstreams) => {
if !compare_dashmaps(&upstreams, &prev_upstreams) { if !compare_dashmaps(&upstreams, &prev_upstreams) {

View File

@@ -2,7 +2,7 @@ use crate::utils::parceyaml::load_configuration;
use crate::utils::structs::Configuration; use crate::utils::structs::Configuration;
use futures::channel::mpsc::Sender; use futures::channel::mpsc::Sender;
use futures::SinkExt; use futures::SinkExt;
use log::{error, info}; use log::{error, info, warn};
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;
@@ -15,10 +15,15 @@ pub async fn start(fp: String, mut toreturn: Sender<Configuration>) {
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();
let (local_tx, mut local_rx) = tokio::sync::mpsc::channel::<notify::Result<Event>>(1); let (local_tx, mut local_rx) = tokio::sync::mpsc::channel::<notify::Result<Event>>(1);
info!("Watching for changes in {:?}", parent_dir);
let snd = load_configuration(file_path, "filepath"); let snd = load_configuration(file_path, "filepath");
match snd { match snd {
Some(snd) => { Some(snd) => {
if snd.typecfg != "file" {
warn!("Disabling file watcher, requested discovery type is: {}", snd.typecfg);
return;
}
info!("Watching for changes in {:?}", parent_dir);
toreturn.send(snd).await.unwrap(); toreturn.send(snd).await.unwrap();
} }
None => {} None => {}

View File

@@ -44,6 +44,7 @@ pub struct PathConfig {
pub servers: Vec<String>, pub servers: Vec<String>,
pub headers: Option<Vec<String>>, pub headers: Option<Vec<String>>,
} }
#[derive(Debug)]
pub struct Configuration { pub struct Configuration {
pub upstreams: UpstreamsDashMap, pub upstreams: UpstreamsDashMap,
pub headers: Headers, pub headers: Headers,

View File

@@ -54,14 +54,10 @@ impl BackgroundService for LB {
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);
self.proxyconf.clear(); self.proxyconf.clear();
// println!(" ====> {:?}", self.extraparams);
{ {
let mut write_guard = self.extraparams.write().await; let mut write_guard = self.extraparams.write().await;
write_guard.stickysessions = ss.extraparams.stickysessions; write_guard.stickysessions = ss.extraparams.stickysessions;
} }
// println!(" ====> {:?}", self.extraparams);
match ss.globals { match ss.globals {
Some(globals) => { Some(globals) => {
for (k,v) in globals { for (k,v) in globals {