Skip to content
Draft
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
11 changes: 4 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "prosa-hyper"
version = "0.3.1"
version = "0.4.0"
authors = ["Jérémy HERGAULT <jeremy.hergault@worldline.com>", "Anthony THOMAS <anthony.thomas@worldline.com>", "Julien TERUEL <julien.teruel@worldline.com>", "Rene-Louis EYMARD <rene-louis.eymard@worldline.com>"]
description = "ProSA Hyper processor for HTTP client/server"
homepage = "https://worldline.com/"
Expand Down Expand Up @@ -39,20 +39,17 @@ bytes = ">=1.11.1, < 2"
thiserror = "2"
serde = { version = "1", features = ["derive"] }
tokio = { version = ">=1.48, < 2", features = ["macros", "net", "rt", "rt-multi-thread"] }
tracing = "0.1"
prosa = "0.4"
aquamarine = "0.6"
prosa = { version = "0.5", git = "https://github.com/worldline/ProSA.git", branch = "reload_improve" }
simple-mermaid = "0.2"
url = { version = "2", features = ["serde"] }

opentelemetry = { version = "0.31", features = ["metrics", "trace", "logs"] }

hyper = { version = "1", features = ["full"] }
http = "1"
http-body-util = "0.1"
hyper-util = { version = "0.1", features = ["full"] }

