-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add 'GET health/inspection' endpoint
- Loading branch information
1 parent
ed73c1d
commit 536ee0f
Showing
3 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
catalyst-gateway/bin/src/service/api/health/inspection_get.rs
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,76 @@ | ||
//! Implementation of the GET /health/inspection endpoint | ||
|
||
use std::sync::Arc; | ||
|
||
use poem::web::Data; | ||
use poem_extensions::{response, UniResponse::T204}; | ||
use tracing::{debug, error}; | ||
|
||
use crate::{ | ||
logger::LogLevel, | ||
service::common::responses::{ | ||
resp_2xx::NoContent, | ||
resp_4xx::ApiValidationError, | ||
resp_5xx::{ServerError, ServiceUnavailable}, | ||
}, | ||
state::{DeepQueryInspection, State}, | ||
}; | ||
|
||
/// All responses | ||
pub(crate) type AllResponses = response! { | ||
204: NoContent, | ||
400: ApiValidationError, | ||
500: ServerError, | ||
503: ServiceUnavailable, | ||
}; | ||
|
||
/// # GET /health/inspection | ||
/// | ||
/// Inspection settings endpoint. | ||
/// | ||
/// | ||
/// ## Responses | ||
/// | ||
/// * 204 No Content - Service is Started and can serve requests. | ||
/// * 400 API Validation Error | ||
/// * 500 Server Error - If anything within this function fails unexpectedly. (Possible | ||
/// but unlikely) | ||
/// * 503 Service Unavailable - Service has not started, do not send other requests. | ||
#[allow(clippy::unused_async)] | ||
pub(crate) async fn endpoint( | ||
state: Data<&Arc<State>>, log_level: Option<LogLevel>, | ||
query_inspection: Option<DeepQueryInspection>, | ||
) -> AllResponses { | ||
if let Some(level) = log_level { | ||
match state.inspection_settings().modify_logger_level(level) { | ||
Ok(()) => { | ||
debug!("successfully set log level to: {:?}", level); | ||
}, | ||
Err(_) => { | ||
error!("failed to set log level: {:?}", level); | ||
}, | ||
} | ||
} | ||
|
||
if let Some(inspection_mode) = query_inspection { | ||
match state | ||
.inspection_settings() | ||
.modify_deep_query(inspection_mode) | ||
{ | ||
Ok(()) => { | ||
debug!( | ||
"successfully set deep query inspection mode to: {:?}", | ||
inspection_mode | ||
); | ||
}, | ||
Err(_) => { | ||
error!( | ||
"failed to set deep query inspection mode: {:?}", | ||
inspection_mode | ||
); | ||
}, | ||
} | ||
} | ||
// otherwise everything seems to be A-OK | ||
T204(NoContent) | ||
} |
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