-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a handler to dynamically change the log level. (#4662)
* Added a handler to dynamically change the log level. Usage example: just visit. http://localhost:7280/api/v1/log_level?filter=debug,hyper=debug,tantivy=info,quickwit_serve=debug * CR comment and compilation fix
- Loading branch information
1 parent
3b686a4
commit 862a7d8
Showing
9 changed files
with
102 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (C) 2024 Quickwit, Inc. | ||
// | ||
// Quickwit is offered under the AGPL v3.0 and as commercial software. | ||
// For commercial licensing, contact us at [email protected]. | ||
// | ||
// AGPL: | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as | ||
// published by the Free Software Foundation, either version 3 of the | ||
// License, or (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
use hyper::StatusCode; | ||
use serde::Deserialize; | ||
use tracing::{error, info}; | ||
use warp::{Filter, Rejection}; | ||
|
||
use crate::{with_arg, EnvFilterReloadFn}; | ||
|
||
#[derive(Deserialize)] | ||
struct EnvFilter { | ||
filter: String, | ||
} | ||
|
||
#[utoipa::path(get, tag = "Log level", path = "/log_level")] | ||
pub fn log_level_handler( | ||
env_filter_reload_fn: EnvFilterReloadFn, | ||
) -> impl warp::Filter<Extract = (impl warp::Reply,), Error = Rejection> + Clone { | ||
warp::path("log_level") | ||
.and(warp::get().or(warp::post()).unify()) | ||
.and(warp::path::end()) | ||
.and(with_arg(env_filter_reload_fn)) | ||
.and(warp::query::<EnvFilter>()) | ||
.then( | ||
|env_filter_reload_fn: EnvFilterReloadFn, env_filter: EnvFilter| async move { | ||
match env_filter_reload_fn(env_filter.filter.as_str()) { | ||
Ok(_) => { | ||
info!(filter = env_filter.filter, "change log level"); | ||
warp::reply::with_status( | ||
format!("changed log level to:[{}]", env_filter.filter), | ||
StatusCode::OK, | ||
) | ||
} | ||
Err(_) => { | ||
error!(filter = env_filter.filter, "invalid log level"); | ||
warp::reply::with_status( | ||
format!("invalid log level:[{}]", env_filter.filter), | ||
StatusCode::BAD_REQUEST, | ||
) | ||
} | ||
} | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters