Skip to content

Commit 9d7ea15

Browse files
Vasilii Iakliushinashmckenzie
authored andcommitted
Merge branch '767-ensure-lfs-protocol-logic-has-prometheus-metrics' into 'main'
Add basic LFS connections metric for SSH See merge request https://gitlab.com/gitlab-org/gitlab-shell/-/merge_requests/1107 Merged-by: Vasilii Iakliushin <[email protected]> Approved-by: Ethan Urie <[email protected]> Approved-by: Vasilii Iakliushin <[email protected]> Reviewed-by: Vasilii Iakliushin <[email protected]> Reviewed-by: Ash McKenzie <[email protected]> Co-authored-by: Ash McKenzie <[email protected]>
2 parents 0653124 + 3c042d0 commit 9d7ea15

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

cmd/gitlab-shell/command/command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func Build(args *commandargs.Shell, config *config.Config, readWriter *readwrite
120120
return &lfsauthenticate.Command{Config: config, Args: args, ReadWriter: readWriter}
121121
case commandargs.LfsTransfer:
122122
if config.LFSConfig.PureSSHProtocol {
123+
metrics.LfsSSHConnectionsTotal.Inc()
123124
return &lfstransfer.Command{Config: config, Args: args, ReadWriter: readWriter}
124125
}
125126
case commandargs.ReceivePack:

cmd/gitlab-shell/command/command_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,16 @@ func TestLFSTransferCommands(t *testing.T) {
151151

152152
for _, tc := range testCases {
153153
t.Run(tc.desc, func(t *testing.T) {
154+
lfsSSHConnectionsTotal := testutil.ToFloat64(metrics.LfsSSHConnectionsTotal)
155+
154156
command, err := cmd.New(tc.arguments, tc.env, tc.config, nil)
155157

156158
if len(tc.errorString) > 0 {
157159
require.Equal(t, err.Error(), tc.errorString)
160+
} else {
161+
require.InDelta(t, lfsSSHConnectionsTotal+1, testutil.ToFloat64(metrics.LfsSSHConnectionsTotal), 0)
158162
}
163+
159164
require.IsType(t, tc.expectedType, command)
160165
})
161166
}

internal/command/lfstransfer/lfstransfer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ func (c *Command) Execute(ctx context.Context) (context.Context, error) {
5656
accessResponse.RootNamespaceID,
5757
))
5858

59+
log.WithContextFields(ctxWithLogData, log.Fields{"action": action}).Info("processing action")
60+
5961
auth, err := c.authenticate(ctx, operation, repo, accessResponse.UserID)
6062
if err != nil {
6163
return ctxWithLogData, err
@@ -81,7 +83,8 @@ func (c *Command) Execute(ctx context.Context) (context.Context, error) {
8183
}
8284

8385
p := transfer.NewProcessor(handler, backend, logger)
84-
defer log.WithContextFields(ctxWithLogData, log.Fields{}).Info("done processing commands")
86+
defer log.WithContextFields(ctxWithLogData, log.Fields{"action": action}).Info("done processing commands")
87+
8588
switch operation {
8689
case transfer.DownloadOperation:
8790
return ctxWithLogData, p.ProcessCommands(transfer.DownloadOperation)

internal/metrics/metrics.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
sliSshdSessionsErrorsTotalName = "gitlab_sli:shell_sshd_sessions:errors_total"
2929

3030
lfsHTTPConnectionsTotalName = "lfs_http_connections_total"
31+
lfsSSHConnectionsTotalName = "lfs_ssh_connections_total"
3132

3233
gitalyConnectionsTotalName = "connections_total"
3334
)
@@ -152,6 +153,13 @@ var (
152153
Help: "Number of LFS over HTTP connections that have been established",
153154
},
154155
)
156+
157+
LfsSSHConnectionsTotal = promauto.NewCounter(
158+
prometheus.CounterOpts{
159+
Name: lfsSSHConnectionsTotalName,
160+
Help: "Number of LFS over SSH connections that have been established",
161+
},
162+
)
155163
)
156164

157165
func NewRoundTripper(next http.RoundTripper) promhttp.RoundTripperFunc {

0 commit comments

Comments
 (0)