mirror of
https://github.com/atuinsh/atuin.git
synced 2024-11-25 17:54:55 +01:00
feat: add some metrics related to Atuin as an app (#1399)
This commit is contained in:
parent
15d214e237
commit
7575a83fa7
@ -6,6 +6,7 @@ use axum::{
|
|||||||
Json,
|
Json,
|
||||||
};
|
};
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
|
use metrics::counter;
|
||||||
use time::{Month, UtcOffset};
|
use time::{Month, UtcOffset};
|
||||||
use tracing::{debug, error, instrument};
|
use tracing::{debug, error, instrument};
|
||||||
|
|
||||||
@ -65,6 +66,8 @@ pub async fn list<DB: Database>(
|
|||||||
|
|
||||||
if req.sync_ts.unix_timestamp_nanos() < 0 || req.history_ts.unix_timestamp_nanos() < 0 {
|
if req.sync_ts.unix_timestamp_nanos() < 0 || req.history_ts.unix_timestamp_nanos() < 0 {
|
||||||
error!("client asked for history from < epoch 0");
|
error!("client asked for history from < epoch 0");
|
||||||
|
counter!("atuin_history_epoch_before_zero", 1);
|
||||||
|
|
||||||
return Err(
|
return Err(
|
||||||
ErrorResponse::reply("asked for history from before epoch 0")
|
ErrorResponse::reply("asked for history from before epoch 0")
|
||||||
.with_status(StatusCode::BAD_REQUEST),
|
.with_status(StatusCode::BAD_REQUEST),
|
||||||
@ -93,6 +96,8 @@ pub async fn list<DB: Database>(
|
|||||||
user.id
|
user.id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
counter!("atuin_history_returned", history.len() as u64);
|
||||||
|
|
||||||
Ok(Json(SyncHistoryResponse { history }))
|
Ok(Json(SyncHistoryResponse { history }))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,6 +132,7 @@ pub async fn add<DB: Database>(
|
|||||||
let State(AppState { database, settings }) = state;
|
let State(AppState { database, settings }) = state;
|
||||||
|
|
||||||
debug!("request to add {} history items", req.len());
|
debug!("request to add {} history items", req.len());
|
||||||
|
counter!("atuin_history_uploaded", req.len() as u64);
|
||||||
|
|
||||||
let mut history: Vec<NewHistory> = req
|
let mut history: Vec<NewHistory> = req
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -146,6 +152,8 @@ pub async fn add<DB: Database>(
|
|||||||
// Don't return an error here. We want to insert as much of the
|
// Don't return an error here. We want to insert as much of the
|
||||||
// history list as we can, so log the error and continue going.
|
// history list as we can, so log the error and continue going.
|
||||||
if !keep {
|
if !keep {
|
||||||
|
counter!("atuin_history_too_long", 1);
|
||||||
|
|
||||||
tracing::warn!(
|
tracing::warn!(
|
||||||
"history too long, got length {}, max {}",
|
"history too long, got length {}, max {}",
|
||||||
h.data.len(),
|
h.data.len(),
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use axum::{extract::Query, extract::State, Json};
|
use axum::{extract::Query, extract::State, Json};
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
|
use metrics::counter;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use tracing::{error, instrument};
|
use tracing::{error, instrument};
|
||||||
|
|
||||||
@ -23,11 +24,15 @@ pub async fn post<DB: Database>(
|
|||||||
"request to add records"
|
"request to add records"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
counter!("atuin_record_uploaded", records.len() as u64);
|
||||||
|
|
||||||
let too_big = records
|
let too_big = records
|
||||||
.iter()
|
.iter()
|
||||||
.any(|r| r.data.data.len() >= settings.max_record_size || settings.max_record_size == 0);
|
.any(|r| r.data.data.len() >= settings.max_record_size || settings.max_record_size == 0);
|
||||||
|
|
||||||
if too_big {
|
if too_big {
|
||||||
|
counter!("atuin_record_too_large", 1);
|
||||||
|
|
||||||
return Err(
|
return Err(
|
||||||
ErrorResponse::reply("could not add records; record too large")
|
ErrorResponse::reply("could not add records; record too large")
|
||||||
.with_status(StatusCode::BAD_REQUEST),
|
.with_status(StatusCode::BAD_REQUEST),
|
||||||
|
Loading…
Reference in New Issue
Block a user