fix: Don't fail entire preview requests when auxiliary requests fail #2448
No reviewers
Labels
No labels
Abandoned
Blocked
Bug
Changelog
Added
Changelog
Missing
Changelog
None
Cherry-picking
Compliance
Database
Dependencies
Dependencies/Renovate
Difficulty
Easy
Difficulty
Hard
Difficulty
Medium
Documentation
Enhancement
Good first issue
Help wanted
Inherited
Matrix/Administration
Matrix/Appservices
Matrix/Auth
Matrix/Client
Matrix/Core
Matrix/E2EE
Matrix/Federation
Matrix/Hydra
Matrix/MSC
Matrix/Media
Matrix/T&S
Merge
Merge/Manual
Merge/Squash
Meta
Meta/CI
Meta/Packaging
Priority
Blocking
Priority
High
Priority
Low
Security
Status
Confirmed
Status
Duplicate
Status
Invalid
Status
Needs Investigation
Support
bob the builder
No assignees
7 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
continuwuation/continuwuity!2448
Loading…
Reference in a new issue
No description provided.
Delete branch "nex/fix/nonatomic-url-previews"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
#2437 was really annoying me so I fixed it, and also added additional opengraph tags to improve spec compliance (although this isn't a replacement for arbitrary OG tags, I'll do that in another PR since I unfortunately saw how awful our url preview storage is)
Fixes #2437
Pull request checklist:
mainbranch, and the branch is named something other thanmain.myself, if applicable. This includes ensuring code compiles.
i am planning on completely revamping this in the media rewrite (since the two codebases are very linked together), feel free to change it early but i might replace it a second time when i finish the rewrite
That's fine, my plan was to write a migration that
I wouldn't be too distraught to see it improved further by a rewrite later
@ -349,0 +351,4 @@..Default::default() /* TODO(nex): This weird manual field de/serialisation just* needs replacing with JSON storage to avoid this mess.* This is consequently intentionally dropping information* added later (like image alt text). I'll do it later. */This will be rewritten as part of the media rewrite, feel free to change this todo (and the one on L251) over to me
I'll cc you into the TODO but I'll leave it assigned to me also so that I don't forget to do my aforementioned interim migration
sounds great
@nex wrote in #2448 (comment):
whatever lets me delete all that data has my APPROVED
@nex wrote in #2448 (comment):
My current "plan" (if you can call if that) is to just use serde's standard serializer on the structs, and probably actually using the value instead of storing everything in the key (i believe previews used that same (stupid) method of serialization and storage).
(i might be misremembering, i have it written down somewhere but my memory is ass)
missing changelog :^)
@ -301,0 +336,4 @@preview_data.image_height = image_data.image_height;preview_data.image_type = obj.properties.get("image:type")no need for image: you can just use type https://docs.rs/webpage/2.1.0/src/webpage/opengraph.rs.html#55-88
@ -301,0 +344,4 @@.flatten();preview_data.image_alt = obj.properties.get("image:alt")same here
@ -307,0 +360,4 @@preview_data.video_size = video_data.video_size;preview_data.video_type = obj.properties.get("video:type")same here
@ -307,0 +368,4 @@.flatten();preview_data.video_alt = obj.properties.get("video:alt")same here
@ -307,0 +355,4 @@|e| info!(error=?e, asset_url=%obj.url, "Could not download URL preview video"),) {preview_data.video = video_data.video;preview_data.video_width = video_data.video_width;not set by download_video so .get("width")
@ -219,6 +219,7 @@ pub(crate) async fn get_media_preview_route()));}info!("Fetching a URL preview for {url} on behalf of {sender_user}");debug! ?
I don't think so, I'd like to know when my server is doing things on behalf of users, like making external requests (especially useful in untrusted environments like continuwuity.rocks). Continuwuity has a bad habit of under-logging so I'd like to avoid debug! et al unless the log is actually useful to debugging, not just normal operation
Requests should be logged at the router level, and this log should be a structured log anyway.
My server receives an average of 10 requests per second with spikes into the thousands in some situations, and that's normal for a federated server. Expecting people to use the router logs for this stuff is infeasible
@ -307,0 +356,4 @@) {preview_data.video = video_data.video;preview_data.video_width = video_data.video_width;preview_data.video_height = video_data.video_height;not set by download_video so .get("height")
@ -319,0 +390,4 @@preview_data.determiner = props.get("determiner").cloned();preview_data.locale = props.get("locale").cloned();preview_data.site_name = props.get("site_name").cloned();preview_data.site_type = props.get("type").cloned();i think it should be og_type here as it's an extended type
@ -319,0 +391,4 @@preview_data.locale = props.get("locale").cloned();preview_data.site_name = props.get("site_name").cloned();preview_data.site_type = props.get("type").cloned();preview_data.url = props.get("url").cloned().or_else(|| Some(url.to_owned()));this will always be None, webpage puts og:type into og_type and not into properties
@ -84,3 +84,3 @@.timeout(Duration::from_secs(config.url_preview_timeout)).redirect(redirect::Policy::limited(3)).user_agent(url_preview_user_agent).user_agent(url_preview_user_agent.replace("<version>", conduwuit::version_ua()))ew.
I did this because the docstring for that option starts with
continuwuity/<version>and I naively assumed that<version>would be substituted with the real version if I specified a custom UA, and then was taken by surprised whencontinuwuity/<version>literally appeared in my logs. Anything more than a replace will also then require a documentation update, which is wayy out of scope for this fix with some cheap wins@ -24,1 +25,4 @@pub struct UrlPreviewData {// From https://ogp.me//// The title of your object as it should appear within the graph/// "The Rock".why is dwayne johnson in my doc comment
I copied the descriptions from the ogp website until I got bored
works great!
I'd replace the
info!with a structured log like jade suggested, other than that it lgtme785d78b8879c5af78cdmost recent push fails rust format, but otherwise is ready to go and works extremely well.
TODO
@ -10,2 +10,3 @@use conduwuit::{Err, Result, debug, err, utils::response::LimitReadExt};use conduwuit::{Err, Result, debug, err, utils::response::LimitReadExt, info};use ipaddress::IPAddress;use lettre::message::header::ContentType;we already depend on mime, use it directly
Doesn't appear to be available to the crate. What's wrong with using lettre's ContentType?
lettre is an email library, not a generic web library, and it's just re-exporting mime which I thought we already depended on
we might already depend on it elsewhere but it's not in conduwuit_service's cargo.toml. If it's just re-exporting mime though what's the problem?
Because that's a reexport for an optional feature of an unrelated dependency that might get removed or changed, that's just bad code smell
you smell >:( /lh
I am too tired to be giving proper code review, but:
url_previewfeature disabled (or do we just want to remove that compile option?)@ -219,10 +219,15 @@ pub(crate) async fn get_media_preview_route()));}info!("Fetching a URL preview for {url} on behalf of {sender_user}");(1) please use structured logging, (2) I think this is unlikely to be relevant to typical server admins, and is just going to be log spam
@ -115,3 +154,1 @@| audio if audio.starts_with("audio/") =>self.download_audio(url.as_str(), None).await?,| _ => return Err!(Request(Unknown("Unsupported Content-Type"))),| img if img.starts_with("image/") => self.download_image(url.as_str()).await?,can we also
url.join(&obj.url)to deal with relative paths?Relative paths aren't possible here as
urlis absolute to begin withOh I'm dumb, meant to make this comment on the bits that take the URL from the og: tags
Ah that makes more sense
@ -300,3 +345,1 @@preview_data = self.download_video(&obj.url, Some(preview_data)).await?;preview_data.video_width = obj.properties.get("width").and_then(|v| v.parse().ok());preview_data.video_height = obj.properties.get("height").and_then(|v| v.parse().ok());info!(asset_url=%obj.url, "Downloading preview video");this is gonna log even when downloading audio/videos is disabled (same for in the audio function)
I've made the logs debug_x so I think it's fine now
@ -315,0 +381,4 @@preview_data.video_type = None;preview_data.video_alt = None;preview_data.video_height = None;preview_data.video_width = None;video_size (and image_size above?)
79c5af78cdea3ea4a3d81f3eb0c3cfto355feb950099737724f8634002060bblocked until it works with url_preview feature disabled in continuwuity
I made a bunch of changes to try fix some of the issues. Horrors fixes later