mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
imbris though the Cow would get Cloned anyway, so we go directly for String for now. OnceCell might be a thing in the future, but not now.
Also logging errors in case metrics cannot be build
This commit is contained in:
parent
360cc4a4b7
commit
0baab58928
@ -262,7 +262,6 @@ fn main() -> io::Result<()> {
|
||||
tick_no += 1;
|
||||
// Terminate the server if instructed to do so by the shutdown coordinator
|
||||
if shutdown_coordinator.check(&mut server, &settings) {
|
||||
metrics_shutdown.notify_one();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -337,6 +336,7 @@ fn main() -> io::Result<()> {
|
||||
#[cfg(feature = "tracy")]
|
||||
common_base::tracy_client::frame_mark();
|
||||
}
|
||||
metrics_shutdown.notify_one();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -9,12 +9,12 @@ use chrono::DateTime;
|
||||
use hyper::{Request, StatusCode};
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use server::chat::ChatCache;
|
||||
use std::{borrow::Cow, str::FromStr};
|
||||
use std::str::FromStr;
|
||||
|
||||
/// Keep Size small, so we dont have to Clone much for each request.
|
||||
#[derive(Clone)]
|
||||
struct ChatToken {
|
||||
secret_token: Option<Cow<'static, str>>,
|
||||
secret_token: Option<String>,
|
||||
}
|
||||
|
||||
async fn validate_secret<B>(
|
||||
@ -39,9 +39,7 @@ async fn validate_secret<B>(
|
||||
}
|
||||
|
||||
pub fn router(cache: ChatCache, secret_token: Option<String>) -> Router {
|
||||
let token = ChatToken {
|
||||
secret_token: secret_token.map(Cow::Owned),
|
||||
};
|
||||
let token = ChatToken { secret_token };
|
||||
Router::new()
|
||||
.route("/history", get(history))
|
||||
.layer(axum::middleware::from_fn_with_state(token, validate_secret))
|
||||
|
@ -51,10 +51,15 @@ async fn metrics(State(registry): State<Registry>) -> Result<impl IntoResponse,
|
||||
.encode(&mf, &mut buffer)
|
||||
.expect("write to vec cannot fail");
|
||||
|
||||
let resp = http::Response::builder()
|
||||
match http::Response::builder()
|
||||
.status(StatusCode::OK)
|
||||
.header(header::CONTENT_TYPE, "text/plain; charset=utf-8")
|
||||
.body(Body::from(buffer))
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
Ok(resp)
|
||||
{
|
||||
Err(e) => {
|
||||
tracing::warn!(?e, "could not export metrics to HTTP format");
|
||||
Err(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
},
|
||||
Ok(r) => Ok(r),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user