Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pingora and pandora-web-server dependencies #56

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,35 @@ lto = "thin"

[patch.crates-io.pingora-load-balancing]
git = "https://github.com/memorysafety/pingora.git"
rev = "12ca93c6b187a68ff9a526b4c4e669f602244366"
rev = "a98eadde498a45f32ab906d629342954fa173d11"
# path = "../pingora/pingora-load-balancing"

[patch.crates-io.pingora-core]
git = "https://github.com/memorysafety/pingora.git"
rev = "12ca93c6b187a68ff9a526b4c4e669f602244366"
rev = "a98eadde498a45f32ab906d629342954fa173d11"
# path = "../pingora/pingora-core"

[patch.crates-io.pingora-cache]
git = "https://github.com/memorysafety/pingora.git"
rev = "12ca93c6b187a68ff9a526b4c4e669f602244366"
rev = "a98eadde498a45f32ab906d629342954fa173d11"
# path = "../pingora/pingora-cache"

[patch.crates-io.pingora-http]
git = "https://github.com/memorysafety/pingora.git"
rev = "12ca93c6b187a68ff9a526b4c4e669f602244366"
rev = "a98eadde498a45f32ab906d629342954fa173d11"
# path = "../pingora/pingora-http"

[patch.crates-io.pingora-proxy]
git = "https://github.com/memorysafety/pingora.git"
rev = "12ca93c6b187a68ff9a526b4c4e669f602244366"
rev = "a98eadde498a45f32ab906d629342954fa173d11"
# path = "../pingora/pingora-proxy"

[patch.crates-io.static-files-module]
git = "https://github.com/jamesmunns/pandora-web-server.git"
rev = "f3a84be5d3be0daa65303f62aa01d0b57e7cc708"
git = "https://github.com/pandora-web-server/pandora-web-server.git"
rev = "fe5d7dfc7d943d2bd8371309084a775db99e84f0"
# path = "../pandora-web-server/static-files-module"

[patch.crates-io.pandora-module-utils]
git = "https://github.com/jamesmunns/pandora-web-server.git"
rev = "f3a84be5d3be0daa65303f62aa01d0b57e7cc708"
git = "https://github.com/pandora-web-server/pandora-web-server.git"
rev = "fe5d7dfc7d943d2bd8371309084a775db99e84f0"
# path = "../pandora-web-server/pandora-module-utils"
11 changes: 6 additions & 5 deletions source/river/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ kdl = "4.6.0"
miette = { version = "5.10.0", features = ["fancy"] }
thiserror = "1.0.61"
http = "1.0.0"
futures-util = "0.3.30"

