1
0
Fork 0
mirror of https://gitlab.com/hagrid-keyserver/hagrid.git synced 2023-02-13 20:55:02 -05:00

web: enable prometheus again

This commit is contained in:
Justus Winter 2022-01-17 14:24:00 +01:00 committed by Vincent Breitmoser
parent b428116189
commit a31d69d111
4 changed files with 34 additions and 19 deletions

24
Cargo.lock generated
View file

@ -949,6 +949,7 @@ dependencies = [
"rocket_codegen",
"rocket_dyn_templates",
"rocket_i18n",
"rocket_prometheus",
"sequoia-openpgp",
"serde",
"serde_derive",
@ -2067,6 +2068,20 @@ dependencies = [
"yansi",
]
[[package]]
name = "prometheus"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7f64969ffd5dd8f39bd57a68ac53c163a095ed9d0fb707146da1b27025a3504"
dependencies = [
"cfg-if 1.0.0",
"fnv",
"lazy_static",
"memchr",
"parking_lot",
"thiserror",
]
[[package]]
name = "quick-error"
version = "1.2.3"
@ -2505,6 +2520,15 @@ dependencies = [
"rocket",
]
[[package]]
name = "rocket_prometheus"
version = "0.9.0"
source = "git+https://github.com/sd2k/rocket_prometheus?branch=async#a913a451555ba1344e88c9e730c4164b20032c40"
dependencies = [
"prometheus",
"rocket",
]
[[package]]
name = "rustc-demangle"
version = "0.1.21"

View file

@ -33,7 +33,7 @@ num_cpus = "1.0"
ring = "0.13"
base64 = "0.10"
uuid = { version = "0.7", features = [ "v4" ] }
# rocket_prometheus = "0.2"
rocket_prometheus = { git = "https://github.com/sd2k/rocket_prometheus", branch = "async" }
lazy_static = "1.3.0"
gettext-macros = "0.6"
gettext-utils = "0.1"

View file

@ -1,12 +1,10 @@
use lazy_static::lazy_static;
// use rocket_prometheus::prometheus;
use rocket_prometheus::prometheus;
use crate::anonymize_utils;
use crate::database::types::Email;
// TODO this module is a stub at the moment for rocket 0.5 migration. reintroduce later on?
lazy_static! {
static ref KEY_UPLOAD: LabelCounter =
LabelCounter::new("hagrid_key_upload", "Uploaded keys", &["result"]);
@ -20,7 +18,6 @@ lazy_static! {
LabelCounter::new("hagrid_key_address_unpublished", "Unpublished email addresses", &["domain"]);
}
/*
pub fn register_counters(registry: &prometheus::Registry) {
KEY_UPLOAD.register(registry);
@ -29,7 +26,6 @@ pub fn register_counters(registry: &prometheus::Registry) {
KEY_ADDRESS_PUBLISHED.register(registry);
KEY_ADDRESS_UNPUBLISHED.register(registry);
}
*/
pub fn inc_key_upload(upload_result: &str) {
KEY_UPLOAD.inc(&[upload_result]);
@ -51,24 +47,21 @@ pub fn inc_address_unpublished(email: &Email) {
}
struct LabelCounter {
// prometheus_counter: prometheus::IntCounterVec,
prometheus_counter: prometheus::IntCounterVec,
}
impl LabelCounter {
fn new(name: &str, help: &str, labels: &[&str]) -> Self {
// let opts = prometheus::Opts::new(name, help);
// let prometheus_counter = prometheus::IntCounterVec::new(opts, labels).unwrap();
// Self { prometheus_counter }
Self { }
let opts = prometheus::Opts::new(name, help);
let prometheus_counter = prometheus::IntCounterVec::new(opts, labels).unwrap();
Self { prometheus_counter }
}
/*
fn register(&self, registry: &prometheus::Registry) {
registry.register(Box::new(self.prometheus_counter.clone())).unwrap();
}
*/
fn inc(&self, values: &[&str]) {
// self.prometheus_counter.with_label_values(values).inc();
self.prometheus_counter.with_label_values(values).inc();
}
}

View file

@ -8,6 +8,7 @@ use rocket::response::{Responder, Response};
use rocket::response::status::Custom;
use rocket_dyn_templates::{Engines, Template};
use rocket_i18n::I18n;
use rocket_prometheus::PrometheusMetrics;
use hyperx::header::{ContentDisposition, DispositionType, DispositionParam, Charset};
use gettext_macros::{compile_i18n, include_i18n};
@ -18,6 +19,7 @@ use std::path::PathBuf;
use crate::mail;
use crate::tokens;
use crate::counters;
use crate::i18n_helpers::describe_query_error;
use crate::template_helpers::TemplateOverrides;
use crate::i18n::I18NHelper;
@ -404,7 +406,7 @@ fn rocket_factory(mut rocket: rocket::Rocket<rocket::Build>) -> Result<rocket::R
let localized_template_list = configure_localized_template_list(figment)?;
println!("{:?}", localized_template_list);
// let prometheus = configure_prometheus(rocket.config());
let prometheus = configure_prometheus(figment);
rocket = rocket
.attach(Template::custom(|engines: &mut Engines| {
@ -423,18 +425,15 @@ fn rocket_factory(mut rocket: rocket::Rocket<rocket::Build>) -> Result<rocket::R
.manage(localized_template_list)
.mount("/", routes);
/*
if let Some(prometheus) = prometheus {
rocket = rocket
.attach(prometheus.clone())
.mount("/metrics", prometheus);
}
*/
Ok(rocket)
}
/*
fn configure_prometheus(config: &Figment) -> Option<PrometheusMetrics> {
if !config.extract_inner("enable_prometheus").unwrap_or(false) {
return None;
@ -443,7 +442,6 @@ fn configure_prometheus(config: &Figment) -> Option<PrometheusMetrics> {
counters::register_counters(&prometheus.registry());
return Some(prometheus);
}
*/
fn configure_db_service(config: &Figment) -> Result<KeyDatabase> {
let keys_internal_dir: PathBuf = config.extract_inner("keys_internal_dir")?;