Skip to content

Feature: update client statistics#68

Merged
dtpthao merged 11 commits into
thao/update_logfrom
thao/statistics
Nov 15, 2025
Merged

Feature: update client statistics#68
dtpthao merged 11 commits into
thao/update_logfrom
thao/statistics

Conversation

@dtpthao
Copy link
Copy Markdown
Contributor

@dtpthao dtpthao commented Oct 25, 2025

Result:

image

@dtpthao dtpthao requested review from muse254 and stravid87 October 25, 2025 07:50
# Conflicts:
#	forward-proxy/src/handler/mod.rs
Copy link
Copy Markdown
Contributor

@stravid87 stravid87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work. I'm happy with this once again.
Also, I'm happy(?) to report that this is the first time I feel like I can offer legitimate criticism to stretch your skills? I'm still insecure about my ability to give feedback so I invite you to push back but: in forward-proxy/src/statistics/mod.rs, can you remove the .await calls? Ideally, stats logging will happen entirely in parallel. As a fallback, if we error out, allow the request to go through and we (the Layer8 team) will simply forgo that monetization opportunity.

Comment thread docker/docker-compose.yml
- DOCKER_INFLUXDB_INIT_MODE=setup
- DOCKER_INFLUXDB_INIT_USERNAME=admin
- DOCKER_INFLUXDB_INIT_PASSWORD=12341234
- DOCKER_INFLUXDB_INIT_ORG=globeandcitizen
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing things like this, "ORG=globeandcitizen", always makes me smile.

@@ -11,7 +11,9 @@ pub struct FPConfig {
#[serde(flatten)]
pub tls_config: TlsConfig,
#[serde(flatten)] // This flattens the HandlerConfig fields into this struct
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting...


#[derive(Clone, Debug, Default)]
pub struct IntFPSession {
pub client_id: String,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. You add here the client_id used to track InfluxDB

@@ -101,11 +102,12 @@ impl ForwardHandler {
#[derive(Deserialize, Debug)]
struct AuthServerResponse {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In layer8, the corresponding struct was simply called, x509_certificate. Here it's called AuthServerResponse and that's a better name.

}

let cert: AuthServerResponse = res.json().await.map_err(|err| {
let auth_res: AuthServerResponse = res.json().await.map_err(|err| {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup -- better naming here too.

Comment thread forward-proxy/src/statistics/mod.rs Outdated
ctx: &Layer8Context,
response_status: u16,
) -> Result<(), Box<dyn Error + Sync + Send>> {
self.increase_total_request(client_id).await?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here true async code would be better. Blocking with await could probably be avoided with a clever solution that, if an error occurs, we handle it gracefully. The 'cost' might be that we miss out on the monetization of an incremented requests but the benefit might be more performant code.

Comment thread forward-proxy/src/statistics/mod.rs Outdated
"/proxy" => {
self.add_total_byte_transferred(
client_id,
(ctx.get_request_body().len() + ctx.get_response_body().len()) as i64,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup works for me.

Comment thread forward-proxy/src/statistics/mod.rs Outdated
self.increase_total_success(client_id).await
}
"/init-tunnel" => self.increase_total_tunnel_initiated(client_id).await,
_ => Ok(()),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread forward-proxy/src/statistics/mod.rs Outdated
)
.await?;

self.increase_total_success(client_id).await
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove awaits when tracking stats?

@dtpthao dtpthao merged commit d65b393 into thao/update_log Nov 15, 2025
0 of 2 checks passed
@dtpthao dtpthao deleted the thao/statistics branch November 15, 2025 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants