Skip to content

Commit 6f03605

Browse files
authored
Use hyper-util git rev (v1.17) and adapt pool event API (kmesh-net#133)
Signed-off-by: Nicola Bonelli <nicola.bonelli@huawei-partners.com>
1 parent 34517a6 commit 6f03605

3 files changed

Lines changed: 68 additions & 35 deletions

File tree

Cargo.lock

Lines changed: 9 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ rust-version = "1.86"
2525
version = "0.1.0"
2626

2727
[patch.crates-io]
28-
hyper-util = { git = "https://github.com/awgn/hyper-util.git", branch = "event-handler" }
28+
hyper-util = { git = "https://github.com/awgn/hyper-util.git", branch = "orion_client" }
2929

3030
[workspace.dependencies]
3131
envoy-data-plane-api = { path = "envoy-data-plane-api" }

orion-lib/src/transport/http_channel.rs

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use webpki::types::ServerName;
7171
#[cfg(feature = "metrics")]
7272
use {
7373
hyper_util::client::legacy::{
74-
pool::{ConnectionEvent, EventHandler, Tag},
74+
pool::{EventHandler, PoolEvent},
7575
PoolKey,
7676
},
7777
std::any::Any,
@@ -209,7 +209,7 @@ impl HttpChannelBuilder {
209209
#[cfg(feature = "metrics")]
210210
{
211211
let cluster_name = self.cluster_name.unwrap_or_default();
212-
client_builder.event_handler(EventHandler::new(update_upstream_stats, cluster_name));
212+
client_builder.pool_event_handler(EventHandler::new(update_upstream_stats, cluster_name));
213213
}
214214

215215
client_builder
@@ -318,51 +318,89 @@ impl HttpChannelBuilder {
318318

319319
#[cfg(feature = "metrics")]
320320
#[allow(clippy::needless_pass_by_value)]
321-
fn update_upstream_stats(event: ConnectionEvent, key: &dyn Any, tag: &dyn Tag) {
321+
fn update_upstream_stats(event: PoolEvent, tag: &dyn Any, keys: &[&PoolKey]) {
322322
use tracing::debug;
323-
let cluster_name = *(tag.as_any().downcast_ref::<&str>().unwrap_or(&""));
323+
let cluster_name = *(tag.downcast_ref::<&str>().unwrap_or(&""));
324324
let shard_id = std::thread::current().id();
325-
if let Some(pk) = key.downcast_ref::<PoolKey>() {
326-
debug!("HttpClient: {:?} for cluster {:?} (pool_key: {:?})", event, cluster_name, pk);
325+
326+
for key in keys {
327+
debug!("HttpClient: {:?} for cluster {:?} (pool_key: {:?})", event, cluster_name, key);
327328
}
328329

330+
let num_events = keys.len() as u64;
329331
match event {
330-
ConnectionEvent::NewConnection => {
331-
with_metric!(clusters::UPSTREAM_CX_TOTAL, add, 1, shard_id, &[KeyValue::new("cluster", cluster_name)]);
332-
with_metric!(clusters::UPSTREAM_CX_ACTIVE, add, 1, shard_id, &[KeyValue::new("cluster", cluster_name)]);
332+
PoolEvent::NewConnection => {
333+
with_metric!(
334+
clusters::UPSTREAM_CX_TOTAL,
335+
add,
336+
num_events,
337+
shard_id,
338+
&[KeyValue::new("cluster", cluster_name)]
339+
);
340+
with_metric!(
341+
clusters::UPSTREAM_CX_ACTIVE,
342+
add,
343+
num_events,
344+
shard_id,
345+
&[KeyValue::new("cluster", cluster_name)]
346+
);
333347
},
334-
ConnectionEvent::IdleConnectionClosed => {
335-
with_metric!(clusters::UPSTREAM_CX_DESTROY, add, 1, shard_id, &[KeyValue::new("cluster", cluster_name)]);
348+
PoolEvent::IdleConnectionClosed => {
349+
with_metric!(
350+
clusters::UPSTREAM_CX_DESTROY,
351+
add,
352+
num_events,
353+
shard_id,
354+
&[KeyValue::new("cluster", cluster_name)]
355+
);
336356
with_metric!(
337357
clusters::UPSTREAM_CX_IDLE_TIMEOUT,
338358
add,
339-
1,
359+
num_events,
360+
shard_id,
361+
&[KeyValue::new("cluster", cluster_name)]
362+
);
363+
with_metric!(
364+
clusters::UPSTREAM_CX_ACTIVE,
365+
sub,
366+
num_events,
340367
shard_id,
341368
&[KeyValue::new("cluster", cluster_name)]
342369
);
343-
with_metric!(clusters::UPSTREAM_CX_ACTIVE, sub, 1, shard_id, &[KeyValue::new("cluster", cluster_name)]);
344370
},
345-
ConnectionEvent::ConnectionError => {
371+
PoolEvent::ConnectionError => {
346372
with_metric!(
347373
clusters::UPSTREAM_CX_CONNECT_FAIL,
348374
add,
349-
1,
375+
num_events,
350376
shard_id,
351377
&[KeyValue::new("cluster", cluster_name)]
352378
);
353379
},
354-
ConnectionEvent::ConnectionTimeout => {
380+
PoolEvent::ConnectionTimeout => {
355381
with_metric!(
356382
clusters::UPSTREAM_CX_CONNECT_TIMEOUT,
357383
add,
358-
1,
384+
num_events,
359385
shard_id,
360386
&[KeyValue::new("cluster", cluster_name)]
361387
);
362388
},
363-
ConnectionEvent::ConnectionClosed => {
364-
with_metric!(clusters::UPSTREAM_CX_DESTROY, add, 1, shard_id, &[KeyValue::new("cluster", cluster_name)]);
365-
with_metric!(clusters::UPSTREAM_CX_ACTIVE, sub, 1, shard_id, &[KeyValue::new("cluster", cluster_name)]);
389+
PoolEvent::ConnectionClosed => {
390+
with_metric!(
391+
clusters::UPSTREAM_CX_DESTROY,
392+
add,
393+
num_events,
394+
shard_id,
395+
&[KeyValue::new("cluster", cluster_name)]
396+
);
397+
with_metric!(
398+
clusters::UPSTREAM_CX_ACTIVE,
399+
sub,
400+
num_events,
401+
shard_id,
402+
&[KeyValue::new("cluster", cluster_name)]
403+
);
366404
},
367405
}
368406
}

0 commit comments

Comments
 (0)