Skip to content
Snippets Groups Projects
Commit 7f97b987 authored by Stephen D's avatar Stephen D
Browse files

don't send 404 paths to prometheus since that would allow unbounded label growth

parent 54ee546f
No related branches found
No related tags found
No related merge requests found
......@@ -5,8 +5,8 @@ use fnv::FnvHashMap;
use warp::hyper::StatusCode;
use crate::{
config::Config, favicon::Favicon, image::MyImage, load::load_from_path, misc::Misc,
path::UrlPath, post::Post, resp::Response, style::Style,
config::Config, favicon::Favicon, image::MyImage, load::load_from_path, metrics::HTTP_COUNTER,
misc::Misc, path::UrlPath, post::Post, resp::Response, style::Style,
};
pub struct Blog {
......@@ -118,10 +118,16 @@ pub struct RenderedBlog {
impl RenderedBlog {
pub fn get(&self, path: &UrlPath) -> (StatusCode, Response) {
self.pages
.get(path)
.map(|x| (StatusCode::OK, x.clone()))
.unwrap_or((StatusCode::NOT_FOUND, self.not_found.clone()))
match self.pages.get(path) {
Some(x) => {
HTTP_COUNTER.with_label_values(&[&path.to_string()]).inc();
(StatusCode::OK, x.clone())
}
None => {
HTTP_COUNTER.with_label_values(&["unknown"]).inc();
(StatusCode::NOT_FOUND, self.not_found.clone())
}
}
}
}
......
use blog::{Blog, RenderedBlog};
use config::Config;
use metrics::{
BUILD_BLOG_FROM_ASSETS, HTTP_COUNTER, INVALID_EXPIRES_HEADER_VALUE, REQUEST_LATENCY,
RESPONSE_COUNTER,
BUILD_BLOG_FROM_ASSETS, INVALID_EXPIRES_HEADER_VALUE, REQUEST_LATENCY, RESPONSE_COUNTER,
};
use path::UrlPath;
use std::sync::Arc;
......@@ -39,7 +38,6 @@ async fn handle_request(
let timer = REQUEST_LATENCY.start_timer();
let path = UrlPath::new(req.as_str());
HTTP_COUNTER.with_label_values(&[&path.to_string()]).inc();
let blog = blog.read().await;
let (status, content) = blog.get(&path);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment