Skip to content

Commit

Permalink
Upgrade http and opentelemetry crates
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Sep 9, 2024
1 parent 572a42d commit 792a077
Show file tree
Hide file tree
Showing 9 changed files with 281 additions and 346 deletions.
562 changes: 246 additions & 316 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ embed-pictrs = ["pict-rs"]
console = [
"console-subscriber",
"opentelemetry",
"opentelemetry_sdk",
"opentelemetry-otlp",
"tracing-opentelemetry",
"reqwest-tracing/opentelemetry_0_16",
"reqwest-tracing/opentelemetry_0_24",
]
json-log = ["tracing-subscriber/json"]
default = []
Expand Down Expand Up @@ -99,7 +100,7 @@ lemmy_db_views = { version = "=0.19.5", path = "./crates/db_views" }
lemmy_db_views_actor = { version = "=0.19.5", path = "./crates/db_views_actor" }
lemmy_db_views_moderator = { version = "=0.19.5", path = "./crates/db_views_moderator" }
lemmy_federate = { version = "=0.19.5", path = "./crates/federate" }
activitypub_federation = { version = "0.5.8", default-features = false, features = [
activitypub_federation = { path = "../activitypub-federation-rust", default-features = false, features = [
"actix-web",
] }
diesel = "2.1.6"
Expand All @@ -121,14 +122,14 @@ tracing-error = "0.2.0"
tracing-log = "0.2.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
url = { version = "2.5.0", features = ["serde"] }
reqwest = { version = "0.11.27", default-features = false, features = [
reqwest = { version = "0.12.7", default-features = false, features = [
"json",
"blocking",
"gzip",
"rustls-tls",
] }
reqwest-middleware = "0.2.5"
reqwest-tracing = "0.4.8"
reqwest-middleware = "0.3.3"
reqwest-tracing = "0.5.3"
clokwerk = "0.4.0"
doku = { version = "0.21.1", features = ["url-2"] }
bcrypt = "0.15.1"
Expand All @@ -153,10 +154,11 @@ strum = "0.26.2"
strum_macros = "0.26.4"
itertools = "0.13.0"
futures = "0.3.30"
http = "0.2.12"
http = "1.0"
rosetta-i18n = "0.1.3"
opentelemetry = { version = "0.19.0", features = ["rt-tokio"] }
tracing-opentelemetry = { version = "0.19.0" }
opentelemetry = "0.24.0"
opentelemetry_sdk = { version = "0.24.0", features = ["rt-tokio"] }
tracing-opentelemetry = { version = "0.24.0" }
ts-rs = { version = "7.1.1", features = [
"serde-compat",
"chrono-impl",
Expand Down Expand Up @@ -200,6 +202,7 @@ clokwerk = { workspace = true }
serde_json = { workspace = true }
tracing-opentelemetry = { workspace = true, optional = true }
opentelemetry = { workspace = true, optional = true }
opentelemetry_sdk = { workspace = true, optional = true }
console-subscriber = { version = "0.3.0", optional = true }
opentelemetry-otlp = { version = "0.12.0", optional = true }
pict-rs = { version = "0.5.15", optional = true }
Expand Down
5 changes: 2 additions & 3 deletions crates/apub/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use activitypub_federation::{
FEDERATION_CONTENT_TYPE,
};
use actix_web::{web, web::Bytes, HttpRequest, HttpResponse};
use http::{header::LOCATION, StatusCode};
use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{
newtypes::DbUrl,
Expand Down Expand Up @@ -76,14 +75,14 @@ fn create_apub_tombstone_response<T: Into<Url>>(id: T) -> LemmyResult<HttpRespon
Ok(
HttpResponse::Gone()
.content_type(FEDERATION_CONTENT_TYPE)
.status(StatusCode::GONE)
.status(actix_web::http::StatusCode::GONE)
.body(json),
)
}

fn redirect_remote_object(url: &DbUrl) -> HttpResponse {
let mut res = HttpResponse::PermanentRedirect();
res.insert_header((LOCATION, url.as_str()));
res.insert_header((actix_web::http::header::LOCATION, url.as_str()));
res.finish()
}

Expand Down
1 change: 1 addition & 0 deletions crates/routes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ once_cell = { workspace = true }
tracing = { workspace = true }
tokio = { workspace = true }
urlencoding = { workspace = true }
http.workspace = true
rss = "2.0.8"
18 changes: 11 additions & 7 deletions crates/routes/src/images.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use activitypub_federation::actix_web::http_compat;
use actix_web::{
body::BodyStream,
http::{
Expand Down Expand Up @@ -110,7 +111,7 @@ fn adapt_request(
const INVALID_HEADERS: &[HeaderName] = &[ACCEPT_ENCODING, HOST];

let client_request = client
.request(request.method().clone(), url)
.request(http_compat::method(request.method()), url)
.timeout(REQWEST_TIMEOUT);

request
Expand All @@ -120,7 +121,7 @@ fn adapt_request(
if INVALID_HEADERS.contains(key) {
client_req
} else {
client_req.header(key, value)
client_req.header(key.as_str(), value.as_bytes())
}
})
}
Expand Down Expand Up @@ -167,7 +168,7 @@ async fn upload(
}
}

Ok(HttpResponse::build(status).json(images))
Ok(HttpResponse::build(StatusCode::from_u16(status.as_u16())?).json(images))
}

async fn full_res(
Expand Down Expand Up @@ -210,14 +211,14 @@ async fn image(

let res = client_req.send().await?;

if res.status() == StatusCode::NOT_FOUND {
if res.status() == http::StatusCode::NOT_FOUND {
return Ok(HttpResponse::NotFound().finish());
}

let mut client_res = HttpResponse::build(res.status());
let mut client_res = HttpResponse::build(StatusCode::from_u16(res.status().as_u16())?);

for (name, value) in res.headers().iter().filter(|(h, _)| *h != "connection") {
client_res.insert_header((name.clone(), value.clone()));
client_res.insert_header((name.as_str(), value.as_bytes()));
}

Ok(client_res.body(BodyStream::new(res.bytes_stream())))
Expand Down Expand Up @@ -246,7 +247,10 @@ async fn delete(

LocalImage::delete_by_alias(&mut context.pool(), &file).await?;

Ok(HttpResponse::build(res.status()).body(BodyStream::new(res.bytes_stream())))
Ok(
HttpResponse::build(StatusCode::from_u16(res.status().as_u16())?)
.body(BodyStream::new(res.bytes_stream())),
)
}

pub async fn image_proxy(
Expand Down
2 changes: 1 addition & 1 deletion crates/routes/src/webfinger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async fn get_webfinger_response(

Ok(
HttpResponse::Ok()
.content_type(&WEBFINGER_CONTENT_TYPE)
.content_type(WEBFINGER_CONTENT_TYPE.as_bytes())
.json(json),
)
}
Expand Down
8 changes: 4 additions & 4 deletions crates/utils/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@ cfg_if! {
}

impl actix_web::error::ResponseError for LemmyError {
fn status_code(&self) -> http::StatusCode {
fn status_code(&self) -> actix_web::http::StatusCode {
if self.error_type == LemmyErrorType::IncorrectLogin {
return http::StatusCode::UNAUTHORIZED;
return actix_web::http::StatusCode::UNAUTHORIZED;
}
match self.inner.downcast_ref::<diesel::result::Error>() {
Some(diesel::result::Error::NotFound) => http::StatusCode::NOT_FOUND,
_ => http::StatusCode::BAD_REQUEST,
Some(diesel::result::Error::NotFound) => actix_web::http::StatusCode::NOT_FOUND,
_ => actix_web::http::StatusCode::BAD_REQUEST,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/session_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use core::future::Ready;
use futures_util::future::LocalBoxFuture;
use lemmy_api::{local_user_view_from_jwt, read_auth_token};
use lemmy_api_common::context::LemmyContext;
use reqwest::header::HeaderValue;
use actix_web::http::header::HeaderValue;
use std::{future::ready, rc::Rc};

#[derive(Clone)]
Expand Down
10 changes: 4 additions & 6 deletions src/telemetry.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use console_subscriber::ConsoleLayer;
use lemmy_utils::error::LemmyResult;
use opentelemetry::{
sdk::{propagation::TraceContextPropagator, Resource},
KeyValue,
};
use opentelemetry::KeyValue;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::{propagation::TraceContextPropagator, Resource};
use tracing::{subscriber::set_global_default, Subscriber};
use tracing_subscriber::{filter::Targets, layer::SubscriberExt, registry::LookupSpan, Layer};

Expand All @@ -25,15 +23,15 @@ where
let tracer = opentelemetry_otlp::new_pipeline()
.tracing()
.with_trace_config(
opentelemetry::sdk::trace::config()
opentelemetry_sdk::trace::config()
.with_resource(Resource::new(vec![KeyValue::new("service.name", "lemmy")])),
)
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_endpoint(opentelemetry_url),
)
.install_batch(opentelemetry::runtime::Tokio)?;
.install_batch(opentelemetry_sdk::runtime::Tokio)?;

let otel_layer = tracing_opentelemetry::layer()
.with_tracer(tracer)
Expand Down

0 comments on commit 792a077

Please sign in to comment.