mirror of https://github.com/telemt/telemt.git
Metrics + Fixes in tests
This commit is contained in:
parent
7304dacd60
commit
1fd78e012d
|
|
@ -2,7 +2,7 @@ use std::convert::Infallible;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use http_body_util::Full;
|
use http_body_util::{Full, BodyExt};
|
||||||
use hyper::body::Bytes;
|
use hyper::body::Bytes;
|
||||||
use hyper::server::conn::http1;
|
use hyper::server::conn::http1;
|
||||||
use hyper::service::service_fn;
|
use hyper::service::service_fn;
|
||||||
|
|
@ -54,7 +54,7 @@ pub async fn serve(port: u16, stats: Arc<Stats>, whitelist: Vec<IpNetwork>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle(req: Request<hyper::body::Incoming>, stats: &Stats) -> Result<Response<Full<Bytes>>, Infallible> {
|
fn handle<B>(req: Request<B>, stats: &Stats) -> Result<Response<Full<Bytes>>, Infallible> {
|
||||||
if req.uri().path() != "/metrics" {
|
if req.uri().path() != "/metrics" {
|
||||||
let resp = Response::builder()
|
let resp = Response::builder()
|
||||||
.status(StatusCode::NOT_FOUND)
|
.status(StatusCode::NOT_FOUND)
|
||||||
|
|
@ -194,21 +194,20 @@ mod tests {
|
||||||
stats.increment_connects_all();
|
stats.increment_connects_all();
|
||||||
stats.increment_connects_all();
|
stats.increment_connects_all();
|
||||||
|
|
||||||
let port = 19091u16;
|
let req = Request::builder()
|
||||||
let s = stats.clone();
|
.uri("/metrics")
|
||||||
tokio::spawn(async move {
|
.body(())
|
||||||
serve(port, s, vec![]).await;
|
.unwrap();
|
||||||
});
|
let resp = handle(req, &stats).unwrap();
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
|
let body = resp.into_body().collect().await.unwrap().to_bytes();
|
||||||
|
assert!(std::str::from_utf8(body.as_ref()).unwrap().contains("telemt_connections_total 3"));
|
||||||
|
|
||||||
let resp = reqwest::get(format!("http://127.0.0.1:{}/metrics", port))
|
let req404 = Request::builder()
|
||||||
.await.unwrap();
|
.uri("/other")
|
||||||
assert_eq!(resp.status(), 200);
|
.body(())
|
||||||
let body = resp.text().await.unwrap();
|
.unwrap();
|
||||||
assert!(body.contains("telemt_connections_total 3"));
|
let resp404 = handle(req404, &stats).unwrap();
|
||||||
|
assert_eq!(resp404.status(), StatusCode::NOT_FOUND);
|
||||||
let resp404 = reqwest::get(format!("http://127.0.0.1:{}/other", port))
|
|
||||||
.await.unwrap();
|
|
||||||
assert_eq!(resp404.status(), 404);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -899,7 +899,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_extract_alpn_single() {
|
fn test_extract_alpn_single() {
|
||||||
let mut alpn_data = Vec::new();
|
let mut alpn_data = Vec::new();
|
||||||
alpn_data.extend_from_slice(&2u16.to_be_bytes()); // list len
|
// list length = 3 (1 length byte + "h2")
|
||||||
|
alpn_data.extend_from_slice(&3u16.to_be_bytes());
|
||||||
alpn_data.push(2);
|
alpn_data.push(2);
|
||||||
alpn_data.extend_from_slice(b"h2");
|
alpn_data.extend_from_slice(b"h2");
|
||||||
let ch = build_client_hello_with_exts(vec![(0x0010, alpn_data)], "alpn.test");
|
let ch = build_client_hello_with_exts(vec![(0x0010, alpn_data)], "alpn.test");
|
||||||
|
|
@ -910,10 +911,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_extract_alpn_multiple() {
|
fn test_extract_alpn_multiple() {
|
||||||
let mut alpn_data = Vec::new();
|
let mut alpn_data = Vec::new();
|
||||||
alpn_data.extend_from_slice(&9u16.to_be_bytes()); // list len
|
// list length = 11 (sum of per-proto lengths including length bytes)
|
||||||
|
alpn_data.extend_from_slice(&11u16.to_be_bytes());
|
||||||
alpn_data.push(2);
|
alpn_data.push(2);
|
||||||
alpn_data.extend_from_slice(b"h2");
|
alpn_data.extend_from_slice(b"h2");
|
||||||
alpn_data.push(3);
|
alpn_data.push(4);
|
||||||
alpn_data.extend_from_slice(b"spdy");
|
alpn_data.extend_from_slice(b"spdy");
|
||||||
alpn_data.push(2);
|
alpn_data.push(2);
|
||||||
alpn_data.extend_from_slice(b"h3");
|
alpn_data.extend_from_slice(b"h3");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue