2019-07-19 18:46:16 +00:00
|
|
|
use lazy_static::lazy_static;
|
2022-01-11 01:32:59 +00:00
|
|
|
// use rocket_prometheus::prometheus;
|
2019-07-19 18:46:16 +00:00
|
|
|
|
2019-09-02 20:49:02 +00:00
|
|
|
use crate::anonymize_utils;
|
2019-07-19 18:46:16 +00:00
|
|
|
|
2019-09-02 20:49:02 +00:00
|
|
|
use crate::database::types::Email;
|
2019-07-19 18:46:16 +00:00
|
|
|
|
2022-01-11 01:32:59 +00:00
|
|
|
// TODO this module is a stub at the moment for rocket 0.5 migration. reintroduce later on?
|
|
|
|
|
2019-07-19 18:46:16 +00:00
|
|
|
lazy_static! {
|
2019-07-20 15:00:02 +00:00
|
|
|
static ref KEY_UPLOAD: LabelCounter =
|
2019-07-20 17:44:18 +00:00
|
|
|
LabelCounter::new("hagrid_key_upload", "Uploaded keys", &["result"]);
|
2019-07-20 15:00:02 +00:00
|
|
|
|
|
|
|
static ref MAIL_SENT: LabelCounter =
|
2019-07-20 17:44:18 +00:00
|
|
|
LabelCounter::new("hagrid_mail_sent", "Sent verification mails", &["type", "domain"]);
|
2019-07-20 15:00:02 +00:00
|
|
|
|
|
|
|
static ref KEY_ADDRESS_PUBLISHED: LabelCounter =
|
2019-07-20 17:44:18 +00:00
|
|
|
LabelCounter::new("hagrid_key_address_published", "Verified email addresses", &["domain"]);
|
2019-07-20 15:00:02 +00:00
|
|
|
static ref KEY_ADDRESS_UNPUBLISHED: LabelCounter =
|
2019-07-20 17:44:18 +00:00
|
|
|
LabelCounter::new("hagrid_key_address_unpublished", "Unpublished email addresses", &["domain"]);
|
2019-07-19 18:46:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-11 01:32:59 +00:00
|
|
|
/*
|
2019-07-19 18:46:16 +00:00
|
|
|
pub fn register_counters(registry: &prometheus::Registry) {
|
2019-07-20 15:00:02 +00:00
|
|
|
KEY_UPLOAD.register(registry);
|
|
|
|
|
|
|
|
MAIL_SENT.register(registry);
|
|
|
|
|
2019-07-19 18:46:16 +00:00
|
|
|
KEY_ADDRESS_PUBLISHED.register(registry);
|
|
|
|
KEY_ADDRESS_UNPUBLISHED.register(registry);
|
|
|
|
}
|
2022-01-11 01:32:59 +00:00
|
|
|
*/
|
2019-07-19 18:46:16 +00:00
|
|
|
|
2019-07-20 15:00:02 +00:00
|
|
|
pub fn inc_key_upload(upload_result: &str) {
|
|
|
|
KEY_UPLOAD.inc(&[upload_result]);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn inc_mail_sent(mail_type: &str, email: &Email) {
|
|
|
|
let anonymized_adddress = anonymize_utils::anonymize_address_fallback(email);
|
|
|
|
MAIL_SENT.inc(&[mail_type, &anonymized_adddress]);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn inc_address_published(email: &Email) {
|
|
|
|
let anonymized_adddress = anonymize_utils::anonymize_address_fallback(email);
|
|
|
|
KEY_ADDRESS_PUBLISHED.inc(&[&anonymized_adddress]);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn inc_address_unpublished(email: &Email) {
|
|
|
|
let anonymized_adddress = anonymize_utils::anonymize_address_fallback(email);
|
|
|
|
KEY_ADDRESS_UNPUBLISHED.inc(&[&anonymized_adddress]);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct LabelCounter {
|
2022-01-11 01:32:59 +00:00
|
|
|
// prometheus_counter: prometheus::IntCounterVec,
|
2019-07-19 18:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl LabelCounter {
|
|
|
|
fn new(name: &str, help: &str, labels: &[&str]) -> Self {
|
2022-01-11 01:32:59 +00:00
|
|
|
// let opts = prometheus::Opts::new(name, help);
|
|
|
|
// let prometheus_counter = prometheus::IntCounterVec::new(opts, labels).unwrap();
|
|
|
|
// Self { prometheus_counter }
|
|
|
|
Self { }
|
2019-07-19 18:46:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-11 01:32:59 +00:00
|
|
|
/*
|
2019-07-19 18:46:16 +00:00
|
|
|
fn register(&self, registry: &prometheus::Registry) {
|
|
|
|
registry.register(Box::new(self.prometheus_counter.clone())).unwrap();
|
|
|
|
}
|
2022-01-11 01:32:59 +00:00
|
|
|
*/
|
2019-07-19 18:46:16 +00:00
|
|
|
|
|
|
|
fn inc(&self, values: &[&str]) {
|
2022-01-11 01:32:59 +00:00
|
|
|
// self.prometheus_counter.with_label_values(values).inc();
|
2019-07-19 18:46:16 +00:00
|
|
|
}
|
|
|
|
}
|