From 9e4c4551a786830bf34d74c4ef111a8ed292fa9f Mon Sep 17 00:00:00 2001 From: Vika Date: Tue, 15 Feb 2022 02:44:33 +0300 Subject: 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... --- src/metrics.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/metrics.rs') 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 tide::Middleware for InstrumentationMiddleware @@ -55,9 +56,9 @@ where Ok(res) } -} +}*/ -pub async fn gather(_: Request) -> Result +/*pub async fn gather(_: Request) -> 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 { + let mut buffer: Vec = vec![]; + let encoder = TextEncoder::new(); + let metric_families = prometheus::gather(); + encoder.encode(&metric_families, &mut buffer).unwrap(); + + buffer } -- cgit 1.4.1