From 1ebd4111a452358b85baec93d68eace79b12c68e Mon Sep 17 00:00:00 2001 From: Evan Wall Date: Wed, 29 Jun 2022 12:39:15 -0400 Subject: [PATCH] Colocate auth logging with auth metric for consistency refs #83224 Release note (bug fix): Move connection OK log and metric to same location after auth completes for consistency. This resolves an inconsistency (see linked isssue) in the DB console where the log and metric did not match. --- pkg/sql/pgwire/auth.go | 1 - pkg/sql/pgwire/conn.go | 13 ++++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/sql/pgwire/auth.go b/pkg/sql/pgwire/auth.go index 1164fe25fe59..2e4cbdfa6b2e 100644 --- a/pkg/sql/pgwire/auth.go +++ b/pkg/sql/pgwire/auth.go @@ -205,7 +205,6 @@ func (c *conn) handleAuthentication( } } - ac.LogAuthOK(ctx) return connClose, nil } diff --git a/pkg/sql/pgwire/conn.go b/pkg/sql/pgwire/conn.go index 7ef3e9b3788b..4bd4e70fe0c5 100644 --- a/pkg/sql/pgwire/conn.go +++ b/pkg/sql/pgwire/conn.go @@ -466,11 +466,6 @@ func (c *conn) serveImpl( return true, isSimpleQuery, nil //nolint:returnerrcheck } authDone = true - - // We count the connection establish latency until we are ready to - // serve a SQL query. It includes the time it takes to authenticate. - duration := timeutil.Since(c.startTime).Nanoseconds() - c.metrics.ConnLatency.RecordValue(duration) } switch typ { @@ -714,6 +709,14 @@ func (c *conn) processCommandsAsync( } // Signal the connection was established to the authenticator. ac.AuthOK(ctx) + ac.LogAuthOK(ctx) + + // We count the connection establish latency until we are ready to + // serve a SQL query. It includes the time it takes to authenticate and + // send the initial ReadyForQuery message. + duration := timeutil.Since(c.startTime).Nanoseconds() + c.metrics.ConnLatency.RecordValue(duration) + // Mark the authentication as succeeded in case a panic // is thrown below and we need to report to the client // using the defer above.