Line data Source code
1 : use axum::response::{IntoResponse, Response};
2 : use http::StatusCode;
3 : use tracing::info;
4 : use utils::failpoint_support::{apply_failpoint, ConfigureFailpointsRequest};
5 :
6 : use crate::http::{extract::Json, JsonResponse};
7 :
8 : /// Configure failpoints for testing purposes.
9 0 : pub(in crate::http) async fn configure_failpoints(
10 0 : failpoints: Json<ConfigureFailpointsRequest>,
11 0 : ) -> Response {
12 0 : if !fail::has_failpoints() {
13 0 : return JsonResponse::error(
14 0 : StatusCode::PRECONDITION_FAILED,
15 0 : "Cannot manage failpoints because neon was compiled without failpoints support",
16 0 : );
17 0 : }
18 :
19 0 : for fp in &*failpoints {
20 0 : info!("cfg failpoint: {} {}", fp.name, fp.actions);
21 :
22 : // We recognize one extra "action" that's not natively recognized
23 : // by the failpoints crate: exit, to immediately kill the process
24 0 : let cfg_result = apply_failpoint(&fp.name, &fp.actions);
25 :
26 0 : if let Err(e) = cfg_result {
27 0 : return JsonResponse::error(
28 0 : StatusCode::BAD_REQUEST,
29 0 : format!("failed to configure failpoints: {e}"),
30 0 : );
31 0 : }
32 : }
33 :
34 0 : StatusCode::OK.into_response()
35 0 : }
|