Skip to content

Commit

Permalink
fix: reviewdog warning and add comment
Browse files Browse the repository at this point in the history
Signed-off-by: hlts2 <[email protected]>
  • Loading branch information
hlts2 committed Nov 16, 2023
1 parent 08c44fb commit 7d7a690
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 400 deletions.
28 changes: 19 additions & 9 deletions internal/config/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,35 @@ package config
// Mirror represents the Mirror Gateway configuration.
type Mirror struct {
// Net represents the network configuration tcp, udp, unix domain socket.
Net *Net `json:"net,omitempty" yaml:"net"`
Net *Net `json:"net,omitempty" yaml:"net"`

// GRPCClient represents the configurations for gRPC client.
Client *GRPCClient `json:"client" yaml:"client"`
Client *GRPCClient `json:"client" yaml:"client"`

// SelfMirrorAddr represents the address for the self Mirror Gateway.
SelfMirrorAddr string `json:"self_mirror_addr" yaml:"self_mirror_addr"`
SelfMirrorAddr string `json:"self_mirror_addr" yaml:"self_mirror_addr"`

// GatewayAddr represents the address for the Vald Gateway (e.g lb-gateway).
GatewayAddr string `json:"gateway_addr" yaml:"gateway_addr"`
GatewayAddr string `json:"gateway_addr" yaml:"gateway_addr"`

// PodName represents the mirror gateway pod name.
PodName string `json:"pod_name" yaml:"pod_name"`
PodName string `json:"pod_name" yaml:"pod_name"`

// RegisterDuration represents the duration to register Mirror Gateway.
RegisterDuration string `json:"register_duration" yaml:"register_duration"`
RegisterDuration string `json:"register_duration" yaml:"register_duration"`

// Namespace represents the target namespace to discover ValdMirrorTarget resource.
Namespace string `json:"namespace" yaml:"namespace"`
Namespace string `json:"namespace" yaml:"namespace"`

// DiscoveryDuration represents the duration to discover.
DiscoveryDuration string `json:"discovery_duration" yaml:"discovery_duration"`

// Colocation represents the colocation name.
Colocation string `json:"colocation" yaml:"colocation"`
Colocation string `json:"colocation" yaml:"colocation"`

// Group represents the group name of the Mirror Gateways.
// It is used to discover ValdMirrorTarget resources with the same group name.
Group string `json:"group" yaml:"group"`
Group string `json:"group" yaml:"group"`
}

