Skip to content

Commit

Permalink
sql/pgwire: add sql.conn.failures metric
Browse files Browse the repository at this point in the history
Related to #73566

This commit adds the the new sql.conn.failures counter metric that
reflects the number of failed SQL connections.

Release note (sql change): the new sql.conn.failures counter metric shows
number of failed SQL connections.
  • Loading branch information
Azhng committed Apr 7, 2022
1 parent f69b88f commit 6914cc7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/sql/pgwire/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ var (
Measurement: "Nanoseconds",
Unit: metric.Unit_NANOSECONDS,
}
MetaConnFailures = metric.Metadata{
Name: "sql.conn.failures",
Help: "Number of sql conection failures",
Measurement: "Connections",
Unit: metric.Unit_COUNT,
}
MetaPGWireCancelTotal = metric.Metadata{
Name: "sql.pgwire_cancel.total",
Help: "Counter of the number of pgwire query cancel requests",
Expand Down Expand Up @@ -273,6 +279,7 @@ type ServerMetrics struct {
Conns *metric.Gauge
NewConns *metric.Counter
ConnLatency *metric.Histogram
ConnFailures *metric.Counter
PGWireCancelTotalCount *metric.Counter
PGWireCancelIgnoredCount *metric.Counter
PGWireCancelSuccessfulCount *metric.Counter
Expand All @@ -289,6 +296,7 @@ func makeServerMetrics(
Conns: metric.NewGauge(MetaConns),
NewConns: metric.NewCounter(MetaNewConns),
ConnLatency: metric.NewLatency(MetaConnLatency, histogramWindow),
ConnFailures: metric.NewCounter(MetaConnFailures),
PGWireCancelTotalCount: metric.NewCounter(MetaPGWireCancelTotal),
PGWireCancelIgnoredCount: metric.NewCounter(MetaPGWireCancelIgnored),
PGWireCancelSuccessfulCount: metric.NewCounter(MetaPGWireCancelSuccessful),
Expand Down Expand Up @@ -710,7 +718,13 @@ func (s *Server) TestingEnableAuthLogging() {
// compatible with postgres.
//
// An error is returned if the initial handshake of the connection fails.
func (s *Server) ServeConn(ctx context.Context, conn net.Conn, socketType SocketType) error {
func (s *Server) ServeConn(ctx context.Context, conn net.Conn, socketType SocketType) (err error) {
defer func() {
if err != nil {
s.metrics.ConnFailures.Inc(1)
}
}()

ctx, rejectNewConnections, onCloseFn := s.registerConn(ctx)
defer onCloseFn()

Expand Down
7 changes: 7 additions & 0 deletions pkg/ts/catalog/chart_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,13 @@ var charts = []sectionDescription{
},
AxisLabel: "Latency",
},
{
Title: "Connection Failures",
Metrics: []string{
"sql.conn.failures",
},
AxisLabel: "Failures",
},
{
Title: "Open Transactions",
Metrics: []string{
Expand Down

0 comments on commit 6914cc7

Please sign in to comment.