From 6b82f22ada28c72797235df0cd6a8c2104e15df3 Mon Sep 17 00:00:00 2001 From: khanova <32508607+khanova@users.noreply.github.com> Date: Thu, 16 Nov 2023 13:19:13 +0100 Subject: [PATCH] Collect number of connections by sni type (#5867) ## Problem We don't know the number of users with the different kind of authentication: ["sni", "endpoint in options" (A and B from [here](https://neon.tech/docs/connect/connection-errors)), "password_hack"] ## Summary of changes Collect metrics by sni kind. --- proxy/src/auth/credentials.rs | 20 +++++++++++++++++++- proxy/src/proxy.rs | 9 +++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/proxy/src/auth/credentials.rs b/proxy/src/auth/credentials.rs index d7a8edca79..9fe9c26f0c 100644 --- a/proxy/src/auth/credentials.rs +++ b/proxy/src/auth/credentials.rs @@ -1,7 +1,9 @@ //! User credentials used in authentication. use crate::{ - auth::password_hack::parse_endpoint_param, error::UserFacingError, proxy::neon_options, + auth::password_hack::parse_endpoint_param, + error::UserFacingError, + proxy::{neon_options, NUM_CONNECTION_ACCEPTED_BY_SNI}, }; use itertools::Itertools; use pq_proto::StartupMessageParams; @@ -124,6 +126,22 @@ impl<'a> ClientCredentials<'a> { .transpose()?; info!(user, project = project.as_deref(), "credentials"); + if sni.is_some() { + info!("Connection with sni"); + NUM_CONNECTION_ACCEPTED_BY_SNI + .with_label_values(&["sni"]) + .inc(); + } else if project.is_some() { + NUM_CONNECTION_ACCEPTED_BY_SNI + .with_label_values(&["no_sni"]) + .inc(); + info!("Connection without sni"); + } else { + NUM_CONNECTION_ACCEPTED_BY_SNI + .with_label_values(&["password_hack"]) + .inc(); + info!("Connection with password hack"); + } let cache_key = format!( "{}{}", diff --git a/proxy/src/proxy.rs b/proxy/src/proxy.rs index 2d38acd05b..b03f95dc5f 100644 --- a/proxy/src/proxy.rs +++ b/proxy/src/proxy.rs @@ -129,6 +129,15 @@ pub static RATE_LIMITER_LIMIT: Lazy = Lazy::new(|| { .unwrap() }); +pub static NUM_CONNECTION_ACCEPTED_BY_SNI: Lazy = Lazy::new(|| { + register_int_counter_vec!( + "proxy_accepted_connections_by_sni", + "Number of connections (per sni).", + &["kind"], + ) + .unwrap() +}); + pub struct LatencyTimer { // time since the stopwatch was started start: Option,