From 140f28bf1b99d2c5c37f1b03afe53e49b22fd1e9 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Tue, 18 Oct 2022 16:07:12 +0300 Subject: [PATCH] [proxy] Add more metrics --- proxy/src/auth/backend.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/proxy/src/auth/backend.rs b/proxy/src/auth/backend.rs index bb919770c1..6a19ff76ae 100644 --- a/proxy/src/auth/backend.rs +++ b/proxy/src/auth/backend.rs @@ -11,6 +11,7 @@ use crate::{ compute, http, mgmt, stream, url, waiters::{self, Waiter, Waiters}, }; +use metrics::{register_int_counter_vec, IntCounterVec}; use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use std::borrow::Cow; @@ -19,6 +20,15 @@ use tracing::{info, warn}; static CPLANE_WAITERS: Lazy> = Lazy::new(Default::default); +static AUTH_METHOD_USED_COUNTER: Lazy = Lazy::new(|| { + register_int_counter_vec!( + "proxy_auth_method_used_total", + "Number of authentication requests served.", + &["method_name"], + ) + .unwrap() +}); + /// Give caller an opportunity to wait for the cloud's reply. pub async fn with_waiter( psql_session_id: impl Into, @@ -172,8 +182,11 @@ impl BackendType<'_, ClientCredentials<'_>> { // support SNI or other means of passing the project name. // We now expect to see a very specific payload in the place of password. if creds.project().is_none() { - warn!("project name not specified, resorting to the password hack auth flow"); + AUTH_METHOD_USED_COUNTER + .with_label_values(&["password_hack"]) + .inc(); + warn!("project name not specified, resorting to the password hack auth flow"); let payload = AuthFlow::new(client) .begin(auth::PasswordHack) .await? @@ -210,6 +223,10 @@ impl BackendType<'_, ClientCredentials<'_>> { let res = match self { Console(endpoint, creds) => { + AUTH_METHOD_USED_COUNTER + .with_label_values(&["console"]) + .inc(); + info!( user = creds.user, project = creds.project(), @@ -220,6 +237,10 @@ impl BackendType<'_, ClientCredentials<'_>> { .await } Postgres(endpoint, creds) => { + AUTH_METHOD_USED_COUNTER + .with_label_values(&["postgres"]) + .inc(); + info!("performing mock authentication using a local postgres instance"); postgres::Api::new(&endpoint, &creds) .handle_user(client) @@ -227,6 +248,7 @@ impl BackendType<'_, ClientCredentials<'_>> { } // NOTE: this auth backend doesn't use client credentials. Link(url) => { + AUTH_METHOD_USED_COUNTER.with_label_values(&["link"]).inc(); info!("performing link authentication"); link::handle_user(&url, client).await }