Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

chore(queues): use mozlog and failure in queues process #161

Merged
merged 9 commits into from
Aug 9, 2018

Conversation

brizental
Copy link
Contributor

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 and errno, instead of a string.

For logging, I implemented an AppErrorFields so that we get better structured logs for our AppErrors. I used slog_scope to make it easier to have a global logger for the queues process, let me know what you think about that... In the README.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

@brizental brizental force-pushed the brizental/queue-logs-and-errors branch 2 times, most recently from 556e7e1 to 880455d Compare August 8, 2018 07:10
fields.insert(String::from("errno"), Value::String(format!("{}", errno)));
fields.insert(
String::from("errno"),
Value::Number(errno.to_owned().into()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QueueError(String),
/// An error for when we get an invalid notification type in the queues
/// process.
#[fail(display = "Invalid notification type.")]
Copy link
Contributor

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.

@@ -59,6 +60,46 @@ impl KV for RequestMozlogFields {
}
}

#[derive(Clone)]
struct AppErrorFields {
code: String,
Copy link
Contributor

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?

Copy link
Contributor

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>>,
Copy link
Contributor

@philbooth philbooth Aug 8, 2018

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?

Copy link
Contributor

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! 😄)

Copy link
Contributor Author

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 ?

Copy link
Contributor

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>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ref: #162

.map_err(|_| Status::InternalServerError)?;
slog_error!(log, "{}", "Request errored.");
}
_ => println!("Internal error: No managed MozlogLogger"),
Copy link
Contributor

@philbooth philbooth Aug 8, 2018

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!?

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, panicking sounds reasonable.

Copy link
Contributor

@philbooth philbooth left a 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.

@brizental brizental force-pushed the brizental/queue-logs-and-errors branch from cb02bb3 to 0da0f5b Compare August 8, 2018 17:14
@philbooth
Copy link
Contributor

I'm happy, we can merge this as soon as the conflict is resolved!

@brizental brizental force-pushed the brizental/queue-logs-and-errors branch from 0da0f5b to 79e204e Compare August 8, 2018 18:25
@brizental
Copy link
Contributor Author

Would you like me to squash these commits before merging also, @philbooth ?

@vladikoff vladikoff merged commit 501a591 into mozilla:master Aug 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants