mirror of
https://github.com/tursodatabase/libsql.git
synced 2025-07-16 05:25:18 +00:00
add admin endpoint to dynamically set log filter
This commit is contained in:
@ -48,6 +48,7 @@ struct AppState<C> {
|
||||
user_http_server: Arc<hrana::http::Server>,
|
||||
connector: C,
|
||||
metrics: Metrics,
|
||||
set_env_filter: Option<Box<dyn Fn(&str) -> anyhow::Result<()> + Sync + Send + 'static>>,
|
||||
}
|
||||
|
||||
impl<C> FromRef<Arc<AppState<C>>> for Metrics {
|
||||
@ -66,6 +67,7 @@ pub async fn run<A, C>(
|
||||
disable_metrics: bool,
|
||||
shutdown: Arc<Notify>,
|
||||
auth: Option<Arc<str>>,
|
||||
set_env_filter: Option<Box<dyn Fn(&str) -> anyhow::Result<()> + Sync + Send + 'static>>,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
A: crate::net::Accept,
|
||||
@ -167,11 +169,13 @@ where
|
||||
.route("/profile/heap/enable", post(enable_profile_heap))
|
||||
.route("/profile/heap/disable/:id", post(disable_profile_heap))
|
||||
.route("/profile/heap/:id", delete(delete_profile_heap))
|
||||
.route("/log-filter", post(handle_set_log_filter))
|
||||
.with_state(Arc::new(AppState {
|
||||
namespaces: namespaces.clone(),
|
||||
connector,
|
||||
user_http_server,
|
||||
metrics,
|
||||
set_env_filter,
|
||||
}))
|
||||
.layer(
|
||||
tower_http::trace::TraceLayer::new_for_http()
|
||||
@ -512,6 +516,16 @@ async fn handle_delete_namespace<C>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_set_log_filter<C>(
|
||||
State(app_state): State<Arc<AppState<C>>>,
|
||||
body: String,
|
||||
) -> crate::Result<()> {
|
||||
if let Some(ref cb) = app_state.set_env_filter {
|
||||
cb(&body)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_checkpoint<C>(
|
||||
State(app_state): State<Arc<AppState<C>>>,
|
||||
Path(namespace): Path<NamespaceName>,
|
||||
|
@ -7,7 +7,6 @@ use axum::middleware::Next;
|
||||
use axum::response::Response;
|
||||
use hashbrown::HashMap;
|
||||
use parking_lot::Mutex;
|
||||
use tracing::{Instrument, Span};
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct Timings {
|
||||
|
@ -181,7 +181,7 @@ pub struct Server<C = HttpConnector, A = AddrIncoming, D = HttpsConnector<HttpCo
|
||||
pub should_sync_from_storage: bool,
|
||||
pub force_load_wals: bool,
|
||||
pub sync_conccurency: usize,
|
||||
pub set_log_level: Option<Box<dyn Fn(&str) -> anyhow::Result<()> + Send +'static>>
|
||||
pub set_log_level: Option<Box<dyn Fn(&str) -> anyhow::Result<()> + Send + Sync + 'static>>,
|
||||
}
|
||||
|
||||
impl<C, A, D> Default for Server<C, A, D> {
|
||||
@ -227,6 +227,7 @@ struct Services<A, P, S, C> {
|
||||
disable_default_namespace: bool,
|
||||
db_config: DbConfig,
|
||||
user_auth_strategy: Auth,
|
||||
pub set_log_level: Option<Box<dyn Fn(&str) -> anyhow::Result<()> + Send + Sync + 'static>>,
|
||||
}
|
||||
|
||||
struct TaskManager {
|
||||
@ -306,7 +307,7 @@ where
|
||||
S: ReplicationLog,
|
||||
C: Connector,
|
||||
{
|
||||
fn configure(self, task_manager: &mut TaskManager) {
|
||||
fn configure(mut self, task_manager: &mut TaskManager) {
|
||||
let user_http = UserApi {
|
||||
http_acceptor: self.user_api_config.http_acceptor,
|
||||
hrana_ws_acceptor: self.user_api_config.hrana_ws_acceptor,
|
||||
@ -341,6 +342,7 @@ where
|
||||
disable_metrics,
|
||||
shutdown,
|
||||
auth_key.map(Into::into),
|
||||
self.set_log_level.take(),
|
||||
)
|
||||
});
|
||||
}
|
||||
@ -540,7 +542,7 @@ where
|
||||
}
|
||||
|
||||
fn make_services<P: Proxy, L: ReplicationLog>(
|
||||
self,
|
||||
mut self,
|
||||
namespace_store: NamespaceStore,
|
||||
idle_shutdown_kicker: Option<IdleShutdownKicker>,
|
||||
proxy_service: P,
|
||||
@ -558,6 +560,7 @@ where
|
||||
disable_default_namespace: self.disable_default_namespace,
|
||||
db_config: self.db_config,
|
||||
user_auth_strategy,
|
||||
set_log_level: self.set_log_level.take(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,9 @@ use hyper::client::HttpConnector;
|
||||
use libsql_server::auth::{parse_http_basic_auth_arg, parse_jwt_keys, user_auth_strategies, Auth};
|
||||
use tokio::sync::Notify;
|
||||
use tokio::time::Duration;
|
||||
use tracing_subscriber::{prelude::*, EnvFilter};
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
use tracing_subscriber::Layer;
|
||||
use tracing_subscriber::{prelude::*, EnvFilter};
|
||||
|
||||
use libsql_server::config::{
|
||||
AdminApiConfig, BottomlessConfig, DbConfig, HeartbeatConfig, MetaStoreConfig, RpcClientConfig,
|
||||
@ -642,7 +642,10 @@ fn make_meta_store_config(config: &Cli) -> anyhow::Result<MetaStoreConfig> {
|
||||
})
|
||||
}
|
||||
|
||||
async fn build_server(config: &Cli, set_log_level: impl Fn(&str) -> anyhow::Result<()> + Send + 'static) -> anyhow::Result<Server> {
|
||||
async fn build_server(
|
||||
config: &Cli,
|
||||
set_log_level: impl Fn(&str) -> anyhow::Result<()> + Send + Sync + 'static,
|
||||
) -> anyhow::Result<Server> {
|
||||
let db_config = make_db_config(config)?;
|
||||
let user_api_config = make_user_api_config(config).await?;
|
||||
let admin_api_config = make_admin_api_config(config).await?;
|
||||
@ -750,9 +753,10 @@ async fn main() -> Result<()> {
|
||||
#[cfg(feature = "debug-tools")]
|
||||
enable_libsql_logging();
|
||||
|
||||
let (filter, reload_handle) = tracing_subscriber::reload::Layer::new(tracing_subscriber::EnvFilter::from_default_env());
|
||||
let (filter, reload_handle) =
|
||||
tracing_subscriber::reload::Layer::new(tracing_subscriber::EnvFilter::from_default_env());
|
||||
let set_log_level = move |s: &str| -> anyhow::Result<()> {
|
||||
let filter = EnvFilter::from_str(s)?;
|
||||
let filter = EnvFilter::from_str(s.trim())?;
|
||||
reload_handle.reload(filter)?;
|
||||
Ok(())
|
||||
};
|
||||
|
Reference in New Issue
Block a user