// Bind binds the actual data from the Mirror receiver fields.
Expand All @@ -48,6 +57,7 @@ func (m *Mirror) Bind() *Mirror {
m.DiscoveryDuration = GetActualValue(m.DiscoveryDuration)
m.Colocation = GetActualValue(m.Colocation)
m.Group = GetActualValue(m.Group)

if m.Net != nil {
m.Net = m.Net.Bind()
} else {
Expand Down
88 changes: 6 additions & 82 deletions pkg/gateway/mirror/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ import (
)

type (
// GlobalConfig is a type alias of config.GlobalConfig representing application base configurations.
GlobalConfig = config.GlobalConfig
Server = config.Server

// Server is a type alias of config.Server representing server base configurations.
Server = config.Server
)

// Config represent a application setting data content (config.yaml).
Expand All @@ -38,6 +41,7 @@ type Data struct {
Mirror *config.Mirror `json:"gateway" yaml:"gateway"`
}

// NewConfig load configurations from file path.
func NewConfig(path string) (cfg *Data, err error) {
cfg = new(Data)

Expand All @@ -46,7 +50,7 @@ func NewConfig(path string) (cfg *Data, err error) {
}

if cfg != nil {
cfg.Bind()
_ = cfg.Bind()
} else {
return nil, errors.ErrInvalidConfig
}
Expand All @@ -70,83 +74,3 @@ func NewConfig(path string) (cfg *Data, err error) {
}
return cfg, nil
}

// func FakeData() {
// d := Data{
// Version: "v0.0.1",
// Server: &config.Servers{
// Servers: []*config.Server{
// {
// Name: "agent-rest",
// Host: "127.0.0.1",
// Port: 8080,
// Mode: "REST",
// ProbeWaitTime: "3s",
// ShutdownDuration: "5s",
// HandlerTimeout: "5s",
// IdleTimeout: "2s",
// ReadHeaderTimeout: "1s",
// ReadTimeout: "1s",
// WriteTimeout: "1s",
// },
// {
// Name: "agent-grpc",
// Host: "127.0.0.1",
// Port: 8082,
// Mode: "GRPC",
// },
// },
// MetricsServers: []*config.Server{
// {
// Name: "pprof",
// Host: "127.0.0.1",
// Port: 6060,
// Mode: "REST",
// ProbeWaitTime: "3s",
// ShutdownDuration: "5s",
// HandlerTimeout: "5s",
// IdleTimeout: "2s",
// ReadHeaderTimeout: "1s",
// ReadTimeout: "1s",
// WriteTimeout: "1s",
// },
// },
// HealthCheckServers: []*config.Server{
// {
// Name: "livenesss",
// Host: "127.0.0.1",
// Port: 3000,
// },
// {
// Name: "readiness",
// Host: "127.0.0.1",
// Port: 3001,
// },
// },
// StartUpStrategy: []string{
// "livenesss",
// "pprof",
// "agent-grpc",
// "agent-rest",
// "readiness",
// },
// ShutdownStrategy: []string{
// "readiness",
// "agent-rest",
// "agent-grpc",
// "pprof",
// "livenesss",
// },
// FullShutdownDuration: "30s",
// TLS: &config.TLS{
// Enabled: false,
// Cert: "/path/to/cert",
// Key: "/path/to/key",
// CA: "/path/to/ca",
// },
// },
// Mirror: &config.Mirror{
// },
// }
// fmt.Println(config.ToRawYaml(d))
// }
165 changes: 6 additions & 159 deletions pkg/gateway/mirror/handler/grpc/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,129 +23,27 @@ import (
)

type mockClient struct {
InsertFunc func(ctx context.Context, in *payload.Insert_Request, opts ...grpc.CallOption) (*payload.Object_Location, error)
StreamInsertFunc func(ctx context.Context, opts ...grpc.CallOption) (vald.Insert_StreamInsertClient, error)
MultiInsertFunc func(ctx context.Context, in *payload.Insert_MultiRequest, opts ...grpc.CallOption) (*payload.Object_Locations, error)

UpdateFunc func(ctx context.Context, in *payload.Update_Request, opts ...grpc.CallOption) (*payload.Object_Location, error)
StreamUpdateFunc func(ctx context.Context, opts ...grpc.CallOption) (vald.Update_StreamUpdateClient, error)
MultiUpdateFunc func(ctx context.Context, in *payload.Update_MultiRequest, opts ...grpc.CallOption) (*payload.Object_Locations, error)

UpsertFunc func(ctx context.Context, in *payload.Upsert_Request, opts ...grpc.CallOption) (*payload.Object_Location, error)
StreamUpsertFunc func(ctx context.Context, opts ...grpc.CallOption) (vald.Upsert_StreamUpsertClient, error)
MultiUpsertFunc func(ctx context.Context, in *payload.Upsert_MultiRequest, opts ...grpc.CallOption) (*payload.Object_Locations, error)

SearchFunc func(ctx context.Context, in *payload.Search_Request, opts ...grpc.CallOption) (*payload.Search_Response, error)
SearchByIDFunc func(ctx context.Context, in *payload.Search_IDRequest, opts ...grpc.CallOption) (*payload.Search_Response, error)
StreamSearchFunc func(ctx context.Context, opts ...grpc.CallOption) (vald.Search_StreamSearchClient, error)
StreamSearchByIDFunc func(ctx context.Context, opts ...grpc.CallOption) (vald.Search_StreamSearchByIDClient, error)
MultiSearchFunc func(ctx context.Context, in *payload.Search_MultiRequest, opts ...grpc.CallOption) (*payload.Search_Responses, error)
MultiSearchByIDFunc func(ctx context.Context, in *payload.Search_MultiIDRequest, opts ...grpc.CallOption) (*payload.Search_Responses, error)
LinearSearchFunc func(ctx context.Context, in *payload.Search_Request, opts ...grpc.CallOption) (*payload.Search_Response, error)
LinearSearchByIDFunc func(ctx context.Context, in *payload.Search_IDRequest, opts ...grpc.CallOption) (*payload.Search_Response, error)
StreamLinearSearchFunc func(ctx context.Context, opts ...grpc.CallOption) (vald.Search_StreamLinearSearchClient, error)
StreamLinearSearchByIDFunc func(ctx context.Context, opts ...grpc.CallOption) (vald.Search_StreamLinearSearchByIDClient, error)
MultiLinearSearchFunc func(ctx context.Context, in *payload.Search_MultiRequest, opts ...grpc.CallOption) (*payload.Search_Responses, error)
MultiLinearSearchByIDFunc func(ctx context.Context, in *payload.Search_MultiIDRequest, opts ...grpc.CallOption) (*payload.Search_Responses, error)
vald.ClientWithMirror

InsertFunc func(ctx context.Context, in *payload.Insert_Request, opts ...grpc.CallOption) (*payload.Object_Location, error)
UpdateFunc func(ctx context.Context, in *payload.Update_Request, opts ...grpc.CallOption) (*payload.Object_Location, error)
UpsertFunc func(ctx context.Context, in *payload.Upsert_Request, opts ...grpc.CallOption) (*payload.Object_Location, error)
RemoveFunc func(ctx context.Context, in *payload.Remove_Request, opts ...grpc.CallOption) (*payload.Object_Location, error)
RemoveByTimestampFunc func(ctx context.Context, in *payload.Remove_TimestampRequest, opts ...grpc.CallOption) (*payload.Object_Locations, error)
StreamRemoveFunc func(ctx context.Context, opts ...grpc.CallOption) (vald.Remove_StreamRemoveClient, error)
MultiRemoveFunc func(ctx context.Context, in *payload.Remove_MultiRequest, opts ...grpc.CallOption) (*payload.Object_Locations, error)

ExistsFunc func(ctx context.Context, in *payload.Object_ID, opts ...grpc.CallOption) (*payload.Object_ID, error)
GetObjectFunc func(ctx context.Context, in *payload.Object_VectorRequest, opts ...grpc.CallOption) (*payload.Object_Vector, error)
StreamGetObjectFunc func(ctx context.Context, opts ...grpc.CallOption) (vald.Object_StreamGetObjectClient, error)
StreamListObjectFunc func(ctx context.Context, opts ...grpc.CallOption) (vald.Object_StreamListObjectClient, error)

RegisterFunc func(ctx context.Context, in *payload.Mirror_Targets, opts ...grpc.CallOption) (*payload.Mirror_Targets, error)
AdvertiseFunc func(ctx context.Context, in *payload.Mirror_Targets, opts ...grpc.CallOption) (*payload.Mirror_Targets, error)
}

func (m *mockClient) Insert(ctx context.Context, in *payload.Insert_Request, opts ...grpc.CallOption) (*payload.Object_Location, error) {
return m.InsertFunc(ctx, in, opts...)
}

func (m *mockClient) StreamInsert(ctx context.Context, opts ...grpc.CallOption) (vald.Insert_StreamInsertClient, error) {
return m.StreamInsertFunc(ctx, opts...)
}

func (m *mockClient) MultiInsert(ctx context.Context, in *payload.Insert_MultiRequest, opts ...grpc.CallOption) (*payload.Object_Locations, error) {
return m.MultiInsertFunc(ctx, in, opts...)
}

func (m *mockClient) Update(ctx context.Context, in *payload.Update_Request, opts ...grpc.CallOption) (*payload.Object_Location, error) {
return m.UpdateFunc(ctx, in, opts...)
}

func (m *mockClient) StreamUpdate(ctx context.Context, opts ...grpc.CallOption) (vald.Update_StreamUpdateClient, error) {
return m.StreamUpdateFunc(ctx, opts...)
}

func (m *mockClient) MultiUpdate(ctx context.Context, in *payload.Update_MultiRequest, opts ...grpc.CallOption) (*payload.Object_Locations, error) {
return m.MultiUpdateFunc(ctx, in, opts...)
}

func (m *mockClient) Upsert(ctx context.Context, in *payload.Upsert_Request, opts ...grpc.CallOption) (*payload.Object_Location, error) {
return m.UpsertFunc(ctx, in, opts...)
}

func (m *mockClient) StreamUpsert(ctx context.Context, opts ...grpc.CallOption) (vald.Upsert_StreamUpsertClient, error) {
return m.StreamUpsertFunc(ctx, opts...)
}

func (m *mockClient) MultiUpsert(ctx context.Context, in *payload.Upsert_MultiRequest, opts ...grpc.CallOption) (*payload.Object_Locations, error) {
return m.MultiUpsertFunc(ctx, in, opts...)
}

func (m *mockClient) Search(ctx context.Context, in *payload.Search_Request, opts ...grpc.CallOption) (*payload.Search_Response, error) {
return m.SearchFunc(ctx, in, opts...)
}

func (m *mockClient) SearchByID(ctx context.Context, in *payload.Search_IDRequest, opts ...grpc.CallOption) (*payload.Search_Response, error) {
return m.SearchByIDFunc(ctx, in, opts...)
}

func (m *mockClient) StreamSearch(ctx context.Context, opts ...grpc.CallOption) (vald.Search_StreamSearchClient, error) {
return m.StreamSearchFunc(ctx, opts...)
}

func (m *mockClient) StreamSearchByID(ctx context.Context, opts ...grpc.CallOption) (vald.Search_StreamSearchByIDClient, error) {
return m.StreamSearchByIDFunc(ctx, opts...)
}

func (m *mockClient) MultiSearch(ctx context.Context, in *payload.Search_MultiRequest, opts ...grpc.CallOption) (*payload.Search_Responses, error) {
return m.MultiSearchFunc(ctx, in, opts...)
}

func (m *mockClient) MultiSearchByID(ctx context.Context, in *payload.Search_MultiIDRequest, opts ...grpc.CallOption) (*payload.Search_Responses, error) {
return m.MultiSearchByIDFunc(ctx, in, opts...)
}

func (m *mockClient) LinearSearch(ctx context.Context, in *payload.Search_Request, opts ...grpc.CallOption) (*payload.Search_Response, error) {
return m.LinearSearchFunc(ctx, in, opts...)
}

func (m *mockClient) LinearSearchByID(ctx context.Context, in *payload.Search_IDRequest, opts ...grpc.CallOption) (*payload.Search_Response, error) {
return m.LinearSearchByIDFunc(ctx, in, opts...)
}

func (m *mockClient) StreamLinearSearch(ctx context.Context, opts ...grpc.CallOption) (vald.Search_StreamLinearSearchClient, error) {
return m.StreamLinearSearchFunc(ctx, opts...)
}

func (m *mockClient) StreamLinearSearchByID(ctx context.Context, opts ...grpc.CallOption) (vald.Search_StreamLinearSearchByIDClient, error) {
return m.StreamLinearSearchByIDFunc(ctx, opts...)
}

func (m *mockClient) MultiLinearSearch(ctx context.Context, in *payload.Search_MultiRequest, opts ...grpc.CallOption) (*payload.Search_Responses, error) {
return m.MultiLinearSearchFunc(ctx, in, opts...)
}

func (m *mockClient) MultiLinearSearchByID(ctx context.Context, in *payload.Search_MultiIDRequest, opts ...grpc.CallOption) (*payload.Search_Responses, error) {
return m.MultiLinearSearchByIDFunc(ctx, in, opts...)
}

func (m *mockClient) Remove(ctx context.Context, in *payload.Remove_Request, opts ...grpc.CallOption) (*payload.Object_Location, error) {
return m.RemoveFunc(ctx, in, opts...)
}
Expand All @@ -154,55 +52,16 @@ func (m *mockClient) RemoveByTimestamp(ctx context.Context, in *payload.Remove_T
return m.RemoveByTimestampFunc(ctx, in, opts...)
}

func (m *mockClient) StreamRemove(ctx context.Context, opts ...grpc.CallOption) (vald.Remove_StreamRemoveClient, error) {
return m.StreamRemoveFunc(ctx, opts...)
}

func (m *mockClient) MultiRemove(ctx context.Context, in *payload.Remove_MultiRequest, opts ...grpc.CallOption) (*payload.Object_Locations, error) {
return m.MultiRemoveFunc(ctx, in, opts...)
}

func (m *mockClient) Exists(ctx context.Context, in *payload.Object_ID, opts ...grpc.CallOption) (*payload.Object_ID, error) {
return m.ExistsFunc(ctx, in, opts...)
}

func (m *mockClient) GetObject(ctx context.Context, in *payload.Object_VectorRequest, opts ...grpc.CallOption) (*payload.Object_Vector, error) {
return m.GetObjectFunc(ctx, in, opts...)
}

func (m *mockClient) StreamGetObject(ctx context.Context, opts ...grpc.CallOption) (vald.Object_StreamGetObjectClient, error) {
return m.StreamGetObjectFunc(ctx, opts...)
}

func (m *mockClient) StreamListObject(ctx context.Context, in *payload.Object_List_Request, opts ...grpc.CallOption) (vald.Object_StreamListObjectClient, error) {
return m.StreamListObjectFunc(ctx, opts...)
}

func (m *mockClient) Register(ctx context.Context, in *payload.Mirror_Targets, opts ...grpc.CallOption) (*payload.Mirror_Targets, error) {
return m.RegisterFunc(ctx, in)
}

func (m *mockClient) Advertise(ctx context.Context, in *payload.Mirror_Targets, opts ...grpc.CallOption) (*payload.Mirror_Targets, error) {
return m.AdvertiseFunc(ctx, in)
}

var _ vald.ClientWithMirror = (*mockClient)(nil)

type mockGateway struct {
service.Gateway

StartFunc func(ctx context.Context) (<-chan error, error)
ForwardedContextFunc func(ctx context.Context, podName string) context.Context
FromForwardedContextFunc func(ctx context.Context) string
BroadCastFunc func(ctx context.Context,
f func(ctx context.Context, target string, vc vald.ClientWithMirror, copts ...grpc.CallOption) error) error
DoFunc func(ctx context.Context, target string,
f func(ctx context.Context, vc vald.ClientWithMirror, copts ...grpc.CallOption) (interface{}, error)) (interface{}, error)
DoMultiFunc func(ctx context.Context, targets []string,
f func(ctx context.Context, target string, vc vald.ClientWithMirror, copts ...grpc.CallOption) error) error
GRPCClientFunc func() grpc.Client
}

func (m *mockGateway) Start(ctx context.Context) (<-chan error, error) {
return m.StartFunc(ctx)
}

func (m *mockGateway) ForwardedContext(ctx context.Context, podName string) context.Context {
Expand All @@ -219,20 +78,8 @@ func (m *mockGateway) BroadCast(ctx context.Context,
return m.BroadCastFunc(ctx, f)
}

func (m *mockGateway) Do(ctx context.Context, target string,
f func(ctx context.Context, vc vald.ClientWithMirror, copts ...grpc.CallOption) (interface{}, error),
) (interface{}, error) {
return m.DoFunc(ctx, target, f)
}

func (m *mockGateway) DoMulti(ctx context.Context, targets []string,
f func(ctx context.Context, target string, vc vald.ClientWithMirror, copts ...grpc.CallOption) error,
) error {
return m.DoMultiFunc(ctx, targets, f)
}

func (m *mockGateway) GRPCClient() grpc.Client {
return m.GRPCClientFunc()
}

var _ service.Gateway = (*mockGateway)(nil)
Loading

0 comments on commit 7d7a690

Please sign in to comment.