You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-31 09:24:31 +03:00
Migrate /health
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2021 The Matrix.org Foundation C.I.C.
|
// Copyright 2021, 2022 The Matrix.org Foundation C.I.C.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
@ -12,36 +12,20 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use hyper::header::CONTENT_TYPE;
|
use axum::{extract::Extension, response::IntoResponse};
|
||||||
use mas_warp_utils::{
|
use mas_axum_utils::{internal_error, FancyError};
|
||||||
errors::WrapError,
|
use sqlx::PgPool;
|
||||||
filters::{self, database::connection},
|
|
||||||
};
|
|
||||||
use mime::TEXT_PLAIN;
|
|
||||||
use sqlx::{pool::PoolConnection, PgPool, Postgres};
|
|
||||||
use tracing::{info_span, Instrument};
|
use tracing::{info_span, Instrument};
|
||||||
use warp::{filters::BoxedFilter, reply::with_header, Filter, Rejection, Reply};
|
|
||||||
|
|
||||||
pub fn filter(pool: &PgPool) -> BoxedFilter<(Box<dyn Reply>,)> {
|
pub async fn get(Extension(pool): Extension<PgPool>) -> Result<impl IntoResponse, FancyError> {
|
||||||
warp::path!("health")
|
let mut conn = pool.acquire().await.map_err(internal_error)?;
|
||||||
.and(filters::trace::name("GET /health"))
|
|
||||||
.and(warp::get())
|
|
||||||
.and(connection(pool))
|
|
||||||
.and_then(get)
|
|
||||||
.boxed()
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get(mut conn: PoolConnection<Postgres>) -> Result<Box<dyn Reply>, Rejection> {
|
|
||||||
sqlx::query("SELECT $1")
|
sqlx::query("SELECT $1")
|
||||||
.bind(1_i64)
|
.bind(1_i64)
|
||||||
.execute(&mut conn)
|
.execute(&mut conn)
|
||||||
.instrument(info_span!("DB health"))
|
.instrument(info_span!("DB health"))
|
||||||
.await
|
.await
|
||||||
.wrap_error()?;
|
.map_err(internal_error)?;
|
||||||
|
|
||||||
Ok(Box::new(with_header(
|
Ok("ok")
|
||||||
"ok",
|
|
||||||
CONTENT_TYPE,
|
|
||||||
TEXT_PLAIN.to_string(),
|
|
||||||
)))
|
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ mod health;
|
|||||||
mod oauth2;
|
mod oauth2;
|
||||||
mod views;
|
mod views;
|
||||||
|
|
||||||
use self::{health::filter as health, oauth2::filter as oauth2, views::filter as views};
|
use self::{oauth2::filter as oauth2, views::filter as views};
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn root(
|
pub fn root(
|
||||||
@ -45,7 +45,6 @@ pub fn root(
|
|||||||
mailer: &Mailer,
|
mailer: &Mailer,
|
||||||
config: &RootConfig,
|
config: &RootConfig,
|
||||||
) -> BoxedFilter<(impl Reply,)> {
|
) -> BoxedFilter<(impl Reply,)> {
|
||||||
let health = health(pool);
|
|
||||||
let oauth2 = oauth2(pool, templates, key_store, encrypter, &config.http);
|
let oauth2 = oauth2(pool, templates, key_store, encrypter, &config.http);
|
||||||
let views = views(
|
let views = views(
|
||||||
pool,
|
pool,
|
||||||
@ -56,7 +55,7 @@ pub fn root(
|
|||||||
&config.csrf,
|
&config.csrf,
|
||||||
);
|
);
|
||||||
|
|
||||||
let filter = health.or(views).unify().or(oauth2);
|
let filter = views.or(oauth2);
|
||||||
|
|
||||||
filter.with(warp::log(module_path!())).boxed()
|
filter.with(warp::log(module_path!())).boxed()
|
||||||
}
|
}
|
||||||
@ -72,6 +71,7 @@ pub fn router<B: Send + 'static>(
|
|||||||
) -> Router<B> {
|
) -> Router<B> {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/", get(self::views::index::get))
|
.route("/", get(self::views::index::get))
|
||||||
|
.route("/health", get(self::health::get))
|
||||||
.fallback(mas_static_files::Assets)
|
.fallback(mas_static_files::Assets)
|
||||||
.layer(Extension(pool.clone()))
|
.layer(Extension(pool.clone()))
|
||||||
.layer(Extension(templates.clone()))
|
.layer(Extension(templates.clone()))
|
||||||
|
Reference in New Issue
Block a user