As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit 1dd65e8c authored by Stan Hu's avatar Stan Hu
Browse files

Merge branch 'id-ignore-api-errors' into 'main'

Exclude API errors from error rate

See merge request gitlab-org/gitlab-shell!630
parents 41942bbb c232dc9a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -37,6 +37,14 @@ type GitlabNetClient struct {
userAgent string
}
type ApiError struct {
Msg string
}
func (e *ApiError) Error() string {
return e.Msg
}
func NewGitlabNetClient(
user,
password,
Loading
Loading
@@ -101,9 +109,9 @@ func parseError(resp *http.Response) error {
parsedResponse := &ErrorResponse{}
if err := json.NewDecoder(resp.Body).Decode(parsedResponse); err != nil {
return fmt.Errorf("Internal API error (%v)", resp.StatusCode)
return &ApiError{fmt.Sprintf("Internal API error (%v)", resp.StatusCode)}
} else {
return fmt.Errorf(parsedResponse.Message)
return &ApiError{parsedResponse.Message}
}
}
Loading
Loading
@@ -157,7 +165,7 @@ func (c *GitlabNetClient) DoRequest(ctx context.Context, method, path string, da
if err != nil {
logger.WithError(err).Error("Internal API unreachable")
return nil, fmt.Errorf("Internal API unreachable")
return nil, &ApiError{"Internal API unreachable"}
}
if response != nil {
Loading
Loading
Loading
Loading
@@ -2,6 +2,7 @@ package sshd
import (
"context"
"errors"
"time"
"golang.org/x/crypto/ssh"
Loading
Loading
@@ -9,6 +10,7 @@ import (
grpccodes "google.golang.org/grpc/codes"
grpcstatus "google.golang.org/grpc/status"
"gitlab.com/gitlab-org/gitlab-shell/client"
"gitlab.com/gitlab-org/gitlab-shell/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/internal/metrics"
Loading
Loading
@@ -90,7 +92,10 @@ func (c *connection) handle(ctx context.Context, chans <-chan ssh.NewChannel, ha
if grpcstatus.Convert(err).Code() == grpccodes.Canceled {
metrics.SshdCanceledSessions.Inc()
} else {
metrics.SliSshdSessionsErrorsTotal.Inc()
var apiError *client.ApiError
if !errors.As(err, &apiError) {
metrics.SliSshdSessionsErrorsTotal.Inc()
}
}
}
Loading
Loading
Loading
Loading
@@ -13,6 +13,7 @@ import (
grpccodes "google.golang.org/grpc/codes"
grpcstatus "google.golang.org/grpc/status"
"gitlab.com/gitlab-org/gitlab-shell/client"
"gitlab.com/gitlab-org/gitlab-shell/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/internal/metrics"
)
Loading
Loading
@@ -222,4 +223,14 @@ func TestSessionsMetrics(t *testing.T) {
require.InDelta(t, initialSessionsTotal+2, testutil.ToFloat64(metrics.SliSshdSessionsTotal), 0.1)
require.InDelta(t, initialSessionsErrorTotal+1, testutil.ToFloat64(metrics.SliSshdSessionsErrorsTotal), 0.1)
require.InDelta(t, initialCanceledSessions+1, testutil.ToFloat64(metrics.SshdCanceledSessions), 0.1)
conn, chans = setup(1, newChannel)
conn.handle(context.Background(), chans, func(context.Context, ssh.Channel, <-chan *ssh.Request) error {
close(chans)
return &client.ApiError{"api error"}
})
require.InDelta(t, initialSessionsTotal+3, testutil.ToFloat64(metrics.SliSshdSessionsTotal), 0.1)
require.InDelta(t, initialSessionsErrorTotal+1, testutil.ToFloat64(metrics.SliSshdSessionsErrorsTotal), 0.1)
require.InDelta(t, initialCanceledSessions+1, testutil.ToFloat64(metrics.SshdCanceledSessions), 0.1)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment