summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2022-05-10 20:23:41 +0000
committerStan Hu <stanhu@gmail.com>2022-05-10 20:23:41 +0000
commit4c2d7ca9ebc7a6814efbf8dc616bea2ad3df42c3 (patch)
treebc21abbeaea7f47a600c9d7a6b5ac77d3b8954f1 /internal
parent733845f9abec43b6573ba3a1167cc27ff2bfc199 (diff)
parentb7fc3251c13320029dc300197ff13b62fdc66486 (diff)
downloadgitlab-shell-4c2d7ca9ebc7a6814efbf8dc616bea2ad3df42c3.tar.gz
Merge branch 'id-improve-errors-metrics' into 'main'
Exclude authentication errors from error rate See merge request gitlab-org/gitlab-shell!611
Diffstat (limited to 'internal')
-rw-r--r--internal/sshd/connection.go5
-rw-r--r--internal/sshd/sshd.go24
2 files changed, 14 insertions, 15 deletions
diff --git a/internal/sshd/connection.go b/internal/sshd/connection.go
index 1312833..278bb37 100644
--- a/internal/sshd/connection.go
+++ b/internal/sshd/connection.go
@@ -2,6 +2,7 @@ package sshd
import (
"context"
+ "time"
"golang.org/x/crypto/ssh"
"golang.org/x/sync/semaphore"
@@ -49,6 +50,10 @@ func (c *connection) handle(ctx context.Context, chans <-chan ssh.NewChannel, ha
}
go func() {
+ defer func(started time.Time) {
+ metrics.SshdSessionDuration.Observe(time.Since(started).Seconds())
+ }(time.Now())
+
defer c.concurrentSessions.Release(1)
// Prevent a panic in a single session from taking out the whole server
diff --git a/internal/sshd/sshd.go b/internal/sshd/sshd.go
index 49b8ab9..d6ea6c6 100644
--- a/internal/sshd/sshd.go
+++ b/internal/sshd/sshd.go
@@ -146,19 +146,8 @@ func (s *Server) getStatus() status {
}
func (s *Server) handleConn(ctx context.Context, nconn net.Conn) {
- success := false
-
metrics.SshdConnectionsInFlight.Inc()
- started := time.Now()
- defer func() {
- metrics.SshdConnectionsInFlight.Dec()
- metrics.SshdSessionDuration.Observe(time.Since(started).Seconds())
-
- metrics.SliSshdSessionsTotal.Inc()
- if !success {
- metrics.SliSshdSessionsErrorsTotal.Inc()
- }
- }()
+ defer metrics.SshdConnectionsInFlight.Dec()
remoteAddr := nconn.RemoteAddr().String()
@@ -174,6 +163,8 @@ func (s *Server) handleConn(ctx context.Context, nconn net.Conn) {
defer func() {
if err := recover(); err != nil {
ctxlog.Warn("panic handling session")
+
+ metrics.SliSshdSessionsErrorsTotal.Inc()
}
}()
@@ -181,11 +172,12 @@ func (s *Server) handleConn(ctx context.Context, nconn net.Conn) {
sconn, chans, reqs, err := ssh.NewServerConn(nconn, s.serverConfig.get(ctx))
if err != nil {
- ctxlog.WithError(err).Error("server: handleConn: failed to initialize SSH connection")
+ ctxlog.WithError(err).Warn("server: handleConn: failed to initialize SSH connection")
return
}
go ssh.DiscardRequests(reqs)
+ started := time.Now()
var establishSessionDuration float64
conn := newConnection(s.Config.Server.ConcurrentSessionsLimit, remoteAddr)
conn.handle(ctx, chans, func(ctx context.Context, channel ssh.Channel, requests <-chan *ssh.Request) {
@@ -199,9 +191,11 @@ func (s *Server) handleConn(ctx context.Context, nconn net.Conn) {
remoteAddr: remoteAddr,
}
+ metrics.SliSshdSessionsTotal.Inc()
session.handle(ctx, requests)
-
- success = session.success
+ if !session.success {
+ metrics.SliSshdSessionsErrorsTotal.Inc()
+ }
})
ctxlog.WithFields(log.Fields{