Skip to content

Commit

Permalink
feat: log out failed conversion items and use histogram for timers
Browse files Browse the repository at this point in the history
  • Loading branch information
bbangert committed Jul 26, 2018
1 parent da65d4b commit 05a71d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,9 @@ where
let elapsed = (now - webpush.connected_at) / 1_000;
let parser = Parser::new();
let (ua_result, metrics_os, metrics_browser) = parse_user_agent(&parser, &user_agent);
// dogstatsd doesn't support timers: use histogram instead
srv.metrics
.time_with_tags("ua.connection.lifespan", elapsed)
.histogram_with_tags("ua.connection.lifespan", elapsed)
.with_tag("ua_os_family", metrics_os)
.with_tag("ua_browser_family", metrics_browser)
.with_tag("host", &webpush.stats.host)
Expand Down
19 changes: 12 additions & 7 deletions src/db/commands.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::HashSet;
use std::fmt::Display;
use std::fmt::{Debug, Display};
use std::rc::Rc;
use std::result::Result as StdResult;
use uuid::Uuid;
Expand Down Expand Up @@ -80,8 +80,9 @@ pub fn fetch_messages(
.into_iter()
.inspect(|i| debug!("Item: {:?}", i))
.filter_map(|item| {
let item2 = item.clone();
ok_or_inspect(serde_dynamodb::from_hashmap(item), |e| {
conversion_err(&metrics, e, "serde_dynamodb_from_hashmap")
conversion_err(&metrics, e, item2, "serde_dynamodb_from_hashmap")
})
})
.collect()
Expand All @@ -97,8 +98,9 @@ pub fn fetch_messages(
let messages = notifs
.into_iter()
.filter_map(|ddb_notif| {
let ddb_notif2 = ddb_notif.clone();
ok_or_inspect(ddb_notif.into_notif(), |e| {
conversion_err(&metrics, e, "into_notif")
conversion_err(&metrics, e, ddb_notif2, "into_notif")
})
})
.collect();
Expand Down Expand Up @@ -145,13 +147,15 @@ pub fn fetch_timestamp_messages(
items
.into_iter()
.filter_map(|item| {
let item2 = item.clone();
ok_or_inspect(serde_dynamodb::from_hashmap(item), |e| {
conversion_err(&metrics, e, "serde_dynamodb_from_hashmap")
conversion_err(&metrics, e, item2, "serde_dynamodb_from_hashmap")
})
})
.filter_map(|ddb_notif: DynamoDbNotification| {
let ddb_notif2 = ddb_notif.clone();
ok_or_inspect(ddb_notif.into_notif(), |e| {
conversion_err(&metrics, e, "into_notif")
conversion_err(&metrics, e, ddb_notif2, "into_notif")
})
})
.collect()
Expand Down Expand Up @@ -451,11 +455,12 @@ where
}

/// Log/metric errors during conversions to Notification
fn conversion_err<E>(metrics: &StatsdClient, err: E, name: &'static str)
fn conversion_err<E, F>(metrics: &StatsdClient, err: E, item: F, name: &'static str)
where
E: Display,
F: Debug,
{
error!("Failed {} conversion: {}", name, err);
error!("Failed {}, item: {:?}, conversion: {}", name, item, err);
metrics
.incr_with_tags("ua.notification_read.error")
.with_tag("conversion", name)
Expand Down

0 comments on commit 05a71d9

Please sign in to comment.