[dependencies.static-files-module]
version = "0.2"
Expand Down Expand Up @@ -62,16 +63,16 @@ features = [
# Pingora dependencies

[dependencies.pingora]
version = "0.2.0"
version = "0.3.0"

[dependencies.pingora-core]
version = "0.2.0"
version = "0.3.0"

[dependencies.pingora-proxy]
version = "0.2.0"
version = "0.3.0"

[dependencies.pingora-http]
version = "0.2.0"
version = "0.3.0"

[dependencies.pingora-load-balancing]
version = "0.2.0"
version = "0.3.0"
1 change: 1 addition & 0 deletions source/river/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub fn river_file_server(
index_file: Vec::new().into(),
page_404: None,
precompressed: Vec::new().into(),
..Default::default()
};
let file_server = FileServer {
server: StaticFilesHandler::try_from(fsconf)
Expand Down
62 changes: 37 additions & 25 deletions source/river/src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
//! this includes creation of HTTP proxy services, as well as Path Control
//! modifiers.

use std::collections::BTreeMap;
use std::collections::{BTreeMap, BTreeSet};

use async_trait::async_trait;
use futures_util::FutureExt;

use pingora::{server::Server, Error};
use pingora_core::{upstreams::peer::HttpPeer, Result};
use pingora_http::{RequestHeader, ResponseHeader};
use pingora_load_balancing::{
discovery,
selection::{
consistent::KetamaHashing, BackendIter, BackendSelection, FVNHash, Random, RoundRobin,
},
LoadBalancer,
Backend, Backends, LoadBalancer,
};
use pingora_proxy::{ProxyHttp, Session};

Expand All @@ -32,12 +34,6 @@ pub mod request_modifiers;
pub mod request_selector;
pub mod response_modifiers;

#[derive(Clone, Hash, PartialEq, Eq)]
pub struct BonusData {
// todo: what else do we need here?
peer: HttpPeer,
}

/// The [RiverProxyService] is intended to capture the behaviors used to extend
/// the [HttpProxy] functionality by providing a [ProxyHttp] trait implementation.
///
Expand All @@ -49,7 +45,7 @@ pub struct RiverProxyService<BS: BackendSelection> {
/// All modifiers used when implementing the [ProxyHttp] trait.
pub modifiers: Modifiers,
/// Load Balancer
pub load_balancer: LoadBalancer<BS, BonusData>,
pub load_balancer: LoadBalancer<BS>,
pub request_selector: RequestSelector,
}

Expand All @@ -63,18 +59,18 @@ pub fn river_proxy_service(
type ServiceMaker = fn(ProxyConfig, &Server) -> Box<dyn pingora::services::Service>;

let service_maker: ServiceMaker = match conf.upstream_options.selection {
SelectionKind::RoundRobin => RiverProxyService::<RoundRobin<BonusData>>::from_basic_conf,
SelectionKind::Random => RiverProxyService::<Random<BonusData>>::from_basic_conf,
SelectionKind::Fnv => RiverProxyService::<FVNHash<BonusData>>::from_basic_conf,
SelectionKind::Ketama => RiverProxyService::<KetamaHashing<BonusData>>::from_basic_conf,
SelectionKind::RoundRobin => RiverProxyService::<RoundRobin>::from_basic_conf,
SelectionKind::Random => RiverProxyService::<Random>::from_basic_conf,
SelectionKind::Fnv => RiverProxyService::<FVNHash>::from_basic_conf,
SelectionKind::Ketama => RiverProxyService::<KetamaHashing>::from_basic_conf,
};
service_maker(conf, server)
}

impl<BS> RiverProxyService<BS>
where
BS: BackendSelection<Metadata = BonusData> + Send + Sync + 'static,
BS::Iter: BackendIter<Metadata = BonusData>,
BS: BackendSelection + Send + Sync + 'static,
BS::Iter: BackendIter,
{
/// Create a new [RiverProxyService] from the given [ProxyConfig]
pub fn from_basic_conf(
Expand All @@ -83,12 +79,23 @@ where
) -> Box<dyn pingora::services::Service> {
let modifiers = Modifiers::from_conf(&conf.path_control).unwrap();

let upstreams = LoadBalancer::<BS, BonusData>::try_from_iter(
conf.upstreams
.iter()
.map(|u| (u._address.clone(), BonusData { peer: u.clone() })),
)
.unwrap();
// TODO: This maybe could be done cleaner? This is a sort-of inlined
// version of `LoadBalancer::try_from_iter` with the ability to add
// metadata extensions
let mut backends = BTreeSet::new();
for uppy in conf.upstreams {
let mut backend = Backend::new(&uppy._address.to_string()).unwrap();
assert!(backend.ext.insert::<HttpPeer>(uppy).is_none());
backends.insert(backend);
}
let disco = discovery::Static::new(backends);
let upstreams = LoadBalancer::<BS>::from_backends(Backends::new(disco));
upstreams
.update()
.now_or_never()
.expect("static should not block")
.expect("static should not error");
// end of TODO

let mut my_proxy = pingora_proxy::http_proxy_service_with_name(
&server.configuration,
Expand Down Expand Up @@ -191,8 +198,8 @@ pub struct RiverContext {
#[async_trait]
impl<BS> ProxyHttp for RiverProxyService<BS>
where
BS: BackendSelection<Metadata = BonusData> + Send + Sync + 'static,
BS::Iter: BackendIter<Metadata = BonusData>,
BS: BackendSelection + Send + Sync + 'static,
BS::Iter: BackendIter,
{
type CTX = RiverContext;

Expand All @@ -218,10 +225,15 @@ where
// Manually clear the selector buf to avoid accidental leaks
ctx.selector_buf.clear();

let backend = backend.ok_or_else(|| pingora::Error::new_str("oops"))?;
let backend =
backend.ok_or_else(|| pingora::Error::new_str("Unable to determine backend"))?;

// Retrieve the HttpPeer from the associated backend metadata
Ok(Box::new(backend.metadata.peer.clone()))
backend
.ext
.get::<HttpPeer>()
.map(|p| Box::new(p.clone()))
.ok_or_else(|| pingora::Error::new_str("Fatal: Missing selected backend metadata"))
}

/// Handle the "upstream request filter" phase, where we can choose to make
Expand Down