Skip to content

Commit

Permalink
fix: fix unset connected_at values
Browse files Browse the repository at this point in the history
and emit metrics for to be sent notifications

Closes #26, #24
  • Loading branch information
pjenvey committed Jun 29, 2018
1 parent c258545 commit 8f81af3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::cell::RefCell;
use std::mem;
use std::rc::Rc;

use cadence::prelude::*;
use cadence::{prelude::*, StatsdClient};
use futures::AsyncSink;
use futures::future::Either;
use futures::sync::mpsc;
Expand Down Expand Up @@ -834,6 +834,7 @@ where
webpush.unacked_direct_notifs.push(notif.clone());
}
debug!("Got a notification to send, sending!");
emit_metrics_for_send(&data.srv.metrics, &notif, "Direct");
transition!(SendThenWait {
remaining_data: vec![ServerMessage::Notification(notif)],
poll_complete: false,
Expand Down Expand Up @@ -935,6 +936,7 @@ where
transition!(SendThenWait {
remaining_data: messages
.into_iter()
.inspect(|msg| emit_metrics_for_send(&data.srv.metrics, &msg, "Stored"))
.map(ServerMessage::Notification)
.collect(),
poll_complete: false,
Expand Down Expand Up @@ -1052,3 +1054,16 @@ where
})
}
}

fn emit_metrics_for_send(metrics: &StatsdClient, notif: &Notification, source: &'static str) {
if notif.topic.is_some() {
metrics.incr("ua.notification.topic").ok();
}
metrics
.count_with_tags(
"ua.message_data",
notif.data.as_ref().map_or(0, |data| data.len() as i64),
)
.with_tag("source", source)
.send();
}
7 changes: 5 additions & 2 deletions src/db/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,11 @@ pub fn lookup_user(
let router_url = router_url.to_string();
let metrics = metrics.clone();
let response = response.and_then(move |data| -> MyFuture<_> {
let mut hello_response: HelloResponse = Default::default();
hello_response.message_month = cur_month.clone();
let mut hello_response = HelloResponse {
message_month: cur_month.clone(),
connected_at,
..Default::default()
};
let user = handle_user_result(
&cur_month,
&messages_tables,
Expand Down
1 change: 1 addition & 0 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ impl DynamoStorage {
Box::new(future::ok((
HelloResponse {
message_month: current_message_month.to_string(),
connected_at: *connected_at,
..Default::default()
},
None,
Expand Down

0 comments on commit 8f81af3

Please sign in to comment.