diff options
author | Vika <vika@fireburn.ru> | 2022-02-15 02:44:33 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2022-02-15 02:46:24 +0300 |
commit | 9e4c4551a786830bf34d74c4ef111a8ed292fa9f (patch) | |
tree | 7796d7e529c89f22bccfbba4566b6bf5efca8071 /src/metrics.rs | |
parent | d1327ed6b28a49770aa5d9b06245aa063b406f78 (diff) | |
download | kittybox-9e4c4551a786830bf34d74c4ef111a8ed292fa9f.tar.zst |
WIP: convert to Tokio and Warp
Warp allows requests to be applied as "filters", allowing to flexibly split up logic and have it work in a functional style, similar to pipes. Tokio is just an alternative runtime. I thought that maybe switching runtimes and refactoring the code might allow me to fish out that pesky bug with the whole application hanging after a certain amount of requests...
Diffstat (limited to 'src/metrics.rs')
-rw-r--r-- | src/metrics.rs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/metrics.rs b/src/metrics.rs index 9f512dd..7bfa2d2 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -1,3 +1,4 @@ +#![allow(unused_imports, dead_code)] use async_trait::async_trait; use lazy_static::lazy_static; use prometheus::{ @@ -5,7 +6,7 @@ use prometheus::{ TextEncoder, }; use std::time::{Duration, Instant}; -use tide::{Next, Request, Response, Result}; +//use tide::{Next, Request, Response, Result}; // Copied from https://docs.rs/prometheus/0.12.0/src/prometheus/histogram.rs.html#885-889 #[inline] @@ -29,7 +30,7 @@ lazy_static! { .unwrap(); } -pub struct InstrumentationMiddleware {} +/*pub struct InstrumentationMiddleware {} #[async_trait] impl<S> tide::Middleware<S> for InstrumentationMiddleware @@ -55,9 +56,9 @@ where Ok(res) } -} +}*/ -pub async fn gather<S>(_: Request<S>) -> Result +/*pub async fn gather<S>(_: Request<S>) -> Result where S: Send + Sync + Clone, { @@ -67,4 +68,18 @@ where encoder.encode(&metric_families, &mut buffer).unwrap(); Ok(Response::builder(200).body(buffer).build()) +}*/ + +// TODO metrics middleware +// warp doesn't allow running a filter manually +// so you need to escape into the world of hyper +// to collect metrics on requests + +pub fn gather() -> Vec<u8> { + let mut buffer: Vec<u8> = vec![]; + let encoder = TextEncoder::new(); + let metric_families = prometheus::gather(); + encoder.encode(&metric_families, &mut buffer).unwrap(); + + buffer } |