diff options
author | Igor Drozdov <idrozdov@gitlab.com> | 2022-04-05 13:02:45 +0400 |
---|---|---|
committer | Igor Drozdov <idrozdov@gitlab.com> | 2022-04-05 13:02:46 +0400 |
commit | 8e1d69b17502ffd98ec8222abb5482ebee62ccbf (patch) | |
tree | 1f7e96301c73185d5007118ebb48961616e2baa1 /internal | |
parent | 969bf2e27edf49c3998b62d64507c79909624e81 (diff) | |
download | gitlab-shell-8e1d69b17502ffd98ec8222abb5482ebee62ccbf.tar.gz |
Fix connections duration metrics
We need to pass time.Now as a param, otherwise it's calculated on call
Diffstat (limited to 'internal')
-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") |