-
Notifications
You must be signed in to change notification settings - Fork 6
chore(queues): use mozlog and failure in queues process #161
chore(queues): use mozlog and failure in queues process #161
Conversation
556e7e1
to
880455d
Compare
fields.insert(String::from("errno"), Value::String(format!("{}", errno))); | ||
fields.insert( | ||
String::from("errno"), | ||
Value::Number(errno.to_owned().into()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/app_errors/mod.rs
Outdated
QueueError(String), | ||
/// An error for when we get an invalid notification type in the queues | ||
/// process. | ||
#[fail(display = "Invalid notification type.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny nit: I'm not a fan of including a terminating period in our error strings fwiw. None of our other repos do it and it may be incorrect in the context of the receiving code, if it wants to display the message as part of a broader error string.
src/logging/mod.rs
Outdated
@@ -59,6 +60,46 @@ impl KV for RequestMozlogFields { | |||
} | |||
} | |||
|
|||
#[derive(Clone)] | |||
struct AppErrorFields { | |||
code: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't really matter tbh, it's only logging, but this one could/should be an i32
as well, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(actually u16
is probably more correct for both if I'm feeling pedantic, which I usually am)
headers: Option<Vec<Header>>, | ||
#[serde(rename = "commonHeaders")] | ||
common_headers: Option<Vec<Header>>, | ||
common_headers: Option<HashMap<String, HeaderValue>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the Header
struct circa line 160 be deleted too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, wait, no we shouldn't, it's still used for the headers
property on the line above.
(apologies for my poor reading comprehension! 😄)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about writing a deserializing function for the common_headers
so that we can keep it as a Option<Vec<Header>>
, it makes sense to me that both headers are the same type... But then I thought that maybe we might want the struct to mimic exactly the message we get. What do you think, @philbooth ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reckon keep it like you've got here, it's probably less confusing if we match the SES format as closely as possible.
@@ -137,10 +140,10 @@ pub struct Mail { | |||
sending_account_id: Option<String>, | |||
destination: Option<Vec<String>>, | |||
#[serde(rename = "headersTruncated")] | |||
headers_truncated: Option<String>, | |||
headers_truncated: Option<bool>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref: #162
src/app_errors/mod.rs
Outdated
.map_err(|_| Status::InternalServerError)?; | ||
slog_error!(log, "{}", "Request errored."); | ||
} | ||
_ => println!("Internal error: No managed MozlogLogger"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come this isn't a slog_error!
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duh, because haven't got a logger you div.
In that case, should we panic here? If logging isn't working we probably want to abort don't we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, panicking sounds reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! There's a couple of tiny nits in the inline comments, but I'm cool with you ignoring them if you disagree or whatever.
cb02bb3
to
0da0f5b
Compare
I'm happy, we can merge this as soon as the conflict is resolved! |
- Also fix formatting errors.
0da0f5b
to
79e204e
Compare
Would you like me to squash these commits before merging also, @philbooth ? |
Fixes #10
Fixes #99
Connects to #116
This was my first experience messing with the queues part of the service, I thought dealing with these issues first would make the experience smoother. I added the standard logging and error handling with the failure crate just like the rest of the lib.
Since our errors were very much centered around requests and rocket, we have some fields that don't really make sense for the queues process, like the http code, so let me know what you think about that and if the queues process should have a different error format. I also did another minor change to the errors: now the response JSON will return a number for
code
anderrno
, instead of a string.For logging, I implemented an
AppErrorFields
so that we get better structured logs for ourAppError
s. I usedslog_scope
to make it easier to have a global logger for the queues process, let me know what you think about that... In theREADME.md
for that crate, they have some warnings about it not being the best idea all the time, but anyways, I thought it was neat and worked well for our case.Finally, when I started working in the queues they were not really working due to parsing errors, you will see that I changed a little bit the SQS Notification struct, that was for parsing to work, also I created a notification-dev queue in the AWS Console, because it didn't exist yet, I think everything is working fine now.
r? @philbooth @vladikoff