metrics: Implement iocaine_maze_depth
Some checks are pending
build / binary (push) Waiting to run
build / binary-static (x86_64-linux) (push) Waiting to run
build / container (push) Blocked by required conditions
build / clippy (push) Waiting to run
lint / linting (push) Waiting to run

Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
This commit is contained in:
Gergely Nagy 2025-03-04 14:05:35 +01:00
parent fd1530707e
commit 2bfc4c81a8
No known key found for this signature in database
3 changed files with 18 additions and 1 deletions

View file

@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
### Added
- The `iocaine_garbage_served` metric will have the same labels applied to it as `iocaine_requests_total`.
- Implemented a new metric, `iocaine_maze_depth`, a counter to track how deep the maze has been explored so far.
- When metrics are enabled, process metrics such as CPU seconds used, memory usage, etc, are also emitted.
## [1.0.0] - 2025-03-01

View file

@ -123,7 +123,7 @@ async fn poison(
) -> std::result::Result<Html<String>, AppError> {
let default_host = axum::http::HeaderValue::from_static("<unknown>");
let host = headers.get("host").unwrap_or(&default_host).to_str()?;
let path = path.unwrap_or(Path("/".to_string()));
let path = path.unwrap_or(Path("".to_string()));
let garbage = AssembledStatisticalSequences::generate(&state.iocaine, host, &path)?;
@ -135,6 +135,13 @@ async fn poison(
.garbage_served_counter
.with_label_values(&labels)
.inc_by(garbage.len() as u64);
let depth = path.chars().filter(|c| *c == '/').count() as u64;
let maze_depth_counter = counters.maze_depth.with_label_values(&labels);
let maze_depth = maze_depth_counter.get();
if depth > maze_depth {
maze_depth_counter.inc_by(depth - maze_depth);
}
}
Ok(Html(garbage))

View file

@ -22,6 +22,7 @@ pub struct TenXProgrammer {
pub struct TenXProgrammerCounters {
pub request_counter: IntCounterVec,
pub garbage_served_counter: IntCounterVec,
pub maze_depth: IntCounterVec,
}
impl TenXProgrammer {
@ -109,11 +110,19 @@ impl TenXProgrammer {
.register(Box::new(garbage_served_counter.clone()))
.unwrap();
let maze_depth_opts = Opts::new(
"iocaine_maze_depth",
"Maximum explored depth of the maze (in path parts)",
);
let maze_depth = IntCounterVec::new(maze_depth_opts, &labels).unwrap();
registry.register(Box::new(maze_depth.clone())).unwrap();
Some(Self {
registry,
counters: TenXProgrammerCounters {
request_counter,
garbage_served_counter,
maze_depth,
},
})
}