diff options
author | Ash McKenzie <amckenzie@gitlab.com> | 2022-04-06 07:36:20 +0000 |
---|---|---|
committer | Ash McKenzie <amckenzie@gitlab.com> | 2022-04-06 07:36:20 +0000 |
commit | fa5bf866e87fff104f84252293f4a177287cae94 (patch) | |
tree | 330e2ef7f5c29cc6962a0956b6be2ad77737e845 | |
parent | 40b070efa35e13fabe3abed77a0a255771caf17f (diff) | |
parent | 8e1d69b17502ffd98ec8222abb5482ebee62ccbf (diff) | |
download | gitlab-shell-fa5bf866e87fff104f84252293f4a177287cae94.tar.gz |
Merge branch 'id-fix-connections-duration-metrics' into 'main'
Fix connections duration metrics
See merge request gitlab-org/gitlab-shell!588
-rw-r--r-- | internal/sshd/connection.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/internal/sshd/connection.go b/internal/sshd/connection.go index 7ba9bed..25b082a 100644 --- a/internal/sshd/connection.go +++ b/internal/sshd/connection.go @@ -13,7 +13,6 @@ import ( ) type connection struct { - begin time.Time concurrentSessions *semaphore.Weighted remoteAddr string } @@ -22,7 +21,6 @@ type channelHandler func(context.Context, ssh.Channel, <-chan *ssh.Request) func newConnection(maxSessions int64, remoteAddr string) *connection { return &connection{ - begin: time.Now(), concurrentSessions: semaphore.NewWeighted(maxSessions), remoteAddr: remoteAddr, } @@ -32,9 +30,11 @@ func (c *connection) handle(ctx context.Context, chans <-chan ssh.NewChannel, ha ctxlog := log.WithContextFields(ctx, log.Fields{"remote_addr": c.remoteAddr}) metrics.SshdConnectionsInFlight.Inc() - defer metrics.SshdConnectionsInFlight.Dec() - defer metrics.SshdConnectionDuration.Observe(time.Since(c.begin).Seconds()) + defer func(started time.Time) { + metrics.SshdConnectionsInFlight.Dec() + metrics.SshdConnectionDuration.Observe(time.Since(started).Seconds()) + }(time.Now()) for newChannel := range chans { ctxlog.WithField("channel_type", newChannel.ChannelType()).Info("connection: handle: new channel requested") |