diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-30 15:23:27 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-30 15:23:27 +0300 |
commit | 3bba41a8c5dfcca0d086eaef10ef36a705dd4f7a (patch) | |
tree | 81954681947aaa85592fa7f3c9beed23a7b6bb01 /workhorse | |
parent | 1aa447601c6be1e964acbb674887649dab23b804 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'workhorse')
-rw-r--r-- | workhorse/gitaly_test.go | 15 | ||||
-rw-r--r-- | workhorse/go.mod | 2 | ||||
-rw-r--r-- | workhorse/internal/git/archive.go | 2 | ||||
-rw-r--r-- | workhorse/internal/gitaly/gitaly.go | 7 | ||||
-rw-r--r-- | workhorse/internal/gitaly/unmarshal_test.go | 2 | ||||
-rw-r--r-- | workhorse/internal/redis/redis.go | 18 | ||||
-rw-r--r-- | workhorse/internal/redis/redis_test.go | 3 | ||||
-rw-r--r-- | workhorse/internal/testhelper/gitaly.go | 21 |
8 files changed, 41 insertions, 29 deletions
diff --git a/workhorse/gitaly_test.go b/workhorse/gitaly_test.go index 270c40cb4bc..db3b76787aa 100644 --- a/workhorse/gitaly_test.go +++ b/workhorse/gitaly_test.go @@ -17,11 +17,11 @@ import ( "testing" "time" - "github.com/golang/protobuf/jsonpb" //lint:ignore SA1019 https://gitlab.com/gitlab-org/gitlab/-/issues/324868 - "github.com/golang/protobuf/proto" //lint:ignore SA1019 https://gitlab.com/gitlab-org/gitlab/-/issues/324868 "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/codes" + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/proto" "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb" @@ -107,7 +107,7 @@ func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) { require.Len(t, bodySplit, 3) gitalyRequest := &gitalypb.InfoRefsRequest{} - require.NoError(t, jsonpb.UnmarshalString(bodySplit[0], gitalyRequest)) + require.NoError(t, protojson.Unmarshal([]byte(bodySplit[0]), gitalyRequest)) require.Equal(t, gitProtocol, gitalyRequest.GitProtocol) if tc.showAllRefs { @@ -263,7 +263,7 @@ func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) { require.Len(t, split, 2) gitalyRequest := &gitalypb.PostReceivePackRequest{} - require.NoError(t, jsonpb.UnmarshalString(split[0], gitalyRequest)) + require.NoError(t, protojson.Unmarshal([]byte(split[0]), gitalyRequest)) require.Equal(t, apiResponse.Repository.StorageName, gitalyRequest.Repository.StorageName) require.Equal(t, apiResponse.Repository.RelativePath, gitalyRequest.Repository.RelativePath) @@ -437,7 +437,7 @@ func TestPostUploadPackProxiedToGitalySuccessfully(t *testing.T) { require.Len(t, bodySplit, 2) gitalyRequest := &gitalypb.PostUploadPackWithSidechannelRequest{} - require.NoError(t, jsonpb.UnmarshalString(bodySplit[0], gitalyRequest)) + require.NoError(t, protojson.Unmarshal([]byte(bodySplit[0]), gitalyRequest)) require.Equal(t, apiResponse.Repository.StorageName, gitalyRequest.Repository.StorageName) require.Equal(t, apiResponse.Repository.RelativePath, gitalyRequest.Repository.RelativePath) @@ -822,13 +822,12 @@ func buildPbRepo(storageName, relativePath string) *gitalypb.Repository { } func serializedMessage(name string, arg proto.Message) rpcArg { - m := &jsonpb.Marshaler{} - str, err := m.MarshalToString(arg) + data, err := protojson.Marshal(arg) if err != nil { panic(err) } - return rpcArg{name, str} + return rpcArg{name, string(data)} } func serializedProtoMessage(name string, arg proto.Message) rpcArg { diff --git a/workhorse/go.mod b/workhorse/go.mod index 8afe0f049aa..00fddbe2323 100644 --- a/workhorse/go.mod +++ b/workhorse/go.mod @@ -11,7 +11,6 @@ require ( github.com/getsentry/raven-go v0.2.0 github.com/golang-jwt/jwt/v5 v5.0.0 github.com/golang/gddo v0.0.0-20210115222349-20d68f94ee1f - github.com/golang/protobuf v1.5.3 github.com/gorilla/websocket v1.5.0 github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 github.com/johannesboyne/gofakes3 v0.0.0-20230914150226-f005f5cc03aa @@ -68,6 +67,7 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 // indirect github.com/google/s2a-go v0.1.4 // indirect diff --git a/workhorse/internal/git/archive.go b/workhorse/internal/git/archive.go index acccd937038..58048c31834 100644 --- a/workhorse/internal/git/archive.go +++ b/workhorse/internal/git/archive.go @@ -14,7 +14,7 @@ import ( "regexp" "time" - "github.com/golang/protobuf/proto" //lint:ignore SA1019 https://gitlab.com/gitlab-org/gitlab/-/issues/324868 + "google.golang.org/protobuf/proto" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" diff --git a/workhorse/internal/gitaly/gitaly.go b/workhorse/internal/gitaly/gitaly.go index e4fbad17017..98f73b40a9d 100644 --- a/workhorse/internal/gitaly/gitaly.go +++ b/workhorse/internal/gitaly/gitaly.go @@ -5,14 +5,14 @@ import ( "strings" "sync" - "github.com/golang/protobuf/jsonpb" //lint:ignore SA1019 https://gitlab.com/gitlab-org/gitlab/-/issues/324868 - "github.com/golang/protobuf/proto" //lint:ignore SA1019 https://gitlab.com/gitlab-org/gitlab/-/issues/324868 grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "github.com/sirupsen/logrus" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/proto" gitalyauth "gitlab.com/gitlab-org/gitaly/v16/auth" gitalyclient "gitlab.com/gitlab-org/gitaly/v16/client" @@ -38,7 +38,6 @@ type connectionsCache struct { } var ( - jsonUnMarshaler = jsonpb.Unmarshaler{AllowUnknownFields: true} // This connection cache map contains two types of connections: // - Normal gRPC connections // - Sidechannel connections. When client dials to the Gitaly server, the @@ -201,5 +200,5 @@ func newConnection(server api.GitalyServer) (*grpc.ClientConn, error) { } func UnmarshalJSON(s string, msg proto.Message) error { - return jsonUnMarshaler.Unmarshal(strings.NewReader(s), msg) + return protojson.UnmarshalOptions{DiscardUnknown: true}.Unmarshal([]byte(s), msg) } diff --git a/workhorse/internal/gitaly/unmarshal_test.go b/workhorse/internal/gitaly/unmarshal_test.go index 39e3a3f2502..bd9d5dc3bd5 100644 --- a/workhorse/internal/gitaly/unmarshal_test.go +++ b/workhorse/internal/gitaly/unmarshal_test.go @@ -3,9 +3,9 @@ package gitaly import ( "testing" - "github.com/golang/protobuf/proto" //lint:ignore SA1019 https://gitlab.com/gitlab-org/gitlab/-/issues/324868 "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb" + "google.golang.org/protobuf/proto" ) func TestUnmarshalJSON(t *testing.T) { diff --git a/workhorse/internal/redis/redis.go b/workhorse/internal/redis/redis.go index b528255d25b..e21dae916e4 100644 --- a/workhorse/internal/redis/redis.go +++ b/workhorse/internal/redis/redis.go @@ -2,6 +2,7 @@ package redis import ( "context" + "crypto/tls" "errors" "fmt" "net" @@ -55,7 +56,7 @@ const ( // createDialer references https://github.com/redis/go-redis/blob/b1103e3d436b6fe98813ecbbe1f99dc8d59b06c9/options.go#L214 // it intercepts the error and tracks it via a Prometheus counter -func createDialer(sentinels []string) func(ctx context.Context, network, addr string) (net.Conn, error) { +func createDialer(sentinels []string, tlsConfig *tls.Config) func(ctx context.Context, network, addr string) (net.Conn, error) { return func(ctx context.Context, network, addr string) (net.Conn, error) { var isSentinel bool for _, sentinelAddr := range sentinels { @@ -81,7 +82,15 @@ func createDialer(sentinels []string) func(ctx context.Context, network, addr st KeepAlive: 5 * time.Minute, } - conn, err := netDialer.DialContext(ctx, network, addr) + var conn net.Conn + var err error + + if tlsConfig != nil { + conn, err = tls.DialWithDialer(netDialer, network, addr, tlsConfig) + } else { + conn, err = netDialer.DialContext(ctx, network, addr) + } + if err != nil { ErrorCounter.WithLabelValues("dial", destination).Inc() } else { @@ -160,7 +169,8 @@ func configureRedis(cfg *config.RedisConfig) (*redis.Client, error) { opt.ReadTimeout = defaultReadTimeout opt.WriteTimeout = defaultWriteTimeout - opt.Dialer = createDialer([]string{}) + // ParseURL seeds TLSConfig if schems is rediss + opt.Dialer = createDialer([]string{}, opt.TLSConfig) return redis.NewClient(opt), nil } @@ -181,7 +191,7 @@ func configureSentinel(cfg *config.RedisConfig) *redis.Client { ReadTimeout: defaultReadTimeout, WriteTimeout: defaultWriteTimeout, - Dialer: createDialer(sentinels), + Dialer: createDialer(sentinels, nil), }) client.AddHook(sentinelInstrumentationHook{}) diff --git a/workhorse/internal/redis/redis_test.go b/workhorse/internal/redis/redis_test.go index 6fd6ecbae11..d16a7a02761 100644 --- a/workhorse/internal/redis/redis_test.go +++ b/workhorse/internal/redis/redis_test.go @@ -42,6 +42,9 @@ func TestConfigureValidConfigX(t *testing.T) { scheme: "redis", }, { + scheme: "rediss", + }, + { scheme: "tcp", }, } diff --git a/workhorse/internal/testhelper/gitaly.go b/workhorse/internal/testhelper/gitaly.go index b468f0941de..e8f30a043f7 100644 --- a/workhorse/internal/testhelper/gitaly.go +++ b/workhorse/internal/testhelper/gitaly.go @@ -9,8 +9,6 @@ import ( "strings" "sync" - "github.com/golang/protobuf/jsonpb" //lint:ignore SA1019 https://gitlab.com/gitlab-org/gitlab/-/issues/324868 - "github.com/golang/protobuf/proto" //lint:ignore SA1019 https://gitlab.com/gitlab-org/gitlab/-/issues/324868 "github.com/sirupsen/logrus" "golang.org/x/net/context" "google.golang.org/grpc" @@ -18,6 +16,8 @@ import ( "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/proto" "gitlab.com/gitlab-org/gitaly/v16/client" "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb" @@ -71,8 +71,7 @@ func (s *GitalyTestServer) InfoRefsUploadPack(in *gitalypb.InfoRefsRequest, stre fmt.Printf("Result: %+v\n", in) - marshaler := &jsonpb.Marshaler{} - jsonString, err := marshaler.MarshalToString(in) + jsonString, err := marshalJSON(in) if err != nil { return err } @@ -116,8 +115,11 @@ func (s *GitalyTestServer) InfoRefsReceivePack(in *gitalypb.InfoRefsRequest, str } func marshalJSON(msg proto.Message) (string, error) { - marshaler := &jsonpb.Marshaler{} - return marshaler.MarshalToString(msg) + b, err := protojson.Marshal(msg) + if err != nil { + return "", err + } + return string(b), nil } type infoRefsSender interface { @@ -198,14 +200,13 @@ func (s *GitalyTestServer) PostUploadPackWithSidechannel(ctx context.Context, re } defer conn.Close() - marshaler := &jsonpb.Marshaler{} - jsonBytes := &bytes.Buffer{} - if err := marshaler.Marshal(jsonBytes, req); err != nil { + jsonBytes, err := protojson.Marshal(req) + if err != nil { return nil, err } if _, err := io.Copy(conn, io.MultiReader( - bytes.NewReader(append(jsonBytes.Bytes(), 0)), + bytes.NewReader(append(jsonBytes, 0)), conn, )); err != nil { return nil, err |