[dev-dependencies]
prosa-utils = "0.4"
prosa-utils = { version = "0.5", git = "https://github.com/worldline/ProSA.git", branch = "reload_improve" }
openssl = ">=0.10.75, < 0.11"
reqwest = { version = "0.13" }
config = { version = "0.15", default-features = false, features = ["toml", "json", "yaml", "json5", "convert-case", "async"] }
Expand Down
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The server configuration is straightforward.
You only need to set a [ListenerSetting](https://docs.rs/prosa/latest/prosa/io/listener/struct.ListenerSetting.html) to configure.

```yaml
http_server:
hyper_server:
listener:
url: https://0.0.0.0:443
ssl:
Expand All @@ -38,23 +38,33 @@ http_server:

If you have some slow services, you can set the `service_timeout` parameter (800 ms by default).

When ProSA stops, the processor releases its listening port right away so a new client is refused
instead of waiting, then answers the requests it still has in flight before shutting down.

### Client

The client exposes a service if it is available.
For backends, you need to use [TargetSetting](https://docs.rs/prosa/latest/prosa/io/stream/struct.TargetSetting.html).
All backends will be load-balanced with ProSA's internal service load balancing.

```yaml
http_client:
hyper_client:
service_name: "service_name"
min_socket: 1
max_socket: 20
nb_socket: 1
backends:
- url: http://backend01:8080
```

`nb_socket` is how many connections the processor keeps open to each backend (one by default).
An HTTP/1.1 socket serves one request at a time, so it is worth raising against a plain backend;
an HTTP/2 one multiplexes them.

If you have a slow backend response, you can set the `http_timeout` parameter (5 seconds by default).

A socket that can't reach its backend is retried instead of being dropped. It waits `reconnect_delay`
(500 ms by default), doubling that delay on every consecutive failure, up to `max_reconnect_delay`
(30 seconds by default).

## Examples

### Server
Expand All @@ -70,8 +80,8 @@ cargo run --example server
```

The server provides the following targets:
- [/](http://localhost:8080/) returns the ProSA name
- [/test](http://localhost:8080/test) contacts an internal service named SRV_TEST (requires starting the stub processor)
- [/](https://localhost:8443/) returns the ProSA name
- [/test](https://localhost:8443/test) contacts an internal service named SRV_TEST (requires starting the stub processor)
- [metrics](http://localhost:9090/metrics) exposes Prometheus metrics as configured

### Client
Expand Down
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ allow = [
"MIT",
"BSD-2-Clause",
"BSD-3-Clause",
"CC0-1.0",
"CDLA-Permissive-2.0",
"ISC",
"Zlib",
Expand Down
44 changes: 25 additions & 19 deletions examples/client.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
use std::convert::Infallible;
use std::env;
use std::{convert::Infallible, env};

use bytes::Bytes;
use clap::{ArgAction, Command, arg};
use config::Config;
use http_body_util::Empty;
use http_body_util::combinators::BoxBody;
use http_body_util::{Empty, combinators::BoxBody};
use hyper::{Request, Response};
use prosa::core::adaptor::Adaptor;
use prosa::core::error::ProcError;
use prosa::core::main::MainProc;
use prosa::core::main::MainRunnable as _;
use prosa::core::proc::{Proc, ProcBusParam, ProcConfig};
use prosa::core::service::ServiceError;
use prosa::core::settings::settings;
use prosa::inj::adaptor::InjAdaptor;
use prosa::inj::proc::{InjProc, InjSettings};
use prosa_hyper::PRODUCT_VERSION_HEADER;
use prosa_hyper::client::adaptor::HyperClientAdaptor;
use prosa_hyper::client::proc::{HyperClientProc, HyperClientSettings};
use prosa_utils::config::tracing::TelemetryFilter;
use prosa_utils::msg::simple_string_tvf::SimpleStringTvf;
use prosa::{
core::{
adaptor::Adaptor,
error::ProcError,
main::{MainProc, MainRunnable as _},
proc::{Proc, ProcBusParam, ProcConfig},
service::ServiceError,
settings::settings,
},
inj::{
adaptor::InjAdaptor,
proc::{InjProc, InjSettings},
},
tracing::debug,
};
use prosa_hyper::{
PRODUCT_VERSION_HEADER,
client::{
adaptor::HyperClientAdaptor,
proc::{HyperClientProc, HyperClientSettings},
},
};
use prosa_utils::{config::tracing::TelemetryFilter, msg::simple_string_tvf::SimpleStringTvf};
use serde::{Deserialize, Serialize};
use tracing::debug;
use url::Url;

/// Demo Hyper processor adaptor
Expand Down
3 changes: 1 addition & 2 deletions examples/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ hyper_client:
ssl:
store:
path: "examples/"
min_socket: 2
max_socket: 20
nb_socket: 2

observability:
level: DEBUG
Expand Down
49 changes: 29 additions & 20 deletions examples/server.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
use std::borrow::Cow;

use std::env;
use std::{borrow::Cow, env};

use bytes::Bytes;
use clap::{ArgAction, Command, arg};
use config::Config;
use http_body_util::Full;
use http_body_util::combinators::BoxBody;
use http_body_util::{Full, combinators::BoxBody};
use hyper::{Request, Response, StatusCode};
use prosa::core::adaptor::Adaptor;
use prosa::core::error::ProcError;
use prosa::core::main::MainRunnable as _;
use prosa::core::proc::{Proc, ProcBusParam as _, ProcConfig};
use prosa::core::settings::settings;
use prosa::stub::adaptor::StubParotAdaptor;
use prosa::stub::proc::StubSettings;
use prosa::{core::main::MainProc, stub::proc::StubProc};
use prosa_hyper::server::adaptor::{HyperServerAdaptor, default_srv_error_response};
use prosa_hyper::server::proc::{HyperServerProc, HyperServerSettings};
use prosa_hyper::{HyperResp, PRODUCT_VERSION_HEADER};
use prosa_utils::config::tracing::TelemetryFilter;
use prosa_utils::msg::simple_string_tvf::SimpleStringTvf;
use prosa::{
core::{
adaptor::Adaptor,
error::ProcError,
main::{MainProc, MainRunnable as _},
proc::{Proc, ProcBusParam as _, ProcConfig},
settings::settings,
},
io::SocketAddr,
stub::{
adaptor::StubParotAdaptor,
proc::{StubProc, StubSettings},
},
tracing::debug,
};
use prosa_hyper::{
HyperResp, PRODUCT_VERSION_HEADER,
server::{
adaptor::{HyperServerAdaptor, default_srv_error_response},
proc::{HyperServerProc, HyperServerSettings},
},
};
use prosa_utils::{config::tracing::TelemetryFilter, msg::simple_string_tvf::SimpleStringTvf};
use serde::{Deserialize, Serialize};
use tracing::debug;

/// Demo Hyper processor adaptor
#[derive(Debug, Adaptor, Clone)]
Expand All @@ -41,7 +47,10 @@ where
+ prosa_utils::msg::tvf::Tvf
+ std::default::Default,
{
fn new(proc: &HyperServerProc<M>) -> Result<Self, Box<dyn ProcError + Send + Sync>> {
fn new(
proc: &HyperServerProc<M>,
_addr: SocketAddr,
) -> Result<Self, Box<dyn ProcError + Send + Sync>> {
Ok(HyperDemoAdaptor {
prosa_name: proc.name().to_string(),
})
Expand Down
10 changes: 1 addition & 9 deletions src/client/adaptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ use url::Url;

use crate::client::proc::HyperClientProc;

#[cfg_attr(doc, aquamarine::aquamarine)]
/// Trait to define the Hyper adaptor structure
///
/// ```mermaid
/// graph LR
/// OUT1[Output HTTP server]
/// ProSA[ProSA Hyper Procesor]
///
/// ProSA-- HTTP request (process_client_request) -->OUT
/// OUT-- HTTP response (process_client_response) -->ProSA
/// ```
#[doc = simple_mermaid::mermaid!("diagrams/adaptor.mmd")]
pub trait HyperClientAdaptor<M>
where
M: 'static
Expand Down
6 changes: 6 additions & 0 deletions src/client/diagrams/adaptor.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
graph LR
OUT[Output HTTP server]
ProSA[ProSA Hyper Processor]

ProSA-- HTTP request (process_srv_request) -->OUT
OUT-- HTTP response (process_http_response) -->ProSA
Loading
Loading