Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

bug: report error from image library #349

Merged
merged 9 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion integration-tests/volumes/client/scenarios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ scenarios:
headers:
# Contile maps the User-Agent Header value to os-family and form-factor parameters
# The following value will result in os-family: ios and form-factor: tablet
# NOTE: Firefox for iPad returns the default desktop UA string.
- name: User-Agent
value: 'Mozilla/5.0 (iPad; CPU iPhone OS 11_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/35.0 Mobile/15E148 Safari/605.1.15'
value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15'
response:
status_code: 204 # No Content
content: ''
Expand Down
2 changes: 1 addition & 1 deletion src/adm/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl AdmFilter {
// TODO: if not error.is_reportable, just add to metrics.
let mut merged_tags = error.tags.clone();
merged_tags.extend(tags.clone());
l_sentry::report(&merged_tags, sentry::event_from_error(error));
l_sentry::report(sentry::event_from_error(error), &merged_tags);
}

/// check to see if the bucket has been modified since the last time we updated.
Expand Down
27 changes: 19 additions & 8 deletions src/adm/tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
server::ServerState,
settings::Settings,
tags::Tags,
web::middleware::sentry::report,
web::DeviceInfo,
};

Expand Down Expand Up @@ -257,23 +258,33 @@ pub async fn get_tiles(
.take(settings.adm_max_tiles as usize)
.collect();

if filtered.is_empty() {
warn!("adm::get_tiles no valid tiles {}", adm_url);
metrics.incr_with_tags("filter.adm.all_filtered", Some(tags));
}
let mut tiles: Vec<Tile> = Vec::new();
for mut tile in filtered {
if let Some(storage) = image_store {
// we should have already proven the image_url in `filter_and_process`
// we need to validate the image, store the image for eventual CDN retrieval,
// and get the metrics of the image.
let result = storage.store(&tile.image_url.parse().unwrap()).await?;
tile.image_url = result.url.to_string();
// Since height should equal width, using either value here works.
tile.image_size = Some(result.image_metrics.width);
match storage.store(&tile.image_url.parse().unwrap()).await {
Ok(result) => {
tile.image_url = result.url.to_string();
// Since height should equal width, using either value here works.
tile.image_size = Some(result.image_metrics.width);
}
Err(e) => {
// quietly report the error, and drop the tile.
report(sentry::event_from_error(&e), tags);
continue;
}
}
}
tiles.push(tile);
}

if tiles.is_empty() {
warn!("adm::get_tiles no valid tiles {}", adm_url);
metrics.incr_with_tags("filter.adm.all_filtered", Some(tags));
}

Ok(TileResponse { tiles })
}

Expand Down
11 changes: 8 additions & 3 deletions src/server/img_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,13 @@ impl StoreImage {
pub fn meta(&self, image: &Bytes, fmt: ImageFormat) -> HandlerResult<ImageMetrics> {
let mut reader = ImageReader::new(Cursor::new(image));
reader.set_format(fmt);
let img = reader
.decode()
.map_err(|_| HandlerErrorKind::BadImage("Image unreadable"))?;
let img = reader.decode().map_err(|e| {
let mut tags = Tags::default();
tags.add_extra("error", &e.to_string());
Copy link
Member

@pjenvey pjenvey Feb 3, 2022

Choose a reason for hiding this comment

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

I think both url and format are really worth adding as extras here too -- the easiest way to do that is to probably shuffle this method around a bit to have the same signature as validate.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sigh.
the change was included in the merge e767a61

let mut err: HandlerError = HandlerErrorKind::BadImage("Image unreadable").into();
err.tags = tags;
err
})?;
let rgb_img = img.to_rgb16();
Ok(ImageMetrics {
height: rgb_img.height(),
Expand Down Expand Up @@ -271,6 +275,7 @@ impl StoreImage {
_ => {
let mut tags = Tags::default();
tags.add_extra("url", &uri.to_string());
tags.add_extra("format", content_type);
let mut err: HandlerError =
HandlerErrorKind::BadImage("Invalid image format").into();
err.tags = tags;
Expand Down
2 changes: 1 addition & 1 deletion src/web/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub async fn get_tiles(
let mut tags = Tags::from_head(request.head(), settings);
tags.add_extra("err", es);
tags.add_tag("level", "warning");
l_sentry::report(&tags, sentry::event_from_error(&e));
l_sentry::report(sentry::event_from_error(&e), &tags);
warn!("ADM Server error: {:?}", e);
Ok(HttpResponse::NoContent().finish())
}
Expand Down
8 changes: 4 additions & 4 deletions src/web/middleware/sentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub struct SentryWrapperMiddleware<S> {
/// Report an error with [crate::tags::Tags] and [Event] directly to sentry
///
/// And [Event] can be derived using `event_from_error(HandlerError)`
pub fn report(tags: &Tags, mut event: Event<'static>) {
pub fn report(mut event: Event<'static>, tags: &Tags) {
let tags = tags.clone();
event.tags = tags.clone().tag_tree();
event.extra = tags.extra_tree();
Expand Down Expand Up @@ -118,7 +118,7 @@ where
{
for event in events {
trace!("Sentry: found an error stored in request: {:?}", &event);
report(&tags, event);
report(event, &tags);
}
}
if let Some(events) = sresp
Expand All @@ -128,15 +128,15 @@ where
{
for event in events {
trace!("Sentry: Found an error stored in response: {:?}", &event);
report(&tags, event);
report(event, &tags);
}
}
}
Some(e) => {
if let Some(herr) = e.as_error::<HandlerError>() {
if herr.kind().is_sentry_event() {
tags.extend(herr.tags.clone());
report(&tags, event_from_error(herr));
report(event_from_error(herr), &tags);
} else if let Some(label) = herr.kind().metric_label() {
metrics.incr_with_tags(label).send()
}
Expand Down